Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3699843
D6767.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D6767.diff
View Options
diff --git a/native/components/clearable-text-input.react.ios.js b/native/components/clearable-text-input.react.ios.js
--- a/native/components/clearable-text-input.react.ios.js
+++ b/native/components/clearable-text-input.react.ios.js
@@ -114,8 +114,19 @@
};
async getValueAndReset(): Promise<string> {
- const { value } = this.props;
+ // We are doing something very naughty here, which is that we are
+ // constructing a fake nativeEvent. We are certainly not including all the
+ // fields that the type is expected to have, which is why we need to
+ // any-type it. We know this is okay because the code that uses
+ // ClearableTextInput only accesses event.nativeEvent.selection
+ const fakeSelectionEvent: any = {
+ nativeEvent: { selection: { end: 0, start: 0 } },
+ };
+ this.props.onSelectionChange?.(fakeSelectionEvent);
+
this.props.onChangeText('');
+
+ const { value } = this.props;
if (!this.focused) {
return value;
}
@@ -153,7 +164,6 @@
{...props}
style={[props.style, styles.invisibleTextInput]}
onChangeText={this.onOldInputChangeText}
- onSelectionChange={this.props.onSelectionChange}
onKeyPress={this.onOldInputKeyPress}
onBlur={this.onOldInputBlur}
onFocus={this.onOldInputFocus}
@@ -167,7 +177,6 @@
onFocus={this.onFocus}
onBlur={this.onBlur}
onChangeText={this.props.onChangeText}
- onSelectionChange={this.props.onSelectionChange}
key={this.state.textInputKey}
ref={this.textInputRef}
/>,
diff --git a/native/components/clearable-text-input.react.js b/native/components/clearable-text-input.react.js
--- a/native/components/clearable-text-input.react.js
+++ b/native/components/clearable-text-input.react.js
@@ -30,9 +30,20 @@
};
getValueAndReset(): Promise<string> {
+ this.props.onChangeText('');
+
+ // We are doing something very naughty here, which is that we are
+ // constructing a fake nativeEvent. We are certainly not including all the
+ // fields that the type is expected to have, which is why we need to
+ // any-type it. We know this is okay because the code that uses
+ // ClearableTextInput only accesses event.nativeEvent.selection
+ const fakeSelectionEvent: any = {
+ nativeEvent: { selection: { end: 0, start: 0 } },
+ };
+ this.props.onSelectionChange?.(fakeSelectionEvent);
+
const { value } = this.props;
this.lastMessageSent = value;
- this.props.onChangeText('');
if (this.textInput) {
this.textInput.clear();
}
@@ -60,7 +71,6 @@
<TextInput
{...props}
onChangeText={this.onChangeText}
- onSelectionChange={this.props.onSelectionChange}
ref={this.textInputRef}
/>
</View>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 8, 3:54 PM (2 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2809871
Default Alt Text
D6767.diff (2 KB)
Attached To
Mode
D6767: [native] Emit artificial onSelectionChange alongside onChangeText in ClearableTextInput
Attached
Detach File
Event Timeline
Log In to Comment