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;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.TextUtils;
import android.text.TextWatcher;
@ -27,6 +28,8 @@ import android.widget.EditText;
import com.github.pengfeizhou.jscore.JSObject;
import com.github.pengfeizhou.jscore.JSValue;
import java.util.LinkedList;
import pub.doric.DoricContext;
import pub.doric.extension.bridge.DoricMethod;
import pub.doric.extension.bridge.DoricPlugin;
@ -57,6 +60,22 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
@Override
protected void blend(EditText view, String name, JSValue prop) {
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":
view.setText(prop.asString().toString());
break;

View File

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

View File

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

View File

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

View File

@ -3452,6 +3452,10 @@ __decorate$a([
Property,
__metadata$a("design:type", Function)
], Input.prototype, "onFocusChange", void 0);
__decorate$a([
Property,
__metadata$a("design:type", Number)
], Input.prototype, "maxLength", void 0);
function input(config) {
const ret = new Input;
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;
onTextChange?: (text: string) => void;
onFocusChange?: (focused: boolean) => void;
maxLength?: number;
getText(context: BridgeContext): Promise<string>;
setSelection(context: BridgeContext, start: number, end?: number): Promise<string>;
requestFocus(context: BridgeContext): Promise<any>;

View File

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

View File

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

View File

@ -48,6 +48,9 @@ export class Input extends View {
@Property
onFocusChange?: (focused: boolean) => void
@Property
maxLength?: number
getText(context: BridgeContext) {
return this.nativeChannel(context, 'getText')() as Promise<string>
}
@ -75,4 +78,4 @@ export function input(config: Partial<Input>) {
Reflect.set(ret, key, Reflect.get(config, key, config), ret)
}
return ret
}
}

View File

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

File diff suppressed because one or more lines are too long