feat:Input add editable and returnKeyType

This commit is contained in:
pengfei.zhou 2021-06-11 10:35:41 +08:00 committed by osborn
parent 188e3b55f6
commit ff641bf983
4 changed files with 111 additions and 1 deletions

View File

@ -190,6 +190,37 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
}
break;
case "editable":
if (prop.isBoolean()) {
view.setEnabled(prop.asBoolean().value());
}
break;
case "returnKeyType":
if (prop.isNumber()) {
int returnKeyType = prop.asNumber().toInt();
switch (returnKeyType) {
case 1:
view.setImeOptions(EditorInfo.IME_ACTION_DONE);
break;
case 2:
view.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
break;
case 3:
view.setImeOptions(EditorInfo.IME_ACTION_NEXT);
break;
case 4:
view.setImeOptions(EditorInfo.IME_ACTION_GO);
break;
case 5:
view.setImeOptions(EditorInfo.IME_ACTION_SEND);
break;
case 0:
default:
view.setImeOptions(EditorInfo.IME_ACTION_UNSPECIFIED);
break;
}
}
break;
default:
super.blend(view, name, prop);
break;

View File

@ -0,0 +1,40 @@
import { Color, Group, layoutConfig, list, listItem, modal, Panel, slider, stack, text } from "doric";
@Entry
class ListInSlider extends Panel {
build(root: Group) {
slider({
layoutConfig: layoutConfig().most(),
itemCount: 2,
renderPage: (idx) => {
if (idx === 0) {
return listItem(
list({
itemCount: 100,
layoutConfig: layoutConfig().most(),
renderItem: (idx) => {
return listItem(
text({
text: `Item ${idx}`,
onClick: () => {
modal(context).alert(`Clicked ${idx}`)
}
}))
}
}),
{
layoutConfig: layoutConfig().most(),
})
}
return listItem(
stack([], {
layoutConfig: layoutConfig().most(),
backgroundColor: idx === 0 ? Color.BLUE : Color.GREEN,
}),
{
layoutConfig: layoutConfig().most(),
})
}
}).in(root)
}
}

View File

@ -157,7 +157,31 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
}
}
} else if ([name isEqualToString:@"password"]) {
self.view.secureTextEntry = [(NSNumber *) prop boolValue];
view.secureTextEntry = [(NSNumber *) prop boolValue];
} else if ([name isEqualToString:@"editable"]) {
view.editable = [(NSNumber *) prop boolValue];
} else if ([name isEqualToString:@"returnKeyType"]) {
switch ([(NSNumber *) prop integerValue]) {
case 1:
view.returnKeyType = UIReturnKeyDone;
break;
case 2:
view.returnKeyType = UIReturnKeySearch;
break;
case 3:
view.returnKeyType = UIReturnKeyNext;
break;
case 4:
view.returnKeyType = UIReturnKeyGo;
break;
case 5:
view.returnKeyType = UIReturnKeySend;
break;
case 0:
default:
view.returnKeyType = UIReturnKeyDefault;
break;
}
} else {
[super blendView:view forPropName:name propValue:prop];
}

View File

@ -19,6 +19,15 @@ import { Gravity } from "../util/gravity";
import { BridgeContext } from "../runtime/global";
import { layoutConfig } from "../util/index.util";
export enum ReturnKeyType {
Default = 0,
Done = 1,
Search = 2,
Next = 3,
Go = 4,
Send = 5,
}
export class Input extends View {
@InconsistProperty
@ -57,6 +66,12 @@ export class Input extends View {
@Property
password?: boolean
@Property
editable?: boolean
@Property
returnKeyType?: ReturnKeyType
getText(context: BridgeContext) {
return this.nativeChannel(context, 'getText')() as Promise<string>
}