Skip to content

Commit 5dbb3c5

Browse files
sherginfacebook-github-bot
authored andcommittedJan 15, 2018
Modern TextInput's render function for iOS
Reviewed By: sahrens Differential Revision: D6690930 fbshipit-source-id: a6ce5f006b4e6d63feef0f9c0743fb19b0e546fa
1 parent a5af841 commit 5dbb3c5

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed
 

‎Libraries/Components/TextInput/TextInput.js

+55-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,9 @@ const TextInput = createReactClass({
669669

670670
render: function() {
671671
if (Platform.OS === 'ios') {
672-
return this._renderIOS();
672+
return UIManager.RCTVirtualText
673+
? this._renderIOS()
674+
: this._renderIOSLegacy();
673675
} else if (Platform.OS === 'android') {
674676
return this._renderAndroid();
675677
}
@@ -687,7 +689,7 @@ const TextInput = createReactClass({
687689
this._inputRef = ref;
688690
},
689691

690-
_renderIOS: function() {
692+
_renderIOSLegacy: function() {
691693
var textContainer;
692694

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

783+
_renderIOS: function() {
784+
var props = Object.assign({}, this.props);
785+
props.style = [this.props.style];
786+
787+
if (props.selection && props.selection.end == null) {
788+
props.selection = {
789+
start: props.selection.start,
790+
end: props.selection.start,
791+
};
792+
}
793+
794+
const RCTTextInputView = props.multiline
795+
? RCTMultilineTextInputView
796+
: RCTSinglelineTextInputView;
797+
798+
if (props.multiline) {
799+
props.style.unshift(styles.multilineInput);
800+
}
801+
802+
const textContainer = (
803+
<RCTTextInputView
804+
ref={this._setNativeRef}
805+
{...props}
806+
onFocus={this._onFocus}
807+
onBlur={this._onBlur}
808+
onChange={this._onChange}
809+
onContentSizeChange={this.props.onContentSizeChange}
810+
onSelectionChange={this._onSelectionChange}
811+
onTextInput={this._onTextInput}
812+
onSelectionChangeShouldSetResponder={emptyFunction.thatReturnsTrue}
813+
text={this._getText()}
814+
dataDetectorTypes={this.props.dataDetectorTypes}
815+
onScroll={this._onScroll}
816+
/>
817+
);
818+
819+
return (
820+
<TouchableWithoutFeedback
821+
onLayout={props.onLayout}
822+
onPress={this._onPress}
823+
rejectResponderTermination={true}
824+
accessible={props.accessible}
825+
accessibilityLabel={props.accessibilityLabel}
826+
accessibilityTraits={props.accessibilityTraits}
827+
nativeID={this.props.nativeID}
828+
testID={props.testID}>
829+
{textContainer}
830+
</TouchableWithoutFeedback>
831+
);
832+
},
833+
781834
_renderAndroid: function() {
782835
const props = Object.assign({}, this.props);
783836
props.style = [this.props.style];

0 commit comments

Comments
 (0)
Please sign in to comment.