Skip to content

Commit 26e2c08

Browse files
sherginfacebook-github-bot
authored andcommitted
Better TextInput: Native auto-expandable <TextInput> is here (iOS only)
Reviewed By: mmmulani Differential Revision: D4646962 fbshipit-source-id: bc054d9c68c385b13222e7c9fb8728d21f987a48
1 parent 1b013cd commit 26e2c08

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

Examples/UIExplorer/js/TextInputExample.ios.js

+9-30
Original file line numberDiff line numberDiff line change
@@ -103,34 +103,6 @@ class TextEventsExample extends React.Component {
103103
}
104104
}
105105

106-
class AutoExpandingTextInput extends React.Component {
107-
state: any;
108-
109-
constructor(props) {
110-
super(props);
111-
this.state = {
112-
text: 'React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about — learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native.',
113-
height: 0,
114-
};
115-
}
116-
render() {
117-
return (
118-
<TextInput
119-
{...this.props}
120-
multiline={true}
121-
onChangeText={(text) => {
122-
this.setState({text});
123-
}}
124-
onContentSizeChange={(event) => {
125-
this.setState({height: event.nativeEvent.contentSize.height});
126-
}}
127-
style={[styles.default, {height: Math.max(35, this.state.height)}]}
128-
value={this.state.text}
129-
/>
130-
);
131-
}
132-
}
133-
134106
class RewriteExample extends React.Component {
135107
state: any;
136108

@@ -403,6 +375,10 @@ var styles = StyleSheet.create({
403375
padding: 4,
404376
marginBottom: 4,
405377
},
378+
multilineExpandable: {
379+
height: 'auto',
380+
maxHeight: 100,
381+
},
406382
multilineWithFontStyles: {
407383
color: 'blue',
408384
fontWeight: 'bold',
@@ -801,10 +777,13 @@ exports.examples = [
801777
render: function() {
802778
return (
803779
<View>
804-
<AutoExpandingTextInput
780+
<TextInput
805781
placeholder="height increases with content"
782+
defaultValue="React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about — learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native."
783+
multiline={true}
806784
enablesReturnKeyAutomatically={true}
807-
returnKeyType="default"
785+
returnKeyType="go"
786+
style={[styles.multiline, styles.multilineExpandable]}
808787
/>
809788
</View>
810789
);

0 commit comments

Comments
 (0)