react-native/Libraries
hamaron 1ffb2b63be iOS: Fixed the bug where a Backspace event was emitted when entering characters after clearing a text in TextInput by an empty string (#18627)
Summary:
The bug #18374 was caused by the loose condition to execute `stringByReplacingCharactersInRange` in the method `textInputShouldChangeTextInRange` . As a result, `findMismatch` wrongly returning `true` which ends up the Backspace event being fired in another `textInputShouldChangeTextInRange` call in `textInputDidChange`.

<!--
  Required: Write your motivation here.
  If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue when the PR is merged.
-->

1. Pass all the tests by `yarn run test`
2. Run the following code and type any text. (This code is brought from #18374. Thank you michalpetrov!!) And then verify that 'Backspace' events are not emitted after clearing text
and entering any letters.

```javascript
type Props = {};
type State = {
  text: string,
  keys: string
};
export default class App extends Component<Props, State> {
  state = {text: '', keys: ''}
  render() {
    return (
      <View style={styles.container}>
        <TextInput style={styles.textInput} value={this.state.text} onChangeText={this.onChangeText} onKeyPress={this.onKeyPress}/>
        <Button title="Clear" onPress={this.onClear}/>
        <Text>Text: {this.state.text}</Text>
        <Text>Keys: {this.state.keys}</Text>
      </View>
    );
  }

  onChangeText = (text: string) => {
    this.setState({text})
  }

  onKeyPress = ({ nativeEvent }: Object) => {
    this.setState({keys: this.state.keys + nativeEvent.key + ', '})
  }

  onClear = () => {
    this.setState({text: '', keys: ''})
  }
}
```

<!--
  Does this PR require a documentation change?
  Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->

<!--
  Required.
  Help reviewers and the release process by writing your own release notes. See below for an example.
-->

[IOS] [BUGFIX] [TextInput] - Fixed the bug where Backspace event was emitted when entering a character after clearing a text in TextInput by an empty string

<!--
  **INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**

    CATEGORY
  [----------]      TYPE
  [ CLI      ] [-------------]    LOCATION
  [ DOCS     ] [ BREAKING    ] [-------------]
  [ GENERAL  ] [ BUGFIX      ] [ {Component} ]
  [ INTERNAL ] [ ENHANCEMENT ] [ {Filename}  ]
  [ IOS      ] [ FEATURE     ] [ {Directory} ]   |-----------|
  [ ANDROID  ] [ MINOR       ] [ {Framework} ] - | {Message} |
  [----------] [-------------] [-------------]   |-----------|

 EXAMPLES:

 [IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
 [ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
 [CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
 [DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
 [GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
 [INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes https://github.com/facebook/react-native/pull/18627

Differential Revision: D8436331

Pulled By: hramos

fbshipit-source-id: ec75a6ca926061cbf7cb106db652f2b4a71c9a0c
2018-06-14 18:30:54 -07:00
..
ART Bump Prettier to 1.13.4 on xplat 2018-06-06 05:32:06 -07:00
ActionSheetIOS deleted UI Action Sheet Delegate Methods 2018-05-30 10:40:39 -07:00
Alert Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
Animated Enable Flow for bezier 2018-06-10 15:16:15 -07:00
AppState Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
BatchedBridge Remove __fbUninstallRNGlobalErrorHandler 2018-05-21 11:12:46 -07:00
Blob iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
BugReporting Fix some typos in dumpReactTree.js (#19636) 2018-06-09 20:27:42 -07:00
CameraRoll iOS: disable deprecation warning for Xcode 9.3.1+ for now 2018-05-22 01:16:45 -07:00
Color Bump Prettier to 1.13.4 on xplat 2018-06-06 05:32:06 -07:00
Components Feature/add decimal pad to android (#19714) 2018-06-14 14:01:51 -07:00
Core Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
EventEmitter Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
Experimental Flowtype SwipeableRow 2018-05-14 00:24:44 -07:00
Geolocation iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Image Don't pass additional args to requireNativeComponent in .android.js files 2018-06-10 15:38:32 -07:00
Inspector Flowtype ListView 2018-05-14 00:24:44 -07:00
Interaction RN: Remove ReactPerf References 2018-05-15 13:16:57 -07:00
JSInspector Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
LayoutAnimation Remove @providesModule from all modules 2018-04-25 07:37:10 -07:00
Linking Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
LinkingIOS iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Lists Bump Prettier to 1.13.4 on xplat 2018-06-06 05:32:06 -07:00
Modal Switch to Platform.isTV to pass Android Flow 2018-06-10 13:45:57 -07:00
NativeAnimation iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Network iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Performance QuickPerformanceLogger.js: markerPoint + iOS/Android JS binding 2018-06-08 08:32:05 -07:00
PermissionsAndroid Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
PushNotificationIOS iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
RCTTest RN: Remove Native Prop Validation 2018-06-01 12:54:14 -07:00
ReactNative RN: A wild YellowBox has appeared! 2018-06-11 18:31:18 -07:00
Renderer React sync for revisions de84d5c...c0fe8d6 2018-05-18 20:22:45 -07:00
Sample iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Settings iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
Share Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
Storage Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
StyleSheet Support animated values for border dimensions 2018-06-13 17:34:47 -07:00
SurfaceBackedComponent Update license headers for MIT license 2018-02-16 18:31:53 -08:00
SurfaceHostingComponent Update license headers for MIT license 2018-02-16 18:31:53 -08:00
Text iOS: Fixed the bug where a Backspace event was emitted when entering characters after clearing a text in TextInput by an empty string (#18627) 2018-06-14 18:30:54 -07:00
Types Remove @providesModule from all modules 2018-04-25 07:37:10 -07:00
Utilities Switch to Platform.isTV to pass Android Flow 2018-06-10 13:45:57 -07:00
Vibration iOS OSS: deployment target 8.0 => 9.0 2018-05-22 01:16:45 -07:00
WebSocket Bump Prettier to 1.13.4 on xplat 2018-06-06 05:32:06 -07:00
Wrapper Update additional license headers 2018-03-08 12:10:14 -08:00
YellowBox YellowBox: Restore ES5 Compatibility 2018-06-14 09:02:18 -07:00
fishhook Merge fishhook.xcodeproj in RCTWebSocket 2017-08-09 07:48:09 -07:00
polyfills Implement console group APIs (#18555) 2018-06-12 11:18:37 -07:00
react-native Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
vendor Add MIT License Header 2018-06-09 18:16:21 -07:00
.npmignore npmignore: ignore tests and fixtures 2018-02-27 08:42:14 -08:00
Promise.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00
UTFSequence.js RN: A wild YellowBox has appeared! 2018-06-11 18:31:18 -07:00
promiseRejectionIsError.js Prettier React Native Libraries 2018-05-10 19:10:38 -07:00