Skip to content
Open
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 @@ -29,6 +29,7 @@ type TextInputChangeEventData = $ReadOnly<{
eventCount: number,
target: number,
text: string,
selection?: Selection,
}>;

export type TextInputChangeEvent =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ internal class ReactTextChangedEvent(
viewId: Int,
private val text: String,
private val eventCount: Int,
private val selectionStart: Int,
private val selectionEnd: Int,
) : Event<ReactTextChangedEvent>(surfaceId, viewId) {
override fun getEventName(): String = EVENT_NAME

Expand All @@ -25,6 +27,12 @@ internal class ReactTextChangedEvent(
putString("text", text)
putInt("eventCount", eventCount)
putInt("target", viewTag)
val selectionData =
Arguments.createMap().apply {
putInt("start", selectionStart)
putInt("end", selectionEnd)
}
putMap("selection", selectionData)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ internal class ReactTextInputTextWatcher(
editText.id,
s.toString(),
editText.incrementAndGetEventCounter(),
editText.selectionStart,
editText.selectionEnd,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void TextInputEventEmitter::onBlur(const Metrics& textInputMetrics) const {
}

void TextInputEventEmitter::onChange(const Metrics& textInputMetrics) const {
dispatchTextInputEvent("change", textInputMetrics);
dispatchTextInputEvent("change", textInputMetrics, true);
}

void TextInputEventEmitter::onContentSizeChange(
Expand Down
9 changes: 5 additions & 4 deletions packages/react-native/ReactNativeApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bffba0612c645ddb6166e1f5bb1187f2>>
* @generated SignedSource<<249ca589a73aaef41a965bcf3a2c0208>>
*
* This file was generated by scripts/js-api/build-types/index.js.
*/
Expand Down Expand Up @@ -5277,6 +5277,7 @@ declare type TextInputChangeEvent =
NativeSyntheticEvent<TextInputChangeEventData>
declare type TextInputChangeEventData = {
readonly eventCount: number
readonly selection?: Selection
readonly target: number
readonly text: string
}
Expand Down Expand Up @@ -6189,15 +6190,15 @@ export {
TaskProvider, // 266dedf2
Text, // e55ac2e2
TextContentType, // 239b3ecc
TextInput, // cf7a3331
TextInput, // 2e89b91d
TextInputAndroidProps, // 3f09ce49
TextInputChangeEvent, // 380cbe93
TextInputChangeEvent, // 6821f629
TextInputContentSizeChangeEvent, // 5fba3f54
TextInputEndEditingEvent, // 8c22fac3
TextInputFocusEvent, // c36e977c
TextInputIOSProps, // 0d05a855
TextInputKeyPressEvent, // 967178c2
TextInputProps, // a817a7f7
TextInputProps, // c75f0362
TextInputSelectionChangeEvent, // a1a7622f
TextInputSubmitEditingEvent, // 48d903af
TextLayoutEvent, // 45b0a8d7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,14 @@ class TextEventsExample extends React.Component<{...}, $FlowFixMe> {
onFocus={() => this.updateText('onFocus')}
onBlur={() => this.updateText('onBlur')}
onChange={event =>
this.updateText('onChange text: ' + event.nativeEvent.text)
this.updateText(
'onChange text: ' +
event.nativeEvent.text +
', selection: ' +
(event.nativeEvent.selection != null
? JSON.stringify(event.nativeEvent.selection)
: 'undefined'),
)
}
onContentSizeChange={event =>
this.updateText(
Expand Down
Loading