Fixed controlled component on iOS and remove unnecessary code

Summary:
Closes #4290

`mostRecentEventCount` was always being set after `text` on iOS, so let's be really explicit about the order here as we were doing on Android: always call `setNativeProps` providing the `mostRecentEventCount` before we call `onChange` or `onChangeText`.

I also ripped out storing `mostRecentEventCount` in the state, which isn't necessary since we're always doing it through `setNativeProps`.
Closes https://github.com/facebook/react-native/pull/4588

Reviewed By: svcscm

Differential Revision: D2754565

Pulled By: nicklockwood

fb-gh-sync-id: a1401f39b4e19248095517c2a3503cd2af59fa47
This commit is contained in:
Brent Vatne
2015-12-14 06:41:45 -08:00
committed by facebook-github-bot-0
parent 2f56c0c90a
commit c8108bdbe1
2 changed files with 43 additions and 29 deletions

View File

@@ -125,6 +125,27 @@ class RewriteExample extends React.Component {
}
}
class RewriteExampleInvalidCharacters extends React.Component {
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
<View style={styles.rewriteContainer}>
<TextInput
multiline={false}
onChangeText={(text) => {
this.setState({text: text.replace(/\s/g, '')});
}}
style={styles.default}
value={this.state.text}
/>
</View>
);
}
}
class TokenizedTextExample extends React.Component {
constructor(props) {
super(props);
@@ -313,6 +334,12 @@ exports.examples = [
return <RewriteExample />;
}
},
{
title: "Live Re-Write (no spaces allowed)",
render: function() {
return <RewriteExampleInvalidCharacters />;
}
},
{
title: 'Auto-capitalize',
render: function() {