mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 22:42:13 +08:00
implement android maxlength prop
Summary: Fixes https://github.com/facebook/react-native/issues/3864 But I don't sure that this code is correct. But it works and works same as in iOS. Closes https://github.com/facebook/react-native/pull/3873 Reviewed By: mikearmstrong001 Differential Revision: D2626122 Pulled By: andreicoman11 fb-gh-sync-id: 316915c99b218ed5f32ca90fd72ce9810571383a
This commit is contained in:
committed by
facebook-github-bot-2
parent
527d11ce01
commit
b6340ee2b0
@@ -78,15 +78,25 @@ class RewriteExample extends React.Component {
|
||||
this.state = {text: ''};
|
||||
}
|
||||
render() {
|
||||
var limit = 20;
|
||||
var remainder = limit - this.state.text.length;
|
||||
var remainderColor = remainder > 5 ? 'blue' : 'red';
|
||||
return (
|
||||
<TextInput
|
||||
onChangeText={(text) => {
|
||||
text = text.replace(/ /g, '_');
|
||||
this.setState({text});
|
||||
}}
|
||||
style={styles.singleLine}
|
||||
value={this.state.text}
|
||||
/>
|
||||
<View style={styles.rewriteContainer}>
|
||||
<TextInput
|
||||
multiline={false}
|
||||
maxLength={limit}
|
||||
onChangeText={(text) => {
|
||||
text = text.replace(/ /g, '_');
|
||||
this.setState({text});
|
||||
}}
|
||||
style={styles.default}
|
||||
value={this.state.text}
|
||||
/>
|
||||
<Text style={[styles.remainder, {color: remainderColor}]}>
|
||||
{remainder}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user