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.
|
|
|
|
*/
|
2021-03-03 10:08:48 +08:00
|
|
|
import { View, Property, InconsistProperty } 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
|
|
|
|
2021-06-11 10:35:41 +08:00
|
|
|
export enum ReturnKeyType {
|
|
|
|
Default = 0,
|
|
|
|
Done = 1,
|
|
|
|
Search = 2,
|
|
|
|
Next = 3,
|
|
|
|
Go = 4,
|
|
|
|
Send = 5,
|
|
|
|
}
|
|
|
|
|
2020-04-16 19:21:24 +08:00
|
|
|
export class Input extends View {
|
2019-12-06 14:54:33 +08:00
|
|
|
|
2021-03-03 10:08:48 +08:00
|
|
|
@InconsistProperty
|
2019-12-06 14:54:33 +08:00
|
|
|
text?: string
|
|
|
|
|
|
|
|
@Property
|
|
|
|
textColor?: Color
|
|
|
|
|
|
|
|
@Property
|
|
|
|
textSize?: number
|
|
|
|
|
2021-07-20 15:38:25 +08:00
|
|
|
@Property
|
|
|
|
font?: string
|
|
|
|
|
2019-12-06 14:54:33 +08:00
|
|
|
@Property
|
|
|
|
hintText?: string
|
2020-06-13 11:53:21 +08:00
|
|
|
|
2021-07-20 15:38:25 +08:00
|
|
|
@Property
|
|
|
|
hintFont?: string
|
|
|
|
|
2020-06-12 18:02:44 +08:00
|
|
|
@Property
|
|
|
|
inputType?: InputType
|
2019-12-06 14:54:33 +08:00
|
|
|
|
|
|
|
@Property
|
|
|
|
hintTextColor?: Color
|
|
|
|
|
|
|
|
@Property
|
|
|
|
multiline?: boolean
|
|
|
|
|
|
|
|
@Property
|
|
|
|
textAlignment?: Gravity
|
|
|
|
|
|
|
|
@Property
|
|
|
|
onTextChange?: (text: string) => void
|
|
|
|
|
|
|
|
@Property
|
|
|
|
onFocusChange?: (focused: boolean) => void
|
|
|
|
|
2020-04-30 16:36:28 +08:00
|
|
|
@Property
|
|
|
|
maxLength?: number
|
2021-03-03 10:08:48 +08:00
|
|
|
|
2021-02-08 18:18:37 +08:00
|
|
|
@Property
|
|
|
|
password?: boolean
|
2020-04-30 16:36:28 +08:00
|
|
|
|
2021-06-11 10:35:41 +08:00
|
|
|
@Property
|
|
|
|
editable?: boolean
|
|
|
|
|
|
|
|
@Property
|
|
|
|
returnKeyType?: ReturnKeyType
|
|
|
|
|
2021-06-11 15:17:20 +08:00
|
|
|
@Property
|
|
|
|
onSubmitEditing?: (text: string) => void
|
|
|
|
|
2021-06-11 17:47:06 +08:00
|
|
|
@Property
|
|
|
|
beforeTextChange?: (change: {
|
|
|
|
editing: string,
|
|
|
|
start: number,
|
|
|
|
length: number,
|
|
|
|
replacement: string,
|
|
|
|
}) => boolean
|
|
|
|
|
2019-12-06 14:54:33 +08:00
|
|
|
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,
|
2021-06-11 17:40:02 +08:00
|
|
|
}) as Promise<any>
|
|
|
|
}
|
|
|
|
|
|
|
|
getSelection(context: BridgeContext) {
|
|
|
|
return this.nativeChannel(context, 'getSelection')() as Promise<{
|
|
|
|
start: number,
|
|
|
|
end: number,
|
|
|
|
}>
|
2019-12-06 14:54:33 +08:00
|
|
|
}
|
|
|
|
|
2021-06-11 17:40:02 +08:00
|
|
|
|
2019-12-06 14:54:33 +08:00
|
|
|
requestFocus(context: BridgeContext) {
|
|
|
|
return this.nativeChannel(context, 'requestFocus')()
|
|
|
|
}
|
|
|
|
|
|
|
|
releaseFocus(context: BridgeContext) {
|
|
|
|
return this.nativeChannel(context, 'releaseFocus')()
|
|
|
|
}
|
2019-12-31 18:16:55 +08:00
|
|
|
}
|
|
|
|
|
2020-06-13 11:53:21 +08:00
|
|
|
export enum InputType {
|
2020-06-12 18:02:44 +08:00
|
|
|
Default = 0,
|
|
|
|
|
|
|
|
Number = 1,
|
|
|
|
|
2020-06-13 11:53:21 +08:00
|
|
|
Decimal = 2,
|
2020-06-12 18:02:44 +08:00
|
|
|
|
|
|
|
Alphabet = 3,
|
|
|
|
|
|
|
|
Phone = 4,
|
|
|
|
}
|
|
|
|
|
2020-04-16 19:21:24 +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
|
2020-04-30 16:36:28 +08:00
|
|
|
}
|