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 @@ -115,8 +115,19 @@ }; async getValueAndReset(): Promise { - 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; } @@ -154,7 +165,6 @@ {...props} style={[props.style, styles.invisibleTextInput]} onChangeText={this.onOldInputChangeText} - onSelectionChange={this.props.onSelectionChange} onKeyPress={this.onOldInputKeyPress} onBlur={this.onOldInputBlur} onFocus={this.onOldInputFocus} @@ -168,7 +178,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 { + 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 @@