feat:android input add maxLength

This commit is contained in:
刘涛 2020-04-30 16:36:28 +08:00 committed by osborn
parent b169f581d3
commit b7da580842
11 changed files with 50 additions and 4 deletions

View File

@ -16,6 +16,7 @@
package pub.doric.shader; package pub.doric.shader;
import android.text.Editable; import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType; import android.text.InputType;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -27,6 +28,8 @@ import android.widget.EditText;
import com.github.pengfeizhou.jscore.JSObject; import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue; import com.github.pengfeizhou.jscore.JSValue;
import java.util.LinkedList;
import pub.doric.DoricContext; import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricMethod; import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin; import pub.doric.extension.bridge.DoricPlugin;
@ -57,6 +60,22 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
@Override @Override
protected void blend(EditText view, String name, JSValue prop) { protected void blend(EditText view, String name, JSValue prop) {
switch (name) { switch (name) {
case "maxLength":
InputFilter[] currentFilters = view.getFilters();
LinkedList<InputFilter> list = new LinkedList<>();
for (int i = 0; i < currentFilters.length; i++) {
if (!(currentFilters[i] instanceof InputFilter.LengthFilter)) {
list.add(currentFilters[i]);
}
}
if(prop.isNumber()){
list.add( new InputFilter.LengthFilter(prop.asNumber().toInt()));
}
InputFilter[] newFilters = list.toArray(new InputFilter[list.size()]);
view.setFilters(newFilters);
break;
case "text": case "text":
view.setText(prop.asString().toString()); view.setText(prop.asString().toString());
break; break;

View File

@ -6,10 +6,12 @@ class InputDemo extends Panel {
scroller( scroller(
vlayout( vlayout(
[ [
title("Input Demo"),
title("Demo"),
(new Input).also(it => { (new Input).also(it => {
it.layoutConfig = layoutConfig().just().configHeight(LayoutSpec.FIT) it.layoutConfig = layoutConfig().just().configHeight(LayoutSpec.FIT)
it.width = 300 it.width = 300
it.maxLength=10;
it.multiline = false it.multiline = false
it.hintText = "HintText" it.hintText = "HintText"
it.textAlignment = Gravity.Left it.textAlignment = Gravity.Left

View File

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

View File

@ -1993,6 +1993,10 @@ __decorate$a([
Property, Property,
__metadata$a("design:type", Function) __metadata$a("design:type", Function)
], Input.prototype, "onFocusChange", void 0); ], Input.prototype, "onFocusChange", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
function input(config) { function input(config) {
const ret = new Input; const ret = new Input;
ret.layoutConfig = layoutConfig().just(); ret.layoutConfig = layoutConfig().just();

View File

@ -3452,6 +3452,10 @@ __decorate$a([
Property, Property,
__metadata$a("design:type", Function) __metadata$a("design:type", Function)
], Input.prototype, "onFocusChange", void 0); ], Input.prototype, "onFocusChange", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
function input(config) { function input(config) {
const ret = new Input; const ret = new Input;
ret.layoutConfig = layoutConfig().just(); ret.layoutConfig = layoutConfig().just();

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

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

View File

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

View File

@ -79,6 +79,10 @@ __decorate([
Property, Property,
__metadata("design:type", Function) __metadata("design:type", Function)
], Input.prototype, "onFocusChange", void 0); ], Input.prototype, "onFocusChange", void 0);
__decorate([
Property,
__metadata("design:type", Number)
], Input.prototype, "maxLength", void 0);
export function input(config) { export function input(config) {
const ret = new Input; const ret = new Input;
ret.layoutConfig = layoutConfig().just(); ret.layoutConfig = layoutConfig().just();

View File

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

View File

@ -3510,6 +3510,10 @@ __decorate$a([
Property, Property,
__metadata$a("design:type", Function) __metadata$a("design:type", Function)
], Input.prototype, "onFocusChange", void 0); ], Input.prototype, "onFocusChange", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
function input(config) { function input(config) {
const ret = new Input; const ret = new Input;
ret.layoutConfig = layoutConfig().just(); ret.layoutConfig = layoutConfig().just();

File diff suppressed because one or more lines are too long