This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-12-06 14:54:33 +08:00
/*
* Copyright [2019] [Doric.Pub]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { View, Property } from "../ui/view";
2019-12-06 14:54:33 +08:00
import { Color } from "../util/color";
import { Gravity } from "../util/gravity";
import { BridgeContext } from "../runtime/global";
2019-12-31 18:16:55 +08:00
import { layoutConfig } from "../util/index.util";
2019-12-06 14:54:33 +08:00
export class Input extends View {
2019-12-06 14:54:33 +08:00
@Property
text?: string
@Property
textColor?: Color
@Property
textSize?: number
@Property
hintText?: string
@Property
hintTextColor?: Color
@Property
multiline?: boolean
@Property
textAlignment?: Gravity
@Property
onTextChange?: (text: string) => void
@Property
onFocusChange?: (focused: boolean) => void
getText(context: BridgeContext) {
return this.nativeChannel(context, 'getText')() as Promise<string>
}
setSelection(context: BridgeContext, start: number, end: number = start) {
return this.nativeChannel(context, 'setSelection')({
start,
end,
}) as Promise<string>
}
requestFocus(context: BridgeContext) {
return this.nativeChannel(context, 'requestFocus')()
}
releaseFocus(context: BridgeContext) {
return this.nativeChannel(context, 'releaseFocus')()
}
2019-12-31 18:16:55 +08:00
}
export function input(config: Partial<Input>) {
2019-12-31 18:16:55 +08:00
const ret = new Input
ret.layoutConfig = layoutConfig().just()
for (let key in config) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
2019-12-06 14:54:33 +08:00
}