diff --git a/RNTester/js/examples/TextInput/TextInputExample.android.js b/RNTester/js/examples/TextInput/TextInputExample.android.js index 28a3e535922..f0d7be612fd 100644 --- a/RNTester/js/examples/TextInput/TextInputExample.android.js +++ b/RNTester/js/examples/TextInput/TextInputExample.android.js @@ -25,183 +25,6 @@ const TextInputSharedExamples = require('./TextInputSharedExamples.js'); import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes'; -class TextEventsExample extends React.Component<{...}, $FlowFixMeState> { - state = { - curText: '', - prevText: '', - prev2Text: '', - prev3Text: '', - }; - - updateText = text => { - this.setState(state => { - return { - curText: text, - prevText: state.curText, - prev2Text: state.prevText, - prev3Text: state.prev2Text, - }; - }); - }; - - render() { - return ( - - this.updateText('onFocus')} - onBlur={() => this.updateText('onBlur')} - onChange={event => - this.updateText('onChange text: ' + event.nativeEvent.text) - } - onContentSizeChange={event => - this.updateText( - 'onContentSizeChange size: ' + - JSON.stringify(event.nativeEvent.contentSize), - ) - } - onEndEditing={event => - this.updateText('onEndEditing text: ' + event.nativeEvent.text) - } - onSubmitEditing={event => - this.updateText('onSubmitEditing text: ' + event.nativeEvent.text) - } - onKeyPress={event => - this.updateText('onKeyPress key: ' + event.nativeEvent.key) - } - style={styles.singleLine} - /> - - {this.state.curText} - {'\n'} - (prev: {this.state.prevText}){'\n'} - (prev2: {this.state.prev2Text}){'\n'} - (prev3: {this.state.prev3Text}) - - - ); - } -} - -class TokenizedTextExample extends React.Component< - $FlowFixMeProps, - $FlowFixMeState, -> { - constructor(props) { - super(props); - this.state = {text: 'Hello #World'}; - } - render() { - //define delimiter - let delimiter = /\s+/; - - //split string - let _text = this.state.text; - let token, - index, - parts = []; - while (_text) { - delimiter.lastIndex = 0; - token = delimiter.exec(_text); - if (token === null) { - break; - } - index = token.index; - if (token[0].length === 0) { - index = 1; - } - parts.push(_text.substr(0, index)); - parts.push(token[0]); - index = index + token[0].length; - _text = _text.slice(index); - } - parts.push(_text); - - //highlight hashtags - parts = parts.map(text => { - if (/^#/.test(text)) { - return ( - - {text} - - ); - } else { - return text; - } - }); - - return ( - - { - this.setState({text}); - }}> - {parts} - - - ); - } -} - -class BlurOnSubmitExample extends React.Component<{...}> { - focusNextField = nextField => { - this.refs[nextField].focus(); - }; - - render() { - return ( - - this.focusNextField('2')} - /> - this.focusNextField('3')} - /> - this.focusNextField('4')} - /> - this.focusNextField('5')} - /> - - - ); - } -} - class ToggleDefaultPaddingExample extends React.Component< $FlowFixMeProps, $FlowFixMeState, @@ -223,90 +46,6 @@ class ToggleDefaultPaddingExample extends React.Component< } } -type SelectionExampleState = { - selection: $ReadOnly<{| - start: number, - end?: number, - |}>, - value: string, - ... -}; - -class SelectionExample extends React.Component< - $FlowFixMeProps, - SelectionExampleState, -> { - _textInput: any; - - constructor(props) { - super(props); - this.state = { - selection: {start: 0, end: 0}, - value: props.value, - }; - } - - onSelectionChange({nativeEvent: {selection}}) { - this.setState({selection}); - } - - getRandomPosition() { - const length = this.state.value.length; - return Math.round(Math.random() * length); - } - - select(start, end) { - this._textInput.focus(); - this.setState({selection: {start, end}}); - } - - selectRandom() { - const positions = [ - this.getRandomPosition(), - this.getRandomPosition(), - ].sort(); - this.select(...positions); - } - - placeAt(position) { - this.select(position, position); - } - - placeAtRandom() { - this.placeAt(this.getRandomPosition()); - } - - render() { - const length = this.state.value.length; - - return ( - - this.setState({value})} - onSelectionChange={this.onSelectionChange.bind(this)} - ref={textInput => (this._textInput = textInput)} - selection={this.state.selection} - style={this.props.style} - value={this.state.value} - /> - - selection = {JSON.stringify(this.state.selection)} - - Place at Start (0, 0) - - - Place at End ({length}, {length}) - - Place at Random - Select All - Select Random - - - ); - } -} - class AutogrowingTextInputExample extends React.Component<{...}> { constructor(props) { super(props); @@ -394,38 +133,18 @@ const styles = StyleSheet.create({ height: 60, fontSize: 16, }, - eventLabel: { - margin: 3, - fontSize: 12, - }, singleLine: { fontSize: 16, }, singleLineWithHeightTextInput: { height: 30, }, - hashtag: { - color: 'blue', - fontWeight: 'bold', - }, }); exports.title = ''; exports.description = 'Single and multi-line text inputs.'; exports.examples = ([ ...TextInputSharedExamples, - { - title: 'Blur on submit', - render: function(): React.Element { - return ; - }, - }, - { - title: 'Event handling', - render: function(): React.Element { - return ; - }, - }, { title: 'Colors and text inputs', render: function(): React.Node { @@ -487,44 +206,6 @@ exports.examples = ([ ); }, }, - { - title: 'fontFamily, fontWeight and fontStyle', - render: function(): React.Node { - return ( - - - - - - - - ); - }, - }, { title: 'letterSpacing', render: function(): React.Node { @@ -667,12 +348,6 @@ exports.examples = ([ ); }, }, - { - title: 'Attributed text', - render: function(): React.Node { - return ; - }, - }, { title: 'Return key', render: function(): React.Node { @@ -744,24 +419,4 @@ exports.examples = ([ return ; }, }, - { - title: 'Text selection & cursor placement', - render: function(): React.Node { - return ( - - =0.78.0 site=react_native_android_fb) This issue was - * found when making Flow check .android.js files. */ - style={styles.default} - value="text selection can be changed" - /> - - - ); - }, - }, ]: Array); diff --git a/RNTester/js/examples/TextInput/TextInputExample.ios.js b/RNTester/js/examples/TextInput/TextInputExample.ios.js index da8c9848797..7e1673070e0 100644 --- a/RNTester/js/examples/TextInput/TextInputExample.ios.js +++ b/RNTester/js/examples/TextInput/TextInputExample.ios.js @@ -41,68 +41,6 @@ class WithLabel extends React.Component<$FlowFixMeProps> { } } -class TextEventsExample extends React.Component<{...}, $FlowFixMeState> { - state = { - curText: '', - prevText: '', - prev2Text: '', - prev3Text: '', - }; - - updateText = text => { - this.setState(state => { - return { - curText: text, - prevText: state.curText, - prev2Text: state.prevText, - prev3Text: state.prev2Text, - }; - }); - }; - - render() { - return ( - - this.updateText('onFocus')} - onBlur={() => this.updateText('onBlur')} - onChange={event => - this.updateText('onChange text: ' + event.nativeEvent.text) - } - onEndEditing={event => - this.updateText('onEndEditing text: ' + event.nativeEvent.text) - } - onSubmitEditing={event => - this.updateText('onSubmitEditing text: ' + event.nativeEvent.text) - } - onSelectionChange={event => - this.updateText( - 'onSelectionChange range: ' + - event.nativeEvent.selection.start + - ',' + - (event.nativeEvent.selection.end || ''), - ) - } - onKeyPress={event => { - this.updateText('onKeyPress key: ' + event.nativeEvent.key); - }} - style={styles.default} - /> - - {this.state.curText} - {'\n'} - (prev: {this.state.prevText}){'\n'} - (prev2: {this.state.prev2Text}){'\n'} - (prev3: {this.state.prev3Text}) - - - ); - } -} - class TextInputAccessoryViewExample extends React.Component<{...}, *> { constructor(props) { super(props); @@ -198,203 +136,6 @@ class SecureEntryExample extends React.Component<$FlowFixMeProps, any> { } } -class TokenizedTextExample extends React.Component<$FlowFixMeProps, any> { - constructor(props) { - super(props); - this.state = {text: 'Hello #World'}; - } - render() { - //define delimiter - let delimiter = /\s+/; - - //split string - let _text = this.state.text; - let token, - index, - parts = []; - while (_text) { - delimiter.lastIndex = 0; - token = delimiter.exec(_text); - if (token === null) { - break; - } - index = token.index; - if (token[0].length === 0) { - index = 1; - } - parts.push(_text.substr(0, index)); - parts.push(token[0]); - index = index + token[0].length; - _text = _text.slice(index); - } - parts.push(_text); - - //highlight hashtags - parts = parts.map(text => { - if (/^#/.test(text)) { - return ( - - {text} - - ); - } else { - return text; - } - }); - - return ( - - { - this.setState({text}); - }}> - {parts} - - - ); - } -} - -class BlurOnSubmitExample extends React.Component<{...}> { - focusNextField = nextField => { - this.refs[nextField].focus(); - }; - - render() { - return ( - - this.focusNextField('2')} - /> - this.focusNextField('3')} - /> - this.focusNextField('4')} - /> - this.focusNextField('5')} - /> - - - ); - } -} - -type SelectionExampleState = { - selection: $ReadOnly<{| - start: number, - end?: number, - |}>, - value: string, - ... -}; - -class SelectionExample extends React.Component< - $FlowFixMeProps, - SelectionExampleState, -> { - _textInput: any; - - constructor(props) { - super(props); - this.state = { - selection: {start: 0, end: 0}, - value: props.value, - }; - } - - onSelectionChange({nativeEvent: {selection}}) { - this.setState({selection}); - } - - getRandomPosition() { - const length = this.state.value.length; - return Math.round(Math.random() * length); - } - - select(start, end) { - this._textInput.focus(); - this.setState({selection: {start, end}}); - } - - selectRandom() { - const positions = [this.getRandomPosition(), this.getRandomPosition()].sort( - (a, b) => a - b, - ); - this.select(...positions); - } - - placeAt(position) { - this.select(position, position); - } - - placeAtRandom() { - this.placeAt(this.getRandomPosition()); - } - - render() { - const length = this.state.value.length; - - return ( - - this.setState({value})} - onSelectionChange={this.onSelectionChange.bind(this)} - ref={textInput => (this._textInput = textInput)} - selection={this.state.selection} - style={this.props.style} - value={this.state.value} - /> - - selection = {JSON.stringify(this.state.selection)} - - Place at Start (0, 0) - - - Place at End ({length}, {length}) - - Place at Random - Select All - Select Random - - - ); - } -} - class AutogrowingTextInputExample extends React.Component< $FlowFixMeProps, $FlowFixMeState, @@ -492,10 +233,6 @@ const styles = StyleSheet.create({ letterSpacing: 10, textAlign: 'center', }, - eventLabel: { - margin: 3, - fontSize: 12, - }, labelContainer: { flexDirection: 'row', marginVertical: 2, @@ -515,10 +252,6 @@ const styles = StyleSheet.create({ textAlign: 'right', width: 24, }, - hashtag: { - color: 'blue', - fontWeight: 'bold', - }, }); exports.displayName = (undefined: ?string); @@ -625,12 +358,6 @@ exports.examples = ([ return ; }, }, - { - title: 'Event handling', - render: function(): React.Element { - return ; - }, - }, { title: 'Colored input text', render: function(): React.Node { @@ -733,12 +460,6 @@ exports.examples = ([ ); }, }, - { - title: 'Blur on submit', - render: function(): React.Element { - return ; - }, - }, { title: 'Multiline blur on submit', render: function(): React.Node { @@ -916,30 +637,6 @@ exports.examples = ([ ); }, }, - { - title: 'Attributed text', - render: function(): React.Node { - return ; - }, - }, - { - title: 'Text selection & cursor placement', - render: function(): React.Node { - return ( - - - - - ); - }, - }, { title: 'TextInput maxLength', render: function(): React.Node { @@ -988,38 +685,6 @@ exports.examples = ([ ); }, }, - { - title: 'fontFamily, fontWeight and fontStyle', - render: function(): React.Node { - return ( - - - - - - - - ); - }, - }, { title: 'TextInput Placeholder Styles', render: function(): React.Node { diff --git a/RNTester/js/examples/TextInput/TextInputSharedExamples.js b/RNTester/js/examples/TextInput/TextInputSharedExamples.js index 34edd703d54..8437c2944fc 100644 --- a/RNTester/js/examples/TextInput/TextInputSharedExamples.js +++ b/RNTester/js/examples/TextInput/TextInputSharedExamples.js @@ -24,6 +24,18 @@ const styles = StyleSheet.create({ fontSize: 13, padding: 4, }, + multiline: { + borderWidth: StyleSheet.hairlineWidth, + borderColor: '#0f0f0f', + flex: 1, + fontSize: 13, + height: 50, + padding: 4, + marginBottom: 4, + }, + singleLine: { + fontSize: 16, + }, labelContainer: { flexDirection: 'row', marginVertical: 2, @@ -43,6 +55,14 @@ const styles = StyleSheet.create({ textAlign: 'right', width: 24, }, + hashtag: { + color: 'blue', + fontWeight: 'bold', + }, + eventLabel: { + margin: 3, + fontSize: 12, + }, }); class WithLabel extends React.Component<$FlowFixMeProps> { @@ -148,6 +168,267 @@ class RewriteInvalidCharactersAndClearExample extends React.Component< } } +class BlurOnSubmitExample extends React.Component<{...}> { + focusNextField = nextField => { + this.refs[nextField].focus(); + }; + + render() { + return ( + + this.focusNextField('2')} + /> + this.focusNextField('3')} + /> + this.focusNextField('4')} + /> + this.focusNextField('5')} + /> + + + ); + } +} + +class TextEventsExample extends React.Component<{...}, $FlowFixMeState> { + state = { + curText: '', + prevText: '', + prev2Text: '', + prev3Text: '', + }; + + updateText = text => { + this.setState(state => { + return { + curText: text, + prevText: state.curText, + prev2Text: state.prevText, + prev3Text: state.prev2Text, + }; + }); + }; + + render() { + return ( + + this.updateText('onFocus')} + onBlur={() => this.updateText('onBlur')} + onChange={event => + this.updateText('onChange text: ' + event.nativeEvent.text) + } + onContentSizeChange={event => + this.updateText( + 'onContentSizeChange size: ' + + JSON.stringify(event.nativeEvent.contentSize), + ) + } + onEndEditing={event => + this.updateText('onEndEditing text: ' + event.nativeEvent.text) + } + onSubmitEditing={event => + this.updateText('onSubmitEditing text: ' + event.nativeEvent.text) + } + onKeyPress={event => + this.updateText('onKeyPress key: ' + event.nativeEvent.key) + } + style={styles.singleLine} + /> + + {this.state.curText} + {'\n'} + (prev: {this.state.prevText}){'\n'} + (prev2: {this.state.prev2Text}){'\n'} + (prev3: {this.state.prev3Text}) + + + ); + } +} + +class TokenizedTextExample extends React.Component< + $FlowFixMeProps, + $FlowFixMeState, +> { + constructor(props) { + super(props); + this.state = {text: 'Hello #World'}; + } + render() { + //define delimiter + let delimiter = /\s+/; + + //split string + let _text = this.state.text; + let token, + index, + parts = []; + while (_text) { + delimiter.lastIndex = 0; + token = delimiter.exec(_text); + if (token === null) { + break; + } + index = token.index; + if (token[0].length === 0) { + index = 1; + } + parts.push(_text.substr(0, index)); + parts.push(token[0]); + index = index + token[0].length; + _text = _text.slice(index); + } + parts.push(_text); + + //highlight hashtags + parts = parts.map(text => { + if (/^#/.test(text)) { + return ( + + {text} + + ); + } else { + return text; + } + }); + + return ( + + { + this.setState({text}); + }}> + {parts} + + + ); + } +} + +type SelectionExampleState = { + selection: $ReadOnly<{| + start: number, + end?: number, + |}>, + value: string, + ... +}; + +class SelectionExample extends React.Component< + $FlowFixMeProps, + SelectionExampleState, +> { + _textInput: any; + + constructor(props) { + super(props); + this.state = { + selection: {start: 0, end: 0}, + value: props.value, + }; + } + + onSelectionChange({nativeEvent: {selection}}) { + this.setState({selection}); + } + + getRandomPosition() { + const length = this.state.value.length; + return Math.round(Math.random() * length); + } + + select(start, end) { + this._textInput.focus(); + this.setState({selection: {start, end}}); + } + + selectRandom() { + const positions = [ + this.getRandomPosition(), + this.getRandomPosition(), + ].sort(); + this.select(...positions); + } + + placeAt(position) { + this.select(position, position); + } + + placeAtRandom() { + this.placeAt(this.getRandomPosition()); + } + + render() { + const length = this.state.value.length; + + return ( + + this.setState({value})} + onSelectionChange={this.onSelectionChange.bind(this)} + ref={textInput => (this._textInput = textInput)} + selection={this.state.selection} + style={this.props.style} + value={this.state.value} + /> + + selection = {JSON.stringify(this.state.selection)} + + Place at Start (0, 0) + + + Place at End ({length}, {length}) + + Place at Random + Select All + Select Random + + + ); + } +} + module.exports = ([ { title: 'Auto-focus', @@ -243,4 +524,80 @@ module.exports = ([ return {examples}; }, }, + { + title: 'Blur on submit', + render: function(): React.Element { + return ; + }, + }, + { + title: 'Event handling', + render: function(): React.Element { + return ; + }, + }, + { + title: 'fontFamily, fontWeight and fontStyle', + render: function(): React.Node { + return ( + + + + + + + + ); + }, + }, + { + title: 'Attributed text', + render: function(): React.Node { + return ; + }, + }, + { + title: 'Text selection & cursor placement', + render: function(): React.Node { + return ( + + =0.78.0 site=react_native_android_fb) This issue was + * found when making Flow check .android.js files. */ + style={styles.default} + value="text selection can be changed" + /> + + + ); + }, + }, ]: Array);