feat:Input add password property

This commit is contained in:
pengfeizhou 2021-02-08 18:18:37 +08:00 committed by osborn
parent 521ce19c1c
commit 07c701ef23
12 changed files with 170 additions and 86 deletions

View File

@ -24,6 +24,7 @@ import android.text.TextWatcher;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
@ -123,23 +124,68 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
break;
case "inputType":
if (prop.isNumber()) {
final int variation =
mView.getInputType() & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
boolean isPassword = variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_WEB_PASSWORD)
|| variation
== (EditorInfo.TYPE_CLASS_NUMBER | EditorInfo.TYPE_NUMBER_VARIATION_PASSWORD);
int inputType;
switch (prop.asNumber().toInt()) {
case 1:
mView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL);
inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL;
if (isPassword) {
inputType = inputType | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
}
break;
case 2:
mView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
inputType = InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL;
if (isPassword) {
inputType = inputType | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
}
break;
case 3:
mView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
if (isPassword) {
inputType = inputType | InputType.TYPE_TEXT_VARIATION_PASSWORD;
}
break;
case 4:
mView.setInputType(InputType.TYPE_CLASS_PHONE);
inputType = InputType.TYPE_CLASS_PHONE;
if (isPassword) {
inputType = inputType | InputType.TYPE_NUMBER_VARIATION_PASSWORD;
}
break;
default:
mView.setInputType(InputType.TYPE_CLASS_TEXT);
inputType = InputType.TYPE_CLASS_TEXT;
if (isPassword) {
inputType = inputType | InputType.TYPE_TEXT_VARIATION_PASSWORD;
}
break;
}
mView.setInputType(inputType);
}
break;
case "password":
if (prop.isBoolean()) {
final int variation =
mView.getInputType() & (EditorInfo.TYPE_MASK_CLASS | EditorInfo.TYPE_MASK_VARIATION);
if ((variation & EditorInfo.TYPE_CLASS_NUMBER) == EditorInfo.TYPE_CLASS_NUMBER) {
if (prop.asBoolean().value()) {
mView.setInputType(mView.getInputType() | InputType.TYPE_NUMBER_VARIATION_PASSWORD);
} else {
mView.setInputType(mView.getInputType() & (~InputType.TYPE_NUMBER_VARIATION_PASSWORD));
}
} else {
if (prop.asBoolean().value()) {
mView.setInputType(mView.getInputType() | InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
mView.setInputType(mView.getInputType() & (~InputType.TYPE_TEXT_VARIATION_PASSWORD));
}
}
}
break;
default:

View File

@ -1,33 +1,45 @@
import { Panel, Group, scroller, vlayout, layoutConfig, LayoutSpec, Input, Gravity, log, Color, input, text, InputType } from "doric";
import {
Panel,
Group,
scroller,
vlayout,
layoutConfig,
LayoutSpec,
Input,
Gravity,
log,
Color,
input,
text,
InputType,
} from "doric";
import { title, colors } from "./utils";
function getInput(c: Partial<Input>) {
const inputView = input(c)
const inputView = input(c);
const isFocused = text({
layoutConfig: {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
},
height: 50,
})
});
const inputed = text({
layoutConfig: {
widthSpec: LayoutSpec.MOST,
heightSpec: LayoutSpec.JUST,
},
height: 50,
})
});
inputView.onFocusChange = (onFocusChange) => {
isFocused.text = onFocusChange ? `Focused` : `Unfocused`
}
isFocused.text = onFocusChange ? `Focused` : `Unfocused`;
};
inputView.onTextChange = (text) => {
inputed.text = `Inputed:${text}`
}
return [inputView, isFocused, inputed]
inputed.text = `Inputed:${text}`;
};
return [inputView, isFocused, inputed];
}
@Entry
class InputDemo extends Panel {
build(root: Group) {
@ -45,12 +57,12 @@ class InputDemo extends Panel {
textSize: 20,
maxLength: 20,
padding: { top: 10, bottom: 11 },
inputType: InputType.Decimal
inputType: InputType.Decimal,
password: true,
});
scroller(
vlayout(
[
title("Demo"),
// ...getInput({
// layoutConfig: {
@ -74,13 +86,12 @@ class InputDemo extends Panel {
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.MOST),
onClick: () => {
(inputView as Input).releaseFocus(context);
}
},
}
),
{
layoutConfig: layoutConfig().most()
layoutConfig: layoutConfig().most(),
}
).in(root)
).in(root);
}
}

View File

@ -104,8 +104,8 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
}
view.textAlignment = alignment;
} else if ([name isEqualToString:@"multiline"]) {
BOOL mutilin = [(NSNumber *) prop boolValue];
if (!mutilin) {
BOOL value = [(NSNumber *) prop boolValue];
if (!value) {
view.textContainer.maximumNumberOfLines = 1;
} else {
view.textContainer.maximumNumberOfLines = 0;
@ -156,6 +156,8 @@ - (void)blendView:(DoricInputView *)view forPropName:(NSString *)name propValue:
break;
}
}
} else if ([name isEqualToString:@"password"]) {
self.view.secureTextEntry = [(NSNumber *) prop boolValue];
} else {
[super blendView:view forPropName:name propValue:prop];
}

View File

@ -2711,6 +2711,10 @@ var Input = /** @class */ (function (_super) {
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Boolean)
], Input.prototype, "password", void 0);
return Input;
}(View));
(function (InputType) {

View File

@ -2101,6 +2101,10 @@ __decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Boolean)
], Input.prototype, "password", void 0);
(function (InputType) {
InputType[InputType["Default"] = 0] = "Default";
InputType[InputType["Number"] = 1] = "Number";

View File

@ -3590,6 +3590,10 @@ __decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Boolean)
], Input.prototype, "password", void 0);
(function (InputType) {
InputType[InputType["Default"] = 0] = "Default";
InputType[InputType["Number"] = 1] = "Number";

1
doric-js/index.d.ts vendored
View File

@ -744,6 +744,7 @@ declare module 'doric/lib/src/widget/input' {
onTextChange?: (text: string) => void;
onFocusChange?: (focused: boolean) => void;
maxLength?: number;
password?: boolean;
getText(context: BridgeContext): Promise<string>;
setSelection(context: BridgeContext, start: number, end?: number): Promise<string>;
requestFocus(context: BridgeContext): Promise<any>;

View File

@ -14,6 +14,7 @@ export declare class Input extends View {
onTextChange?: (text: string) => void;
onFocusChange?: (focused: boolean) => void;
maxLength?: number;
password?: boolean;
getText(context: BridgeContext): Promise<string>;
setSelection(context: BridgeContext, start: number, end?: number): Promise<string>;
requestFocus(context: BridgeContext): Promise<any>;

View File

@ -87,6 +87,10 @@ __decorate([
Property,
__metadata("design:type", Number)
], Input.prototype, "maxLength", void 0);
__decorate([
Property,
__metadata("design:type", Boolean)
], Input.prototype, "password", void 0);
export var InputType;
(function (InputType) {
InputType[InputType["Default"] = 0] = "Default";

View File

@ -54,6 +54,9 @@ export class Input extends View {
@Property
maxLength?: number
@Property
password?: boolean
getText(context: BridgeContext) {
return this.nativeChannel(context, 'getText')() as Promise<string>
}

View File

@ -3648,6 +3648,10 @@ __decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Boolean)
], Input.prototype, "password", void 0);
(function (InputType) {
InputType[InputType["Default"] = 0] = "Default";
InputType[InputType["Number"] = 1] = "Number";

File diff suppressed because one or more lines are too long