Skip to content

Commit

Permalink
test: improved TextInputExample
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Feb 27, 2019
1 parent cf87a32 commit 32db2dc
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions RNTester/js/TextInputExample.macos.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class TextEventsExample extends React.Component<{}, $FlowFixMeState> {
onChange={event =>
this.updateText('onChange text: ' + event.nativeEvent.text)
}
onTextInput={event =>
this.updateText('onTextInput: ' + JSON.stringify(event.nativeEvent))
}
onEndEditing={event =>
this.updateText('onEndEditing text: ' + event.nativeEvent.text)
}
Expand Down Expand Up @@ -489,6 +492,47 @@ class AutogrowingTextInputExample extends React.Component<
}
}

class ControlledResetExample extends React.Component<
$FlowFixMeProps,
$FlowFixMeState,
> {
constructor(props) {
super(props);
this.state = {
text: '',
keys: '',
};
}

render() {
return (
<View style={styles.container}>
<TextInput
style={styles.default}
value={this.state.text}
onChangeText={this.onChangeText}
onKeyPress={this.onKeyPress}
/>
<Button title="Reset" onPress={this.onReset} />
<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 + ', '});
};

onReset = () => {
this.setState({text: '', keys: ''});
};
}

const styles = StyleSheet.create({
default: {
borderWidth: StyleSheet.hairlineWidth,
Expand Down Expand Up @@ -1104,4 +1148,10 @@ exports.examples = [
);
},
},
{
title: 'Controlled reset',
render: function() {
return <ControlledResetExample />;
},
},
];

0 comments on commit 32db2dc

Please sign in to comment.