feat:Input add getSelection API
This commit is contained in:
parent
5263731dd7
commit
e528630f71
@ -19,6 +19,7 @@ import android.content.Context;
|
|||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputFilter;
|
import android.text.InputFilter;
|
||||||
import android.text.InputType;
|
import android.text.InputType;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
@ -30,9 +31,12 @@ import android.view.inputmethod.InputMethodManager;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||||
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 org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
@ -73,15 +77,15 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
|
|||||||
InputFilter[] currentFilters = view.getFilters();
|
InputFilter[] currentFilters = view.getFilters();
|
||||||
|
|
||||||
LinkedList<InputFilter> list = new LinkedList<>();
|
LinkedList<InputFilter> list = new LinkedList<>();
|
||||||
for (int i = 0; i < currentFilters.length; i++) {
|
for (InputFilter currentFilter : currentFilters) {
|
||||||
if (!(currentFilters[i] instanceof InputFilter.LengthFilter)) {
|
if (!(currentFilter instanceof InputFilter.LengthFilter)) {
|
||||||
list.add(currentFilters[i]);
|
list.add(currentFilter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (prop.isNumber()) {
|
if (prop.isNumber()) {
|
||||||
list.add(new InputFilter.LengthFilter(prop.asNumber().toInt()));
|
list.add(new InputFilter.LengthFilter(prop.asNumber().toInt()));
|
||||||
}
|
}
|
||||||
InputFilter[] newFilters = list.toArray(new InputFilter[list.size()]);
|
InputFilter[] newFilters = list.toArray(new InputFilter[0]);
|
||||||
|
|
||||||
view.setFilters(newFilters);
|
view.setFilters(newFilters);
|
||||||
break;
|
break;
|
||||||
@ -288,6 +292,14 @@ public class InputNode extends ViewNode<EditText> implements TextWatcher, View.O
|
|||||||
doricPromise.resolve();
|
doricPromise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DoricMethod
|
||||||
|
public JSONObject getSelection() {
|
||||||
|
return new JSONBuilder()
|
||||||
|
.put("start", mView.getSelectionStart())
|
||||||
|
.put("end", mView.getSelectionEnd())
|
||||||
|
.toJSONObject();
|
||||||
|
}
|
||||||
|
|
||||||
@DoricMethod
|
@DoricMethod
|
||||||
public void requestFocus(DoricPromise promise) {
|
public void requestFocus(DoricPromise promise) {
|
||||||
mView.requestFocus();
|
mView.requestFocus();
|
||||||
|
@ -67,6 +67,17 @@ function getInput(c: Partial<Input>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
preferenceView().applyChild({
|
||||||
|
title: {
|
||||||
|
text: "maxLength"
|
||||||
|
},
|
||||||
|
switch: {
|
||||||
|
state: true,
|
||||||
|
onSwitch: (ret) => {
|
||||||
|
inputView.maxLength = 20
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,6 +243,13 @@ - (void)setSelection:(NSDictionary *)params withPromise:(DoricPromise *)promise
|
|||||||
[promise resolve:nil];
|
[promise resolve:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDictionary *)getSelection {
|
||||||
|
return @{
|
||||||
|
@"start": @([self.view offsetFromPosition:self.view.beginningOfDocument toPosition:self.view.selectedTextRange.start]),
|
||||||
|
@"end": @([self.view offsetFromPosition:self.view.beginningOfDocument toPosition:self.view.selectedTextRange.end]),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
- (void)requestFocus {
|
- (void)requestFocus {
|
||||||
[self.view becomeFirstResponder];
|
[self.view becomeFirstResponder];
|
||||||
}
|
}
|
||||||
|
@ -2791,6 +2791,9 @@ var Input = /** @class */ (function (_super) {
|
|||||||
end: end,
|
end: end,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Input.prototype.getSelection = function (context) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')();
|
||||||
|
};
|
||||||
Input.prototype.requestFocus = function (context) {
|
Input.prototype.requestFocus = function (context) {
|
||||||
return this.nativeChannel(context, 'requestFocus')();
|
return this.nativeChannel(context, 'requestFocus')();
|
||||||
};
|
};
|
||||||
|
@ -2154,6 +2154,9 @@ class Input extends View {
|
|||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
getSelection(context) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')();
|
||||||
|
}
|
||||||
requestFocus(context) {
|
requestFocus(context) {
|
||||||
return this.nativeChannel(context, 'requestFocus')();
|
return this.nativeChannel(context, 'requestFocus')();
|
||||||
}
|
}
|
||||||
|
@ -3675,6 +3675,9 @@ class Input extends View {
|
|||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
getSelection(context) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')();
|
||||||
|
}
|
||||||
requestFocus(context) {
|
requestFocus(context) {
|
||||||
return this.nativeChannel(context, 'requestFocus')();
|
return this.nativeChannel(context, 'requestFocus')();
|
||||||
}
|
}
|
||||||
|
6
doric-js/index.d.ts
vendored
6
doric-js/index.d.ts
vendored
@ -785,7 +785,11 @@ declare module 'doric/lib/src/widget/input' {
|
|||||||
returnKeyType?: ReturnKeyType;
|
returnKeyType?: ReturnKeyType;
|
||||||
onSubmitEditing?: (text: string) => void;
|
onSubmitEditing?: (text: string) => void;
|
||||||
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<any>;
|
||||||
|
getSelection(context: BridgeContext): Promise<{
|
||||||
|
start: number;
|
||||||
|
end: number;
|
||||||
|
}>;
|
||||||
requestFocus(context: BridgeContext): Promise<any>;
|
requestFocus(context: BridgeContext): Promise<any>;
|
||||||
releaseFocus(context: BridgeContext): Promise<any>;
|
releaseFocus(context: BridgeContext): Promise<any>;
|
||||||
}
|
}
|
||||||
|
6
doric-js/lib/src/widget/input.d.ts
vendored
6
doric-js/lib/src/widget/input.d.ts
vendored
@ -27,7 +27,11 @@ export declare class Input extends View {
|
|||||||
returnKeyType?: ReturnKeyType;
|
returnKeyType?: ReturnKeyType;
|
||||||
onSubmitEditing?: (text: string) => void;
|
onSubmitEditing?: (text: string) => void;
|
||||||
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<any>;
|
||||||
|
getSelection(context: BridgeContext): Promise<{
|
||||||
|
start: number;
|
||||||
|
end: number;
|
||||||
|
}>;
|
||||||
requestFocus(context: BridgeContext): Promise<any>;
|
requestFocus(context: BridgeContext): Promise<any>;
|
||||||
releaseFocus(context: BridgeContext): Promise<any>;
|
releaseFocus(context: BridgeContext): Promise<any>;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,9 @@ export class Input extends View {
|
|||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
getSelection(context) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')();
|
||||||
|
}
|
||||||
requestFocus(context) {
|
requestFocus(context) {
|
||||||
return this.nativeChannel(context, 'requestFocus')();
|
return this.nativeChannel(context, 'requestFocus')();
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,6 @@ export class Input extends View {
|
|||||||
@Property
|
@Property
|
||||||
onSubmitEditing?: (text: string) => void
|
onSubmitEditing?: (text: string) => void
|
||||||
|
|
||||||
|
|
||||||
getText(context: BridgeContext) {
|
getText(context: BridgeContext) {
|
||||||
return this.nativeChannel(context, 'getText')() as Promise<string>
|
return this.nativeChannel(context, 'getText')() as Promise<string>
|
||||||
}
|
}
|
||||||
@ -84,9 +83,17 @@ export class Input extends View {
|
|||||||
return this.nativeChannel(context, 'setSelection')({
|
return this.nativeChannel(context, 'setSelection')({
|
||||||
start,
|
start,
|
||||||
end,
|
end,
|
||||||
}) as Promise<string>
|
}) as Promise<any>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getSelection(context: BridgeContext) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')() as Promise<{
|
||||||
|
start: number,
|
||||||
|
end: number,
|
||||||
|
}>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
requestFocus(context: BridgeContext) {
|
requestFocus(context: BridgeContext) {
|
||||||
return this.nativeChannel(context, 'requestFocus')()
|
return this.nativeChannel(context, 'requestFocus')()
|
||||||
}
|
}
|
||||||
|
3
doric-web/dist/index.js
vendored
3
doric-web/dist/index.js
vendored
@ -3729,6 +3729,9 @@ class Input extends View {
|
|||||||
end,
|
end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
getSelection(context) {
|
||||||
|
return this.nativeChannel(context, 'getSelection')();
|
||||||
|
}
|
||||||
requestFocus(context) {
|
requestFocus(context) {
|
||||||
return this.nativeChannel(context, 'requestFocus')();
|
return this.nativeChannel(context, 'requestFocus')();
|
||||||
}
|
}
|
||||||
|
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