feat:android input add maxLength
This commit is contained in:
parent
b169f581d3
commit
b7da580842
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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
1
doric-js/index.d.ts
vendored
@ -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>;
|
||||
|
1
doric-js/lib/src/widget/input.d.ts
vendored
1
doric-js/lib/src/widget/input.d.ts
vendored
@ -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>;
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
4
doric-web/dist/index.js
vendored
4
doric-web/dist/index.js
vendored
@ -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();
|
||||
|
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