Skip to content
Permalink
Browse files

Modern TextInput's render function for iOS

Reviewed By: sahrens

Differential Revision: D6690930

fbshipit-source-id: a6ce5f006b4e6d63feef0f9c0743fb19b0e546fa
  • Loading branch information...
shergin authored and facebook-github-bot committed Jan 15, 2018
1 parent a5af841 commit 5dbb3c586c9e8483aa7e6f1edd35ffb12bd4305d
Showing with 55 additions and 2 deletions.
  1. +55 −2 Libraries/Components/TextInput/TextInput.js
@@ -669,7 +669,9 @@ const TextInput = createReactClass({

render: function() {
if (Platform.OS === 'ios') {
return this._renderIOS();
return UIManager.RCTVirtualText
? this._renderIOS()
: this._renderIOSLegacy();
} else if (Platform.OS === 'android') {
return this._renderAndroid();
}
@@ -687,7 +689,7 @@ const TextInput = createReactClass({
this._inputRef = ref;
},

_renderIOS: function() {
_renderIOSLegacy: function() {
var textContainer;

var props = Object.assign({}, this.props);
@@ -778,6 +780,57 @@ const TextInput = createReactClass({
);
},

_renderIOS: function() {
var props = Object.assign({}, this.props);
props.style = [this.props.style];

if (props.selection && props.selection.end == null) {
props.selection = {
start: props.selection.start,
end: props.selection.start,
};
}

const RCTTextInputView = props.multiline
? RCTMultilineTextInputView
: RCTSinglelineTextInputView;

if (props.multiline) {
props.style.unshift(styles.multilineInput);
}

const textContainer = (
<RCTTextInputView
ref={this._setNativeRef}
{...props}
onFocus={this._onFocus}
onBlur={this._onBlur}
onChange={this._onChange}
onContentSizeChange={this.props.onContentSizeChange}
onSelectionChange={this._onSelectionChange}
onTextInput={this._onTextInput}
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
text={this._getText()}
dataDetectorTypes={this.props.dataDetectorTypes}
onScroll={this._onScroll}
/>
);

return (
<TouchableWithoutFeedback
onLayout={props.onLayout}
onPress={this._onPress}
rejectResponderTermination={true}
accessible={props.accessible}
accessibilityLabel={props.accessibilityLabel}
accessibilityTraits={props.accessibilityTraits}
nativeID={this.props.nativeID}
testID={props.testID}>
{textContainer}
</TouchableWithoutFeedback>
);
},

_renderAndroid: function() {
const props = Object.assign({}, this.props);
props.style = [this.props.style];

0 comments on commit 5dbb3c5

Please sign in to comment.
You can’t perform that action at this time.