Skip to content

Commit 2d86201

Browse files
duom青源duom青源
authored andcommitted
feat: 添加selectionChange
1 parent 02ff228 commit 2d86201

11 files changed

+77
-56
lines changed

example/src/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import {
77
TouchableOpacity,
88
Text,
99
Image,
10+
TextInput,
11+
NativeSyntheticEvent,
12+
TextInputKeyPressEventData,
1013
} from 'react-native';
1114
import {
1215
IATTextViewBase,
16+
IVSelection,
1317
IonMentionData,
1418
VariableTextInputView,
1519
} from 'react-native-variable-text-input';
@@ -72,11 +76,22 @@ export const App = () => {
7276
data,
7377
]);
7478
};
79+
const onSelectionChange = (e: IVSelection) => {
80+
console.log('==ddd===>', e.nativeEvent);
81+
};
82+
const onKeyPress = (e: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
83+
console.log('==onKeyPress==>', e.nativeEvent.key);
84+
};
7585
return (
7686
<View style={styles.container}>
7787
<Text onPress={onPressText} style={{ marginTop: 200, marginBottom: 50 }}>
7888
{'测试方法'}
7989
</Text>
90+
<TextInput
91+
style={{ marginTop: 50, width: '100%', height: 100 }}
92+
placeholder="ddddddd"
93+
onKeyPress={onKeyPress}
94+
/>
8095
<View>
8196
<View style={styles.hor}>
8297
<VariableTextInputView
@@ -97,6 +112,7 @@ export const App = () => {
97112
onFocus={() => {
98113
console.log('==onFocus==');
99114
}}
115+
onSelectionChange={onSelectionChange}
100116
/>
101117
<TouchableOpacity
102118
activeOpacity={0.85}

ios/VariableTextInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
4949
@property(nonatomic, copy, nullable) RCTDirectEventBlock onTextInput;
5050
@property(nonatomic, copy, nullable) RCTDirectEventBlock onBlur;
5151
@property(nonatomic, copy, nullable) RCTDirectEventBlock onFocus;
52+
@property(nonatomic, copy, nullable) RCTDirectEventBlock onIOSSelectionChange;
5253
@property(nonatomic, strong) NSDictionary *defultTypingAttributes;
5354
@property(nonatomic, strong) NSArray *tags;
5455
@property(nonatomic, strong) NSString *keyWord;

ios/VariableTextInput.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ - (void)textViewDidChangeSelection:(UITextView *)textView {
344344
}
345345
}
346346
self.cursorLocation = textView.selectedRange.location;
347+
NSRange selection = textView.selectedRange;
348+
if (_onIOSSelectionChange) {
349+
_onIOSSelectionChange(@{@"selection":@{@"start":[NSNumber numberWithInt:selection.location],@"end":[NSNumber numberWithInt:selection.location + selection.length]}});
350+
}
347351
}
348352

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

ios/VariableTextInputViewManager.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
4444
RCT_EXPORT_VIEW_PROPERTY(onFocus, RCTBubblingEventBlock)
4545
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock)
4646
RCT_EXPORT_VIEW_PROPERTY(onContentSizeChange, RCTBubblingEventBlock)
47+
RCT_EXPORT_VIEW_PROPERTY(onIOSSelectionChange, RCTBubblingEventBlock)
4748
RCT_EXPORT_VIEW_PROPERTY(onSubmitEditing, RCTBubblingEventBlock)
4849
RCT_CUSTOM_VIEW_PROPERTY(textAlign, NSTextAlignment, VariableTextInput)
4950
{

lib/commonjs/VariableTextInputView.js

Lines changed: 14 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/commonjs/VariableTextInputView.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/module/VariableTextInputView.js

Lines changed: 15 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)