Skip to content

Commit

Permalink
feat: 添加selectionChange
Browse files Browse the repository at this point in the history
  • Loading branch information
duom青源 authored and duom青源 committed Apr 29, 2024
1 parent 02ff228 commit 2d86201
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 56 deletions.
16 changes: 16 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ import {
TouchableOpacity,
Text,
Image,
TextInput,
NativeSyntheticEvent,
TextInputKeyPressEventData,
} from 'react-native';
import {
IATTextViewBase,
IVSelection,
IonMentionData,
VariableTextInputView,
} from 'react-native-variable-text-input';
Expand Down Expand Up @@ -72,11 +76,22 @@ export const App = () => {
data,
]);
};
const onSelectionChange = (e: IVSelection) => {
console.log('==ddd===>', e.nativeEvent);
};
const onKeyPress = (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
console.log('==onKeyPress==>', e.nativeEvent.key);
};
return (
<View style={styles.container}>
<Text onPress={onPressText} style={{ marginTop: 200, marginBottom: 50 }}>
{'测试方法'}
</Text>
<TextInput
style={{ marginTop: 50, width: '100%', height: 100 }}
placeholder="ddddddd"
onKeyPress={onKeyPress}
/>
<View>
<View style={styles.hor}>
<VariableTextInputView
Expand All @@ -97,6 +112,7 @@ export const App = () => {
onFocus={() => {
console.log('==onFocus==');
}}
onSelectionChange={onSelectionChange}
/>
<TouchableOpacity
activeOpacity={0.85}
Expand Down
1 change: 1 addition & 0 deletions ios/VariableTextInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
@property(nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onBlur;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onFocus;
@property(nonatomic, copy, nullable) RCTDirectEventBlock onIOSSelectionChange;
@property(nonatomic, strong) NSDictionary *defultTypingAttributes;
@property(nonatomic, strong) NSArray *tags;
@property(nonatomic, strong) NSString *keyWord;
Expand Down
4 changes: 4 additions & 0 deletions ios/VariableTextInput.m
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,10 @@ - (void)textViewDidChangeSelection:(UITextView *)textView {
}
}
self.cursorLocation = textView.selectedRange.location;
NSRange selection = textView.selectedRange;
if (_onIOSSelectionChange) {
_onIOSSelectionChange(@{@"selection":@{@"start":[NSNumber numberWithInt:selection.location],@"end":[NSNumber numberWithInt:selection.location + selection.length]}});
}
}

- (void)textViewDidChange:(UITextView *)textView {
Expand Down
1 change: 1 addition & 0 deletions ios/VariableTextInputViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
RCT_EXPORT_VIEW_PROPERTY(onFocus, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onIOSSelectionChange, RCTBubblingEventBlock)
RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock)
RCT_CUSTOM_VIEW_PROPERTY(textAlign, NSTextAlignment, VariableTextInput)
{
Expand Down
40 changes: 14 additions & 26 deletions lib/commonjs/VariableTextInputView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/commonjs/VariableTextInputView.js.map

Large diffs are not rendered by default.

42 changes: 15 additions & 27 deletions lib/module/VariableTextInputView.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2d86201

Please sign in to comment.