2015-09-14 14:35:58 +00:00
|
|
|
/**
|
2017-05-06 03:50:47 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-09-14 14:35:58 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {Text, TextInput, View, StyleSheet, Slider, Switch} = ReactNative;
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class TextEventsExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
curText: '<No Event>',
|
|
|
|
prevText: '<No Event>',
|
|
|
|
prev2Text: '<No Event>',
|
2018-01-04 20:40:28 +00:00
|
|
|
prev3Text: '<No Event>',
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
updateText = text => {
|
|
|
|
this.setState(state => {
|
2015-09-14 14:35:58 +00:00
|
|
|
return {
|
|
|
|
curText: text,
|
|
|
|
prevText: state.curText,
|
|
|
|
prev2Text: state.prevText,
|
2018-01-04 20:40:28 +00:00
|
|
|
prev3Text: state.prev2Text,
|
2015-09-14 14:35:58 +00:00
|
|
|
};
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize="none"
|
|
|
|
placeholder="Enter text to see events"
|
|
|
|
autoCorrect={false}
|
2018-01-04 20:40:28 +00:00
|
|
|
multiline
|
2015-09-14 14:35:58 +00:00
|
|
|
onFocus={() => this.updateText('onFocus')}
|
|
|
|
onBlur={() => this.updateText('onBlur')}
|
2018-05-11 20:32:37 +00:00
|
|
|
onChange={event =>
|
|
|
|
this.updateText('onChange text: ' + event.nativeEvent.text)
|
|
|
|
}
|
|
|
|
onContentSizeChange={event =>
|
|
|
|
this.updateText(
|
|
|
|
'onContentSizeChange size: ' + 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)
|
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<Text style={styles.eventLabel}>
|
2018-05-11 20:32:37 +00:00
|
|
|
{this.state.curText}
|
|
|
|
{'\n'}
|
2015-09-14 14:35:58 +00:00
|
|
|
(prev: {this.state.prevText}){'\n'}
|
2018-01-04 20:40:28 +00:00
|
|
|
(prev2: {this.state.prev2Text}){'\n'}
|
|
|
|
(prev3: {this.state.prev3Text})
|
2015-09-14 14:35:58 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-09-14 14:35:58 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class RewriteExample extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
|
2015-09-14 14:35:58 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {text: ''};
|
|
|
|
}
|
|
|
|
render() {
|
2015-11-06 21:25:05 +00:00
|
|
|
var limit = 20;
|
|
|
|
var remainder = limit - this.state.text.length;
|
|
|
|
var remainderColor = remainder > 5 ? 'blue' : 'red';
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
2015-11-06 21:25:05 +00:00
|
|
|
<View style={styles.rewriteContainer}>
|
|
|
|
<TextInput
|
|
|
|
multiline={false}
|
|
|
|
maxLength={limit}
|
2018-05-11 20:32:37 +00:00
|
|
|
onChangeText={text => {
|
2015-11-06 21:25:05 +00:00
|
|
|
text = text.replace(/ /g, '_');
|
|
|
|
this.setState({text});
|
|
|
|
}}
|
|
|
|
style={styles.default}
|
|
|
|
value={this.state.text}
|
|
|
|
/>
|
|
|
|
<Text style={[styles.remainder, {color: remainderColor}]}>
|
|
|
|
{remainder}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class TokenizedTextExample extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
$FlowFixMeState,
|
|
|
|
> {
|
2015-11-06 16:22:22 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {text: 'Hello #World'};
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
//define delimiter
|
|
|
|
let delimiter = /\s+/;
|
|
|
|
|
|
|
|
//split string
|
|
|
|
let _text = this.state.text;
|
2018-05-11 20:32:37 +00:00
|
|
|
let token,
|
|
|
|
index,
|
|
|
|
parts = [];
|
2015-11-06 16:22:22 +00:00
|
|
|
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
|
2018-05-11 20:32:37 +00:00
|
|
|
parts = parts.map(text => {
|
2015-11-06 16:22:22 +00:00
|
|
|
if (/^#/.test(text)) {
|
2018-05-11 20:32:37 +00:00
|
|
|
return (
|
|
|
|
<Text key={text} style={styles.hashtag}>
|
|
|
|
{text}
|
|
|
|
</Text>
|
|
|
|
);
|
2015-11-06 16:22:22 +00:00
|
|
|
} else {
|
|
|
|
return text;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
multiline={true}
|
|
|
|
style={styles.multiline}
|
2018-05-11 20:32:37 +00:00
|
|
|
onChangeText={text => {
|
2015-11-06 16:22:22 +00:00
|
|
|
this.setState({text});
|
|
|
|
}}>
|
|
|
|
<Text>{parts}</Text>
|
|
|
|
</TextInput>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class BlurOnSubmitExample extends React.Component<{}> {
|
2018-05-11 20:32:37 +00:00
|
|
|
focusNextField = nextField => {
|
2016-03-02 15:06:37 +00:00
|
|
|
this.refs[nextField].focus();
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2016-03-02 15:06:37 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
render() {
|
2016-03-02 15:06:37 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
ref="1"
|
|
|
|
style={styles.singleLine}
|
|
|
|
placeholder="blurOnSubmit = false"
|
|
|
|
returnKeyType="next"
|
|
|
|
blurOnSubmit={false}
|
|
|
|
onSubmitEditing={() => this.focusNextField('2')}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
ref="2"
|
|
|
|
style={styles.singleLine}
|
|
|
|
keyboardType="email-address"
|
|
|
|
placeholder="blurOnSubmit = false"
|
|
|
|
returnKeyType="next"
|
|
|
|
blurOnSubmit={false}
|
|
|
|
onSubmitEditing={() => this.focusNextField('3')}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
ref="3"
|
|
|
|
style={styles.singleLine}
|
|
|
|
keyboardType="url"
|
|
|
|
placeholder="blurOnSubmit = false"
|
|
|
|
returnKeyType="next"
|
|
|
|
blurOnSubmit={false}
|
|
|
|
onSubmitEditing={() => this.focusNextField('4')}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
ref="4"
|
|
|
|
style={styles.singleLine}
|
|
|
|
keyboardType="numeric"
|
|
|
|
placeholder="blurOnSubmit = false"
|
|
|
|
blurOnSubmit={false}
|
|
|
|
onSubmitEditing={() => this.focusNextField('5')}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
ref="5"
|
|
|
|
style={styles.singleLine}
|
|
|
|
keyboardType="numbers-and-punctuation"
|
|
|
|
placeholder="blurOnSubmit = true"
|
|
|
|
returnKeyType="done"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2016-03-02 15:06:37 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class ToggleDefaultPaddingExample extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
$FlowFixMeState,
|
|
|
|
> {
|
2016-08-18 10:15:51 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {hasPadding: false};
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TextInput style={this.state.hasPadding ? {padding: 0} : null} />
|
|
|
|
<Text
|
|
|
|
onPress={() => this.setState({hasPadding: !this.state.hasPadding})}>
|
2016-08-18 10:15:51 +00:00
|
|
|
Toggle padding
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-05 14:04:26 +00:00
|
|
|
type SelectionExampleState = {
|
|
|
|
selection: {
|
2018-05-11 20:32:37 +00:00
|
|
|
start: number,
|
|
|
|
end: number,
|
|
|
|
},
|
|
|
|
value: string,
|
2016-09-05 14:04:26 +00:00
|
|
|
};
|
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class SelectionExample extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
SelectionExampleState,
|
|
|
|
> {
|
2016-09-05 14:04:26 +00:00
|
|
|
_textInput: any;
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
selection: {start: 0, end: 0},
|
2018-05-11 20:32:37 +00:00
|
|
|
value: props.value,
|
2016-09-05 14:04:26 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onSelectionChange({nativeEvent: {selection}}) {
|
|
|
|
this.setState({selection});
|
|
|
|
}
|
|
|
|
|
|
|
|
getRandomPosition() {
|
|
|
|
var length = this.state.value.length;
|
|
|
|
return Math.round(Math.random() * length);
|
|
|
|
}
|
|
|
|
|
|
|
|
select(start, end) {
|
|
|
|
this._textInput.focus();
|
|
|
|
this.setState({selection: {start, end}});
|
|
|
|
}
|
|
|
|
|
|
|
|
selectRandom() {
|
|
|
|
var positions = [this.getRandomPosition(), this.getRandomPosition()].sort();
|
|
|
|
this.select(...positions);
|
|
|
|
}
|
|
|
|
|
|
|
|
placeAt(position) {
|
|
|
|
this.select(position, position);
|
|
|
|
}
|
|
|
|
|
|
|
|
placeAtRandom() {
|
|
|
|
this.placeAt(this.getRandomPosition());
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
var length = this.state.value.length;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
multiline={this.props.multiline}
|
2018-05-11 20:32:37 +00:00
|
|
|
onChangeText={value => this.setState({value})}
|
2016-09-05 14:04:26 +00:00
|
|
|
onSelectionChange={this.onSelectionChange.bind(this)}
|
|
|
|
ref={textInput => (this._textInput = textInput)}
|
|
|
|
selection={this.state.selection}
|
|
|
|
style={this.props.style}
|
|
|
|
value={this.state.value}
|
|
|
|
/>
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>selection = {JSON.stringify(this.state.selection)}</Text>
|
2016-09-05 14:04:26 +00:00
|
|
|
<Text onPress={this.placeAt.bind(this, 0)}>
|
|
|
|
Place at Start (0, 0)
|
|
|
|
</Text>
|
|
|
|
<Text onPress={this.placeAt.bind(this, length)}>
|
|
|
|
Place at End ({length}, {length})
|
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text onPress={this.placeAtRandom.bind(this)}>Place at Random</Text>
|
|
|
|
<Text onPress={this.select.bind(this, 0, length)}>Select All</Text>
|
|
|
|
<Text onPress={this.selectRandom.bind(this)}>Select Random</Text>
|
2016-09-05 14:04:26 +00:00
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-02 23:29:44 +00:00
|
|
|
class AutogrowingTextInputExample extends React.Component<{}> {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
width: 100,
|
|
|
|
multiline: true,
|
|
|
|
text: '',
|
2017-11-28 00:30:59 +00:00
|
|
|
contentSize: {
|
|
|
|
width: 0,
|
|
|
|
height: 0,
|
|
|
|
},
|
2017-10-02 23:29:44 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillReceiveProps(props) {
|
2017-10-02 23:29:44 +00:00
|
|
|
this.setState({
|
|
|
|
multiline: props.multiline,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
var {style, multiline, ...props} = this.props;
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>Width:</Text>
|
|
|
|
<Slider
|
|
|
|
value={100}
|
|
|
|
minimumValue={0}
|
|
|
|
maximumValue={100}
|
|
|
|
step={10}
|
2018-05-11 20:32:37 +00:00
|
|
|
onValueChange={value => this.setState({width: value})}
|
2017-10-02 23:29:44 +00:00
|
|
|
/>
|
|
|
|
<Text>Multiline:</Text>
|
|
|
|
<Switch
|
|
|
|
value={this.state.multiline}
|
2018-05-11 20:32:37 +00:00
|
|
|
onValueChange={value => this.setState({multiline: value})}
|
2017-10-02 23:29:44 +00:00
|
|
|
/>
|
|
|
|
<Text>TextInput:</Text>
|
|
|
|
<TextInput
|
|
|
|
multiline={this.state.multiline}
|
|
|
|
style={[style, {width: this.state.width + '%'}]}
|
2018-05-11 20:32:37 +00:00
|
|
|
onChangeText={value => this.setState({text: value})}
|
|
|
|
onContentSizeChange={event =>
|
|
|
|
this.setState({contentSize: event.nativeEvent.contentSize})
|
|
|
|
}
|
2017-10-02 23:29:44 +00:00
|
|
|
{...props}
|
|
|
|
/>
|
|
|
|
<Text>Plain text value representation:</Text>
|
|
|
|
<Text>{this.state.text}</Text>
|
2017-11-28 00:30:59 +00:00
|
|
|
<Text>Content Size: {JSON.stringify(this.state.contentSize)}</Text>
|
2017-10-02 23:29:44 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 14:35:58 +00:00
|
|
|
var styles = StyleSheet.create({
|
|
|
|
multiline: {
|
|
|
|
height: 60,
|
|
|
|
fontSize: 16,
|
|
|
|
},
|
|
|
|
eventLabel: {
|
|
|
|
margin: 3,
|
|
|
|
fontSize: 12,
|
|
|
|
},
|
|
|
|
singleLine: {
|
|
|
|
fontSize: 16,
|
|
|
|
},
|
|
|
|
singleLineWithHeightTextInput: {
|
|
|
|
height: 30,
|
|
|
|
},
|
2015-11-06 16:22:22 +00:00
|
|
|
hashtag: {
|
|
|
|
color: 'blue',
|
|
|
|
fontWeight: 'bold',
|
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
exports.title = '<TextInput>';
|
|
|
|
exports.description = 'Single and multi-line text inputs.';
|
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Auto-focus',
|
|
|
|
render: function() {
|
2016-02-04 13:12:36 +00:00
|
|
|
return (
|
|
|
|
<TextInput
|
|
|
|
autoFocus={true}
|
2017-10-02 23:29:44 +00:00
|
|
|
multiline={true}
|
|
|
|
style={styles.input}
|
2016-02-04 13:12:36 +00:00
|
|
|
accessibilityLabel="I am the accessibility label for text input"
|
|
|
|
/>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: "Live Re-Write (<sp> -> '_')",
|
|
|
|
render: function() {
|
|
|
|
return <RewriteExample />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Auto-capitalize',
|
|
|
|
render: function() {
|
2018-05-11 20:32:37 +00:00
|
|
|
var autoCapitalizeTypes = ['none', 'sentences', 'words', 'characters'];
|
|
|
|
var examples = autoCapitalizeTypes.map(type => {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
|
|
|
<TextInput
|
2015-10-09 16:31:51 +00:00
|
|
|
key={type}
|
2015-09-14 14:35:58 +00:00
|
|
|
autoCapitalize={type}
|
|
|
|
placeholder={'autoCapitalize: ' + type}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return <View>{examples}</View>;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Auto-correct',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect={true}
|
|
|
|
placeholder="This has autoCorrect"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect={false}
|
|
|
|
placeholder="This does not have autoCorrect"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Keyboard types',
|
|
|
|
render: function() {
|
2018-05-11 20:32:37 +00:00
|
|
|
var keyboardTypes = ['default', 'email-address', 'numeric', 'phone-pad'];
|
|
|
|
var examples = keyboardTypes.map(type => {
|
2015-09-14 14:35:58 +00:00
|
|
|
return (
|
|
|
|
<TextInput
|
2015-10-09 16:31:51 +00:00
|
|
|
key={type}
|
2015-09-14 14:35:58 +00:00
|
|
|
keyboardType={type}
|
|
|
|
placeholder={'keyboardType: ' + type}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
return <View>{examples}</View>;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
2016-03-02 15:06:37 +00:00
|
|
|
{
|
|
|
|
title: 'Blur on submit',
|
2018-05-11 20:32:37 +00:00
|
|
|
render: function(): React.Element<any> {
|
|
|
|
return <BlurOnSubmitExample />;
|
|
|
|
},
|
2016-03-02 15:06:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
{
|
|
|
|
title: 'Event handling',
|
2018-05-11 20:32:37 +00:00
|
|
|
render: function(): React.Element<any> {
|
|
|
|
return <TextEventsExample />;
|
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Colors and text inputs',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine]}
|
|
|
|
defaultValue="Default color text"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine, {color: 'green'}]}
|
|
|
|
defaultValue="Green Text"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
placeholder="Default placeholder text color"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
placeholder="Red placeholder text color"
|
|
|
|
placeholderTextColor="red"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
placeholder="Default underline color"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
placeholder="Blue underline color"
|
|
|
|
style={styles.singleLine}
|
|
|
|
underlineColorAndroid="blue"
|
|
|
|
/>
|
2015-09-29 16:12:19 +00:00
|
|
|
<TextInput
|
|
|
|
defaultValue="Same BackgroundColor as View "
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.singleLine,
|
|
|
|
{backgroundColor: 'rgba(100, 100, 100, 0.3)'},
|
|
|
|
]}>
|
2015-09-29 16:12:19 +00:00
|
|
|
<Text style={{backgroundColor: 'rgba(100, 100, 100, 0.3)'}}>
|
|
|
|
Darker backgroundColor
|
|
|
|
</Text>
|
|
|
|
</TextInput>
|
2016-02-03 13:48:31 +00:00
|
|
|
<TextInput
|
|
|
|
defaultValue="Highlight Color is red"
|
|
|
|
selectionColor={'red'}
|
2018-05-11 20:32:37 +00:00
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
2015-09-14 14:35:58 +00:00
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Text input, themes and heights',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<TextInput
|
|
|
|
placeholder="If you set height, beware of padding set from themes"
|
|
|
|
style={[styles.singleLineWithHeightTextInput]}
|
|
|
|
/>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
2016-04-28 20:21:57 +00:00
|
|
|
{
|
|
|
|
title: 'fontFamily, fontWeight and fontStyle',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
2016-06-28 21:11:23 +00:00
|
|
|
<TextInput
|
2016-04-28 20:21:57 +00:00
|
|
|
style={[styles.singleLine, {fontFamily: 'sans-serif'}]}
|
|
|
|
placeholder="Custom fonts like Sans-Serif are supported"
|
|
|
|
/>
|
2016-06-28 21:11:23 +00:00
|
|
|
<TextInput
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.singleLine,
|
|
|
|
{fontFamily: 'sans-serif', fontWeight: 'bold'},
|
|
|
|
]}
|
2016-04-28 20:21:57 +00:00
|
|
|
placeholder="Sans-Serif bold"
|
|
|
|
/>
|
2016-06-28 21:11:23 +00:00
|
|
|
<TextInput
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.singleLine,
|
|
|
|
{fontFamily: 'sans-serif', fontStyle: 'italic'},
|
|
|
|
]}
|
2016-04-28 20:21:57 +00:00
|
|
|
placeholder="Sans-Serif italic"
|
|
|
|
/>
|
2016-06-28 21:11:23 +00:00
|
|
|
<TextInput
|
2016-04-28 20:21:57 +00:00
|
|
|
style={[styles.singleLine, {fontFamily: 'serif'}]}
|
|
|
|
placeholder="Serif"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-04-28 20:21:57 +00:00
|
|
|
},
|
Implement letterSpacing on Android >= 5.0
Summary:
`letterSpacing` is completely missing from RN Android at the moment.
I've reviewed the `letterSpacing` implementations in #13199, #13877 and #16801 (that all seem to have stalled) and managed to put together an improved one based on #13199, updated to merge cleanly post https://github.com/facebook/react-native/commit/6114f863c3aed826355530bcf404ee5aed2f927b, that resolves the [issues](https://github.com/facebook/react-native/pull/13199#issuecomment-354568863) I've identified with that code.
I believe this is the closest PR yet to a correct implementation of this feature, with a few caveats:
- As with the other PRs, this only works on Android >= 5.0 (silently falling back to no letter spacing on older versions). Is this acceptable for a RN feature, in general? Would a dev mode warning be desirable?
- The other PRs seem to have explored the space of potential solutions to the layout issue ([Android renders space _around_ glyphs](https://issuetracker.google.com/issues/37079859), iOS to the _right_ of each one) and come up empty, so I've opted to merely document the difference.
- I have neither updated nor tested the "Flat" UI implementation - everything compiles but I've taken [this comment](https://github.com/facebook/react-native/issues/12770#issuecomment-294052694) to mean there's no point in trying to wade through it on my own right now; I'm happy to tackle it if given some pointers.
- The implementation in `ReactEditText` is only there to handle the placeholder text, as `ReactBaseTextShadowNode` already affects the input control's contents correctly.
- I'm not sure whether `<TextInput>` is meant to respect `allowFontScaling`; I've taken my cue here from `ReactTextInputManager.setFontSize()`, and used the same units (SP) to interpret the value in `ReactEditText.setLetterSpacingPt()`.
- I'm not sure whether `<TextInput>` is even meant to support `letterSpacing` - it doesn't actually work on iOS. I'm not going to be able to handle the Objective-C side of this, not as part of this PR at least.
- I have not added unit tests to `ReactTextTest` - is this desirable? I see that some other props such as `lineHeight` aren't covered there (unless I'm not looking in the right place).
- Overall, I'm new to this codebase, so it's likely I've missed something not mentioned here.
Note comment re: unit tests above; RNTester screenshots follow.
| iOS (existing functionality, amended test) | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458459-c8d59498-edcb-11e7-8c8f-e7426f723886.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458473-2a1ca368-edcc-11e7-9ce6-30c6d3a48660.png width=300> |
| iOS _(not implemented, test not in this branch)_ | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458481-6c60a36e-edcc-11e7-9af5-9734dd722ced.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458486-8b3cdcf8-edcc-11e7-974b-25c6085fa674.png width=300> |
| iOS _(not implemented, test not in this branch)_ | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458492-d69a77be-edcc-11e7-896f-21212621dbee.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458490-b3a1139e-edcc-11e7-88c8-79d4430d1514.png width=300> |
https://github.com/facebook/react-native-website/pull/105 - this docs PR is edited slightly from what's in `TextStylePropTypes` here; happy to align either one to the other after a review.
[ANDROID] [FEATURE] [Text] - Implemented letterSpacing
Closes https://github.com/facebook/react-native/pull/17398
Reviewed By: mdvacca
Differential Revision: D6837718
Pulled By: hramos
fbshipit-source-id: 5c9d49e9cf4af6457b636416ce5fe15315aab72c
2018-02-27 22:26:20 +00:00
|
|
|
{
|
|
|
|
title: 'letterSpacing',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine, {letterSpacing: 0}]}
|
|
|
|
placeholder="letterSpacing = 0"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine, {letterSpacing: 2}]}
|
|
|
|
placeholder="letterSpacing = 2"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine, {letterSpacing: 9}]}
|
|
|
|
placeholder="letterSpacing = 9"
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
style={[styles.singleLine, {letterSpacing: -1}]}
|
|
|
|
placeholder="letterSpacing = -1"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
Implement letterSpacing on Android >= 5.0
Summary:
`letterSpacing` is completely missing from RN Android at the moment.
I've reviewed the `letterSpacing` implementations in #13199, #13877 and #16801 (that all seem to have stalled) and managed to put together an improved one based on #13199, updated to merge cleanly post https://github.com/facebook/react-native/commit/6114f863c3aed826355530bcf404ee5aed2f927b, that resolves the [issues](https://github.com/facebook/react-native/pull/13199#issuecomment-354568863) I've identified with that code.
I believe this is the closest PR yet to a correct implementation of this feature, with a few caveats:
- As with the other PRs, this only works on Android >= 5.0 (silently falling back to no letter spacing on older versions). Is this acceptable for a RN feature, in general? Would a dev mode warning be desirable?
- The other PRs seem to have explored the space of potential solutions to the layout issue ([Android renders space _around_ glyphs](https://issuetracker.google.com/issues/37079859), iOS to the _right_ of each one) and come up empty, so I've opted to merely document the difference.
- I have neither updated nor tested the "Flat" UI implementation - everything compiles but I've taken [this comment](https://github.com/facebook/react-native/issues/12770#issuecomment-294052694) to mean there's no point in trying to wade through it on my own right now; I'm happy to tackle it if given some pointers.
- The implementation in `ReactEditText` is only there to handle the placeholder text, as `ReactBaseTextShadowNode` already affects the input control's contents correctly.
- I'm not sure whether `<TextInput>` is meant to respect `allowFontScaling`; I've taken my cue here from `ReactTextInputManager.setFontSize()`, and used the same units (SP) to interpret the value in `ReactEditText.setLetterSpacingPt()`.
- I'm not sure whether `<TextInput>` is even meant to support `letterSpacing` - it doesn't actually work on iOS. I'm not going to be able to handle the Objective-C side of this, not as part of this PR at least.
- I have not added unit tests to `ReactTextTest` - is this desirable? I see that some other props such as `lineHeight` aren't covered there (unless I'm not looking in the right place).
- Overall, I'm new to this codebase, so it's likely I've missed something not mentioned here.
Note comment re: unit tests above; RNTester screenshots follow.
| iOS (existing functionality, amended test) | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458459-c8d59498-edcb-11e7-8c8f-e7426f723886.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458473-2a1ca368-edcc-11e7-9ce6-30c6d3a48660.png width=300> |
| iOS _(not implemented, test not in this branch)_ | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458481-6c60a36e-edcc-11e7-9af5-9734dd722ced.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458486-8b3cdcf8-edcc-11e7-974b-25c6085fa674.png width=300> |
| iOS _(not implemented, test not in this branch)_ | Android (new functionality & test) |
| - | - |
| <img src=https://user-images.githubusercontent.com/2246565/34458492-d69a77be-edcc-11e7-896f-21212621dbee.png width=300> | <img src=https://user-images.githubusercontent.com/2246565/34458490-b3a1139e-edcc-11e7-88c8-79d4430d1514.png width=300> |
https://github.com/facebook/react-native-website/pull/105 - this docs PR is edited slightly from what's in `TextStylePropTypes` here; happy to align either one to the other after a review.
[ANDROID] [FEATURE] [Text] - Implemented letterSpacing
Closes https://github.com/facebook/react-native/pull/17398
Reviewed By: mdvacca
Differential Revision: D6837718
Pulled By: hramos
fbshipit-source-id: 5c9d49e9cf4af6457b636416ce5fe15315aab72c
2018-02-27 22:26:20 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
{
|
|
|
|
title: 'Passwords',
|
|
|
|
render: function() {
|
|
|
|
return (
|
2016-03-21 20:47:23 +00:00
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
defaultValue="iloveturtles"
|
|
|
|
secureTextEntry={true}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
2016-04-06 16:20:39 +00:00
|
|
|
<TextInput
|
2016-03-21 20:47:23 +00:00
|
|
|
secureTextEntry={true}
|
|
|
|
style={[styles.singleLine, {color: 'red'}]}
|
|
|
|
placeholder="color is supported too"
|
|
|
|
placeholderTextColor="red"
|
|
|
|
/>
|
|
|
|
</View>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Editable',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<TextInput
|
2018-05-11 20:32:37 +00:00
|
|
|
defaultValue="Can't touch this! (>'-')> ^(' - ')^ <('-'<) (>'-')> ^(' - ')^"
|
|
|
|
editable={false}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
2015-09-14 14:35:58 +00:00
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Multiline',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect={true}
|
|
|
|
placeholder="multiline, aligned top-left"
|
|
|
|
placeholderTextColor="red"
|
|
|
|
multiline={true}
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.multiline,
|
|
|
|
{textAlign: 'left', textAlignVertical: 'top'},
|
|
|
|
]}
|
2015-09-14 14:35:58 +00:00
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect={true}
|
|
|
|
placeholder="multiline, aligned center"
|
|
|
|
placeholderTextColor="green"
|
|
|
|
multiline={true}
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.multiline,
|
|
|
|
{textAlign: 'center', textAlignVertical: 'center'},
|
|
|
|
]}
|
2015-09-14 14:35:58 +00:00
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
autoCorrect={true}
|
|
|
|
multiline={true}
|
2018-05-11 20:32:37 +00:00
|
|
|
style={[
|
|
|
|
styles.multiline,
|
|
|
|
{color: 'blue'},
|
|
|
|
{textAlign: 'right', textAlignVertical: 'bottom'},
|
|
|
|
]}>
|
|
|
|
<Text style={styles.multiline}>
|
|
|
|
multiline with children, aligned bottom-right
|
|
|
|
</Text>
|
2015-09-14 14:35:58 +00:00
|
|
|
</TextInput>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Fixed number of lines',
|
|
|
|
platform: 'android',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TextInput
|
|
|
|
numberOfLines={2}
|
2015-09-14 14:35:58 +00:00
|
|
|
multiline={true}
|
|
|
|
placeholder="Two line input"
|
|
|
|
/>
|
2018-05-11 20:32:37 +00:00
|
|
|
<TextInput
|
|
|
|
numberOfLines={5}
|
2015-09-14 14:35:58 +00:00
|
|
|
multiline={true}
|
|
|
|
placeholder="Five line input"
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
},
|
2016-01-25 13:45:44 +00:00
|
|
|
{
|
|
|
|
title: 'Auto-expanding',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
2017-10-02 23:29:44 +00:00
|
|
|
<AutogrowingTextInputExample
|
2016-01-25 13:45:44 +00:00
|
|
|
enablesReturnKeyAutomatically={true}
|
|
|
|
returnKeyType="done"
|
2017-10-02 23:29:44 +00:00
|
|
|
multiline={true}
|
2018-05-11 20:32:37 +00:00
|
|
|
style={{maxHeight: 400, minHeight: 20, backgroundColor: '#eeeeee'}}>
|
2017-10-02 23:29:44 +00:00
|
|
|
generic generic generic
|
|
|
|
<Text style={{fontSize: 6, color: 'red'}}>
|
|
|
|
small small small small small small
|
|
|
|
</Text>
|
|
|
|
<Text>regular regular</Text>
|
|
|
|
<Text style={{fontSize: 30, color: 'green'}}>
|
|
|
|
huge huge huge huge huge
|
|
|
|
</Text>
|
|
|
|
generic generic generic
|
|
|
|
</AutogrowingTextInputExample>
|
2016-01-25 13:45:44 +00:00
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-01-25 13:45:44 +00:00
|
|
|
},
|
2015-11-06 16:22:22 +00:00
|
|
|
{
|
|
|
|
title: 'Attributed text',
|
|
|
|
render: function() {
|
|
|
|
return <TokenizedTextExample />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-11-06 16:22:22 +00:00
|
|
|
},
|
2016-05-05 17:21:35 +00:00
|
|
|
{
|
|
|
|
title: 'Return key',
|
|
|
|
render: function() {
|
|
|
|
var returnKeyTypes = [
|
|
|
|
'none',
|
|
|
|
'go',
|
|
|
|
'search',
|
|
|
|
'send',
|
|
|
|
'done',
|
|
|
|
'previous',
|
|
|
|
'next',
|
|
|
|
];
|
2018-05-11 20:32:37 +00:00
|
|
|
var returnKeyLabels = ['Compile', 'React Native'];
|
|
|
|
var examples = returnKeyTypes.map(type => {
|
2016-05-05 17:21:35 +00:00
|
|
|
return (
|
|
|
|
<TextInput
|
|
|
|
key={type}
|
|
|
|
returnKeyType={type}
|
|
|
|
placeholder={'returnKeyType: ' + type}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-05-11 20:32:37 +00:00
|
|
|
var types = returnKeyLabels.map(type => {
|
2016-05-05 17:21:35 +00:00
|
|
|
return (
|
|
|
|
<TextInput
|
|
|
|
key={type}
|
|
|
|
returnKeyLabel={type}
|
|
|
|
placeholder={'returnKeyLabel: ' + type}
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2018-05-11 20:32:37 +00:00
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
{examples}
|
|
|
|
{types}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
2016-05-05 17:21:35 +00:00
|
|
|
},
|
2016-06-28 21:11:23 +00:00
|
|
|
{
|
|
|
|
title: 'Inline Images',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<TextInput
|
|
|
|
inlineImageLeft="ic_menu_black_24dp"
|
|
|
|
placeholder="This has drawableLeft set"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
inlineImageLeft="ic_menu_black_24dp"
|
|
|
|
inlineImagePadding={30}
|
|
|
|
placeholder="This has drawableLeft and drawablePadding set"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
<TextInput
|
|
|
|
placeholder="This does not have drawable props set"
|
|
|
|
style={styles.singleLine}
|
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-06-28 21:11:23 +00:00
|
|
|
},
|
2016-08-18 10:15:51 +00:00
|
|
|
{
|
|
|
|
title: 'Toggle Default Padding',
|
2018-05-11 20:32:37 +00:00
|
|
|
render: function(): React.Element<any> {
|
|
|
|
return <ToggleDefaultPaddingExample />;
|
|
|
|
},
|
2016-08-18 10:15:51 +00:00
|
|
|
},
|
2016-09-05 14:04:26 +00:00
|
|
|
{
|
|
|
|
title: 'Text selection & cursor placement',
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<SelectionExample
|
|
|
|
style={styles.default}
|
|
|
|
value="text selection can be changed"
|
|
|
|
/>
|
|
|
|
<SelectionExample
|
|
|
|
multiline
|
|
|
|
style={styles.multiline}
|
2017-10-10 00:37:08 +00:00
|
|
|
value={'multiline text selection\ncan also be changed'}
|
2016-09-05 14:04:26 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
);
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-09-05 14:04:26 +00:00
|
|
|
},
|
2015-09-14 14:35:58 +00:00
|
|
|
];
|