feat:Input add password property
This commit is contained in:
parent
521ce19c1c
commit
07c701ef23
@ -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:
|
||||
|
@ -1,86 +1,97 @@
|
||||
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 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`
|
||||
}
|
||||
inputView.onTextChange = (text) => {
|
||||
inputed.text = `Inputed:${text}`
|
||||
}
|
||||
return [inputView, isFocused, inputed]
|
||||
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`;
|
||||
};
|
||||
inputView.onTextChange = (text) => {
|
||||
inputed.text = `Inputed:${text}`;
|
||||
};
|
||||
return [inputView, isFocused, inputed];
|
||||
}
|
||||
|
||||
|
||||
@Entry
|
||||
class InputDemo extends Panel {
|
||||
build(root: Group) {
|
||||
var [inputView, ...otherView] = getInput({
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.FIT,
|
||||
},
|
||||
hintText: "Please input something in one line",
|
||||
border: {
|
||||
width: 1,
|
||||
color: Color.GRAY,
|
||||
},
|
||||
multiline: false,
|
||||
textSize: 20,
|
||||
maxLength: 20,
|
||||
padding: { top: 10, bottom: 11 },
|
||||
inputType: InputType.Decimal
|
||||
});
|
||||
scroller(
|
||||
vlayout(
|
||||
[
|
||||
|
||||
title("Demo"),
|
||||
// ...getInput({
|
||||
// layoutConfig: {
|
||||
// widthSpec: LayoutSpec.JUST,
|
||||
// heightSpec: LayoutSpec.FIT,
|
||||
// },
|
||||
// width: 300,
|
||||
// hintText: "Please input something",
|
||||
// border: {
|
||||
// width: 1,
|
||||
// color: Color.GRAY,
|
||||
// },
|
||||
// textSize: 40,
|
||||
// maxLength: 20,
|
||||
// }),
|
||||
inputView,
|
||||
...otherView,
|
||||
],
|
||||
{
|
||||
space: 10,
|
||||
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.MOST),
|
||||
onClick: () => {
|
||||
(inputView as Input).releaseFocus(context);
|
||||
}
|
||||
}
|
||||
),
|
||||
{
|
||||
layoutConfig: layoutConfig().most()
|
||||
}
|
||||
).in(root)
|
||||
}
|
||||
|
||||
build(root: Group) {
|
||||
var [inputView, ...otherView] = getInput({
|
||||
layoutConfig: {
|
||||
widthSpec: LayoutSpec.FIT,
|
||||
heightSpec: LayoutSpec.FIT,
|
||||
},
|
||||
hintText: "Please input something in one line",
|
||||
border: {
|
||||
width: 1,
|
||||
color: Color.GRAY,
|
||||
},
|
||||
multiline: false,
|
||||
textSize: 20,
|
||||
maxLength: 20,
|
||||
padding: { top: 10, bottom: 11 },
|
||||
inputType: InputType.Decimal,
|
||||
password: true,
|
||||
});
|
||||
scroller(
|
||||
vlayout(
|
||||
[
|
||||
title("Demo"),
|
||||
// ...getInput({
|
||||
// layoutConfig: {
|
||||
// widthSpec: LayoutSpec.JUST,
|
||||
// heightSpec: LayoutSpec.FIT,
|
||||
// },
|
||||
// width: 300,
|
||||
// hintText: "Please input something",
|
||||
// border: {
|
||||
// width: 1,
|
||||
// color: Color.GRAY,
|
||||
// },
|
||||
// textSize: 40,
|
||||
// maxLength: 20,
|
||||
// }),
|
||||
inputView,
|
||||
...otherView,
|
||||
],
|
||||
{
|
||||
space: 10,
|
||||
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.MOST),
|
||||
onClick: () => {
|
||||
(inputView as Input).releaseFocus(context);
|
||||
},
|
||||
}
|
||||
),
|
||||
{
|
||||
layoutConfig: layoutConfig().most(),
|
||||
}
|
||||
).in(root);
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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";
|
||||
|
@ -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
1
doric-js/index.d.ts
vendored
@ -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>;
|
||||
|
1
doric-js/lib/src/widget/input.d.ts
vendored
1
doric-js/lib/src/widget/input.d.ts
vendored
@ -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>;
|
||||
|
@ -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";
|
||||
|
@ -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>
|
||||
}
|
||||
|
4
doric-web/dist/index.js
vendored
4
doric-web/dist/index.js
vendored
@ -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";
|
||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user