Skip to content

Commit

Permalink
Stop emitting deprecated onTextInput events (#44479)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #44479

TextInputs' onTextInput callback was removed way back in React Native 0.62 with 3f7e0a2 , 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

fbshipit-source-id: 5b0beee3d55b70717216fe8ceaf52444540f5adc
  • Loading branch information
javache authored and Titozzz committed Aug 4, 2024
1 parent 10e9669 commit 5da40cb
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,26 +493,13 @@ - (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) {
_predictedText = [backedTextInputView.attributedText.string stringByReplacingCharactersInRange: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.
}

Expand Down
9 changes: 0 additions & 9 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -7362,15 +7362,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 <init> (IILjava/lang/String;Ljava/lang/String;II)V
public fun <init> (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 <init> (Landroid/widget/EditText;)V
public fun apply (Landroid/widget/EditText;)V
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.facebook.react.uimanager.events.Event;

/** Event emitted by EditText native view when key pressed */
class ReactTextInputKeyPressEvent extends Event<ReactTextInputEvent> {
/* package */ class ReactTextInputKeyPressEvent extends Event<ReactTextInputKeyPressEvent> {

public static final String EVENT_NAME = "topKeyPress";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1122,17 +1122,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
Expand Down

0 comments on commit 5da40cb

Please sign in to comment.