Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify returnKeyType #1

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -289,28 +289,22 @@ public void setOnSelectionChange(final VariableTextInput view, boolean onSelecti
public void setKeyboardType(VariableTextInput view, String keyboardType) {
switch (keyboardType) {
case "default": {
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_TEXT);
}
break;
case "numeric":
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
break;
case "email-address":
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
break;
case "phone-pad":
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_PHONE);
break;
case "url":
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_TEXT | EditorInfo.TYPE_TEXT_VARIATION_URI);
break;
default:
view.setImeOptions(EditorInfo.IME_ACTION_NONE);
view.setInputType(EditorInfo.TYPE_CLASS_TEXT);
break;
}
Expand Down Expand Up @@ -382,6 +376,7 @@ public Map<String, Object> getConstants() {
"onAndroidBlur",
MapBuilder.of("registrationName", "onAndroidBlur")).put(
"onAndroidFocus",
MapBuilder.of("registrationName", "onAndroidFocus")).build();
MapBuilder.of("registrationName", "onAndroidFocus")).put("onAndroidSubmitEditing",
MapBuilder.of("registrationName", "onAndroidSubmitEditing")).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,18 @@ public void onPaste() {
new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
Log.d("Input", "onEditorAction actionId:" + actionId);
if (actionId == EditorInfo.IME_ACTION_SEARCH
|| actionId == EditorInfo.IME_ACTION_SEND
|| actionId == EditorInfo.IME_ACTION_DONE) {
WritableMap event = Arguments.createMap();
event.putString("text", editText.getText().toString());
final Context context = getContext();
if (context instanceof ReactContext) {
((ReactContext) context).getJSModule(RCTEventEmitter.class).receiveEvent(getId(), "onAndroidSubmitEditing", event);
}
return true;
}
if ((actionId & EditorInfo.IME_MASK_ACTION) != 0 || actionId == EditorInfo.IME_NULL) {
boolean isMultiline = true;

Expand Down Expand Up @@ -588,12 +600,15 @@ private void updateImeOptions() {
returnKeyFlag = EditorInfo.IME_ACTION_PREVIOUS;
break;
case "search":
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
returnKeyFlag = EditorInfo.IME_ACTION_SEARCH;
break;
case "send":
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
returnKeyFlag = EditorInfo.IME_ACTION_SEND;
break;
case "done":
editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
returnKeyFlag = EditorInfo.IME_ACTION_DONE;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion ios/VariableTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(assign, nonatomic, getter=isSupport) BOOL bSupport;
@property(nonatomic, copy) RCTBubblingEventBlock onChange;
@property (nonatomic, copy, nullable) RCTDirectEventBlock onContentSizeChange;
@property(nonatomic, copy) RCTBubblingEventBlock onSubmitEditing;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onSubmitEditing;
@property(nonatomic,copy, nullable)RCTDirectEventBlock onTag;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onBlur;
Expand Down
9 changes: 8 additions & 1 deletion ios/VariableTextInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,20 @@ - (void)textViewDidChangeSelection:(UITextView *)textView {
}

- (void)textViewDidChange:(UITextView *)textView {

if (_onChange) {
_onChange(@{@"text":[textView.textStorage getPlainString]});
}
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
// 处理键盘return事件
BOOL returnStatus = textView.returnKeyType == UIReturnKeyDone || textView.returnKeyType == UIReturnKeySend || textView.returnKeyType == UIReturnKeySearch;
if(returnStatus && [text isEqualToString:@"\n"]) {
if (self.onSubmitEditing) {
self.onSubmitEditing(@{@"text": [self.textStorage getPlainString]});
}
return NO;
}
NSString *oldStr = [self getStrContentInRange:NSMakeRange(0, [self.attributedText length])];
NSString *newStr = [NSString stringWithFormat:@"%@%@",oldStr,text];
[self handleTags:text];
Expand Down
1 change: 1 addition & 0 deletions ios/VariableTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ @implementation VariableTextInputViewManager
RCT_EXPORT_VIEW_PROPERTY(onFocus, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock)
RCT_CUSTOM_VIEW_PROPERTY(textAlign, NSTextAlignment, VariableTextInput)
{
[view setTextAlignment:[RCTConvert NSTextAlignment:json]];
Expand Down
17 changes: 14 additions & 3 deletions src/VariableTextInputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
TextInputContentSizeChangeEventData,
Platform,
KeyboardTypeOptions,
ReturnKeyTypeOptions,
} from 'react-native';
import React, {
forwardRef,
Expand Down Expand Up @@ -53,13 +54,14 @@
e: NativeSyntheticEvent<TextInputContentSizeChangeEventData>
) => void;
keyboardType?: KeyboardTypeOptions | undefined;
onSubmitEditing?: (text: string) => void;
onAndroidSubmitEditing?: (text: string) => void;
onSubmitEditing?: (e: NativeSyntheticEvent<TextInputChangeEventData>) => void;
onAndroidSubmitEditing?: (e: IVTTextInputData) => void;
submitBehavior?: 'submit';
onBlur?: () => void;
onFocus?: () => void;
onAndroidFocus?: () => void;
onAndroidBlur?: () => void;
returnKeyType?: ReturnKeyTypeOptions | undefined;
}
interface IProps {
style?: StyleProp<TextStyle> | undefined;
Expand All @@ -84,6 +86,7 @@
onMention?: (data: IonMentionData) => void;
onBlur?: () => void;
onFocus?: () => void;
returnKeyType?: ReturnKeyTypeOptions | undefined;
}
export type IATTextViewRef = React.ForwardedRef<IATTextViewBase>;

Expand All @@ -105,7 +108,7 @@
setMention(lastStr);
props.onMention && props.onMention({ mention: lastStr, keyWord: '' });
}
if (!!mention) {

Check warning on line 111 in src/VariableTextInputView.tsx

View workflow job for this annotation

GitHub Actions / lint

Redundant double negation
const result = text.split(mention).pop();
const mentionData: IonMentionData = {
mention,
Expand All @@ -128,7 +131,7 @@
// }
// }, [props.text]);
const clearMention = () => {
if (!!mention) {

Check warning on line 134 in src/VariableTextInputView.tsx

View workflow job for this annotation

GitHub Actions / lint

Redundant double negation
setMention('');
setKeyWord('');
}
Expand Down Expand Up @@ -157,7 +160,7 @@
UIManager.dispatchViewManagerCommand(
reactTag,
commandId,
!!data ? data : []

Check warning on line 163 in src/VariableTextInputView.tsx

View workflow job for this annotation

GitHub Actions / lint

Redundant double negation
);
};
const insertEmoji = (data: IInserTextAttachmentItem) => {
Expand Down Expand Up @@ -236,7 +239,14 @@
insertMentionAndDelateKeyword: insertMentionAndDelateKeyword,
};
});
const onAndroidSubmitEditing = () => {};
const _onSubmitEditing = (
e: NativeSyntheticEvent<TextInputChangeEventData>
) => {
props.onSubmitEditing && props.onSubmitEditing(e.nativeEvent.text);
};
const onAndroidSubmitEditing = (e: IVTTextInputData) => {
props.onSubmitEditing && props.onSubmitEditing(e.nativeEvent.text);
};
const onAndroidTextInput = (e: IVTTextInputData) => {
props.onTextInput && props.onTextInput(e);
};
Expand All @@ -249,6 +259,7 @@
onAndroidChange={_onChange}
onAndroidContentSizeChange={onContentSizeChange}
{...props}
onSubmitEditing={_onSubmitEditing}
onAndroidSubmitEditing={onAndroidSubmitEditing}
onAndroidTextInput={onAndroidTextInput}
onAndroidBlur={props.onBlur}
Expand Down
Loading