From 7dc249b50ac09545ffcabf963b8499201fee8cb8 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Wed, 8 May 2024 02:32:32 -0700 Subject: [PATCH] Stop emitting deprecated onTextInput events Summary: TextInputs' onTextInput callback was removed way back in React Native 0.62 with https://github.com/facebook/react-native/commit/3f7e0a2c9601fc186f25bfd794cd0008ac3983ab , but remnants of the implementation exists. We first have to remove the event emitting in native code, and can land the full removal separately in D57092733, once there's no older client references remaining to this event. Changelog: [General][Removed] Remove deprecated onTextInput callback Reviewed By: cipolleschi Differential Revision: D57092734 --- .../Text/TextInput/RCTBaseTextInputView.mm | 13 ---- .../ReactAndroid/api/ReactAndroid.api | 9 --- .../views/textinput/ReactTextInputEvent.java | 70 ------------------- .../ReactTextInputKeyPressEvent.java | 2 +- .../textinput/ReactTextInputManager.java | 5 -- 5 files changed, 1 insertion(+), 98 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputEvent.java diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index b0d71dcd3508..20b953520b6e 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -493,8 +493,6 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range } } - NSString *previousText = [backedTextInputView.attributedText.string copy] ?: @""; - if (range.location + range.length > backedTextInputView.attributedText.string.length) { _predictedText = backedTextInputView.attributedText.string; } else if (text != nil) { @@ -502,17 +500,6 @@ - (NSString *)textInputShouldChangeText:(NSString *)text inRange:(NSRange)range withString:text]; } - if (_onTextInput) { - _onTextInput(@{ - // We copy the string here because if it's a mutable string it may get released before we stop using it on a - // different thread, causing a crash. - @"text" : [text copy], - @"previousText" : previousText, - @"range" : @{@"start" : @(range.location), @"end" : @(range.location + range.length)}, - @"eventCount" : @(_nativeEventCount), - }); - } - return text; // Accepting the change. } diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 7cf74483ef6f..40078fc9cc95 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7662,15 +7662,6 @@ public class com/facebook/react/views/textinput/ReactTextChangedEvent : com/face public fun getEventName ()Ljava/lang/String; } -public class com/facebook/react/views/textinput/ReactTextInputEvent : com/facebook/react/uimanager/events/Event { - public static final field EVENT_NAME Ljava/lang/String; - public fun (IILjava/lang/String;Ljava/lang/String;II)V - public fun (ILjava/lang/String;Ljava/lang/String;II)V - public fun canCoalesce ()Z - protected fun getEventData ()Lcom/facebook/react/bridge/WritableMap; - public fun getEventName ()Ljava/lang/String; -} - public final class com/facebook/react/views/textinput/ReactTextInputLocalData { public fun (Landroid/widget/EditText;)V public fun apply (Landroid/widget/EditText;)V diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputEvent.java deleted file mode 100644 index 2f4fb2fa7836..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputEvent.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.react.views.textinput; - -import androidx.annotation.Nullable; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.common.ViewUtil; -import com.facebook.react.uimanager.events.Event; - -/** - * Event emitted by EditText native view when text changes. VisibleForTesting from {@link - * TextInputEventsTestCase}. - */ -public class ReactTextInputEvent extends Event { - - public static final String EVENT_NAME = "topTextInput"; - - private String mText; - private String mPreviousText; - private int mRangeStart; - private int mRangeEnd; - - @Deprecated - public ReactTextInputEvent( - int viewId, String text, String previousText, int rangeStart, int rangeEnd) { - this(ViewUtil.NO_SURFACE_ID, viewId, text, previousText, rangeStart, rangeEnd); - } - - public ReactTextInputEvent( - int surfaceId, int viewId, String text, String previousText, int rangeStart, int rangeEnd) { - super(surfaceId, viewId); - mText = text; - mPreviousText = previousText; - mRangeStart = rangeStart; - mRangeEnd = rangeEnd; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - // We don't want to miss any textinput event, as event data is incremental. - return false; - } - - @Nullable - @Override - protected WritableMap getEventData() { - WritableMap eventData = Arguments.createMap(); - WritableMap range = Arguments.createMap(); - range.putDouble("start", mRangeStart); - range.putDouble("end", mRangeEnd); - - eventData.putString("text", mText); - eventData.putString("previousText", mPreviousText); - eventData.putMap("range", range); - - eventData.putInt("target", getViewTag()); - return eventData; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java index 6cf22e00f78e..9973b6ec2a57 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputKeyPressEvent.java @@ -14,7 +14,7 @@ import com.facebook.react.uimanager.events.Event; /** Event emitted by EditText native view when key pressed */ -class ReactTextInputKeyPressEvent extends Event { +/* package */ class ReactTextInputKeyPressEvent extends Event { public static final String EVENT_NAME = "topKeyPress"; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java index eb6fcab6e0ff..b2110398dc11 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactTextInputManager.java @@ -1120,17 +1120,12 @@ public void onTextChanged(CharSequence s, int start, int before, int count) { } // The event that contains the event counter and updates it must be sent first. - // TODO: t7936714 merge these events mEventDispatcher.dispatchEvent( new ReactTextChangedEvent( mSurfaceId, mEditText.getId(), s.toString(), mEditText.incrementAndGetEventCounter())); - - mEventDispatcher.dispatchEvent( - new ReactTextInputEvent( - mSurfaceId, mEditText.getId(), newText, oldText, start, start + before)); } @Override