Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput onSelectionChange() is fired before onChangeText() in IOS, and fired after onChangeText() in Android when letter typed #28865

Closed
amourlanne opened this issue May 10, 2020 · 8 comments
Labels
Component: TextInput Related to the TextInput component. Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Platform: Android Android applications. Platform: iOS iOS applications.

Comments

@amourlanne
Copy link

Description

TextInput onSelectionChange() is fired before onChangeText() in IOS, and fired after onChangeText() in Android when letter is typed

React Native Environment Info

System

  • OS: Windows 10
  • CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  • Memory: 3.35 GB / 15.89 GB

Binaries

  • Node: 12.9.0
  • Yarn: 1.22.4
  • npm: 6.10.2

SDK sdk-35.0.0

Steps To Reproduce

<TextInput
      multiline
      onChangeText={() => console.log('onChangeText')}
      onSelectionChange={() => console.log('onSelectionChange')} />
  1. type letter on input

IOS

onSelectionChange
onChangeText

Android

onChangeText
onSelectionChange

Expected Results

In the same order

@react-native-bot react-native-bot added Component: TextInput Related to the TextInput component. Platform: Android Android applications. Platform: iOS iOS applications. Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. and removed Needs: Triage 🔍 labels May 10, 2020
@github-actions
Copy link

⚠️ Missing Environment Information
ℹ️ Your issue may be missing information about your development environment. You can obtain the missing information by running react-native info in a console.

@JamesMahy
Copy link

I've just come across this issue as well

System:
    OS: macOS 10.15.5
    CPU: (8) x64 Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz
    Memory: 7.69 GB / 32.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.4.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.5, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
    Android SDK:
      API Levels: 27, 28, 29
      Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.0
      System Images: android-27 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom, android-R | Google APIs Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6514223
    Xcode: 11.5/11E608c - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_252 - /usr/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.9.0 => 16.9.0 
    react-native: ^0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

@HyungGilHam
Copy link

HyungGilHam commented Sep 21, 2020

same issue!

System:
OS: macOS 10.15.5
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Memory: 159.66 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.16.2 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.7, DriverKit 19.0, macOS 10.15, tvOS 13.4, watchOS 6.2
Android SDK:
API Levels: 25, 26, 28, 29
Build Tools: 27.0.3, 28.0.3, 29.0.2, 29.0.3
System Images: android-28 | Google Play Intel x86 Atom
Android NDK: 21.0.6113669
IDEs:
Android Studio: 4.0 AI-193.6911.18.40.6626763
Xcode: 11.7/11E801a - /usr/bin/xcodebuild
npmPackages:
react: ~16.9.0 => 16.9.0
react-native: ~0.61.5 => 0.61.5
npmGlobalPackages:
create-react-native-module: 0.11.1
react-native-cli: 2.0.1
react-native-drawer-menu: 0.2.5
react-native-git-upgrade: 0.2.7

@davidmrp
Copy link

Same issue here!

@tomgransden
Copy link

Same issue here, working on a project that needs mentions and this is tripping us up too.

@gpfunk
Copy link

gpfunk commented Jan 15, 2021

This isn't a perfect solution but we ended up calculating the current selection in the onChangeText callback.

If it was IOS we could just use the current selection passed back from onSelectionChange (stored in a ref), and if it was android we would add / subtract the difference in length between the updated and previous value from the selection ref start and end values...there is some nuances for multi char removal etc. but that was the general idea

@Yoshihide-Nishimoto
Copy link

@tomgransden

Have you already resolved this?

Same issue here, working on a project that needs mentions and this is tripping us up too.

I'm stucking on this in same situation, my mention tracking doesn't work for this issue....

kelset pushed a commit that referenced this issue Jan 19, 2023
Summary:
Switched order of onSelectionChange and onChange events on iOS

This was already fixed but for fabric only https://github.com/facebook/react-native/blob/main/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm#L36-L46

This PR is a complementary of 7b48899

Fixes #28865

## Changelog

[IOS] [FIXED] - onSelectionChange() is fired before onChange() on multiline TextInput

Pull Request resolved: #35603

Test Plan:
Reproduce the minimal example provided here #28865
Verify that the events order is onChange then onSelectionChange with no duplicates

Reviewed By: cipolleschi

Differential Revision: D41947673

Pulled By: dmytrorykun

fbshipit-source-id: cf452a6101400b1b54295c83fa7735449d91e781
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this issue May 22, 2023
…k#35603)

Summary:
Switched order of onSelectionChange and onChange events on iOS

This was already fixed but for fabric only https://github.com/facebook/react-native/blob/main/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm#L36-L46

This PR is a complementary of facebook@7b48899

Fixes facebook#28865

## Changelog

[IOS] [FIXED] - onSelectionChange() is fired before onChange() on multiline TextInput

Pull Request resolved: facebook#35603

Test Plan:
Reproduce the minimal example provided here facebook#28865
Verify that the events order is onChange then onSelectionChange with no duplicates

Reviewed By: cipolleschi

Differential Revision: D41947673

Pulled By: dmytrorykun

fbshipit-source-id: cf452a6101400b1b54295c83fa7735449d91e781
@manuelbattaglia
Copy link

same issues here, any solutions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: TextInput Related to the TextInput component. Needs: Author Feedback Needs: Environment Info Please run `react-native info` and edit your issue with that command's output. Platform: Android Android applications. Platform: iOS iOS applications.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants