Convert TextInput to Hooks

Summary:
Modernizing this code a bit more, converting it to hooks.

Changelog:
[General][Changed] Converted TextInput to use React hooks
[General][Fixed] TextInput now properly sends native the end selection location on change

(Note: this ignores all push blocking failures!)

Reviewed By: JoshuaGross

Differential Revision: D18581712

fbshipit-source-id: 62d6ea8489fa019ddf941c520930365f2c4887d8
This commit is contained in:
Eli White authored and Facebook Github Bot committed 2019-11-21 12:41:52 -08:00
1 parent 8553e1acc4
commit dff490d140
2 files changed
+278 -245

No files matched your search

@@ -181,6 +181,43 @@ class RewriteExampleInvalidCharacters extends React.Component<
}
}
class RewriteInvalidCharactersAndClearExample extends React.Component<
$FlowFixMeProps,
any,
> {
inputRef: ?React.ElementRef<typeof TextInput> = null;
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
<View style={styles.rewriteContainer}>
<TextInput
ref={ref => {
this.inputRef = ref;
}}
multiline={false}
onChangeText={text => {
this.setState({text: text.replace(/\s/g, '')});
}}
style={styles.default}
value={this.state.text}
/>
<Button
onPress={() => {
if (this.inputRef != null) {
this.inputRef.clear();
}
}}
title="Clear"
/>
</View>
);
}
}
class RewriteExampleKana extends React.Component<$FlowFixMeProps, any> {
constructor(props) {
super(props);
@@ -598,6 +635,12 @@ exports.examples = [
return <RewriteExampleInvalidCharacters />;
},
},
{
title: 'Rewrite (no spaces allowed) and clear',
render: function(): React.Node {
return <RewriteInvalidCharactersAndClearExample />;
},
},
{
title: 'Live Re-Write (ひ -> 日)',
render: function(): React.Node {