Skip to content

Commit b7bd85a

Browse files
elicwhitefacebook-github-bot
authored andcommitted
Refactor to not copy props
Summary: We don't need a local mutable copy of props. Changelog: [Internal] Reviewed By: JoshuaGross Differential Revision: D18435731 fbshipit-source-id: 13ec1a78ca26b1372a4aed484a821204a93b6437
1 parent 854fa96 commit b7bd85a

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

Libraries/Components/TextInput/TextInput.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -872,48 +872,46 @@ const TextInput = createReactClass({
872872
// This is a hack to let Flow know we want an exact object
873873
|} = {...null};
874874

875-
if (Platform.OS === 'ios') {
876-
const props = Object.assign({}, this.props);
877-
props.style = [this.props.style];
878-
879-
if (props.selection && props.selection.end == null) {
880-
props.selection = {
881-
start: props.selection.start,
882-
end: props.selection.start,
883-
};
884-
}
875+
const selection =
876+
this.props.selection && this.props.selection.end == null
877+
? {
878+
start: this.props.selection.start,
879+
end: this.props.selection.start,
880+
}
881+
: null;
885882

886-
const RCTTextInputView = props.multiline
883+
if (Platform.OS === 'ios') {
884+
const RCTTextInputView = this.props.multiline
887885
? RCTMultilineTextInputView
888886
: RCTSinglelineTextInputView;
889887

890-
if (props.multiline) {
891-
props.style.unshift(styles.multilineInput);
892-
}
888+
const style = this.props.multiline
889+
? [styles.multilineInput, this.props.style]
890+
: this.props.style;
893891

894-
additionalTouchableProps.rejectResponderTermination =
895-
props.rejectResponderTermination;
892+
additionalTouchableProps.rejectResponderTermination = this.props.rejectResponderTermination;
896893

897894
textInput = (
898895
<RCTTextInputView
899896
ref={this._setNativeRef}
900-
{...props}
897+
{...this.props}
901898
onFocus={this._onFocus}
902899
onBlur={this._onBlur}
903900
onChange={this._onChange}
904901
onContentSizeChange={this.props.onContentSizeChange}
905902
onSelectionChange={this._onSelectionChange}
906903
onTextInput={this._onTextInput}
907904
onSelectionChangeShouldSetResponder={emptyFunctionThatReturnsTrue}
905+
selection={selection}
906+
style={style}
908907
text={this._getText()}
909908
dataDetectorTypes={this.props.dataDetectorTypes}
910909
onScroll={this._onScroll}
911910
/>
912911
);
913912
} else if (Platform.OS === 'android') {
914-
const props = Object.assign({}, this.props);
915-
props.style = [this.props.style];
916-
props.autoCapitalize = props.autoCapitalize || 'sentences';
913+
const style = [this.props.style];
914+
const autoCapitalize = this.props.autoCapitalize || 'sentences';
917915
let children = this.props.children;
918916
let childCount = 0;
919917
React.Children.forEach(children, () => ++childCount);
@@ -925,23 +923,19 @@ const TextInput = createReactClass({
925923
children = <Text>{children}</Text>;
926924
}
927925

928-
if (props.selection && props.selection.end == null) {
929-
props.selection = {
930-
start: props.selection.start,
931-
end: props.selection.start,
932-
};
933-
}
934-
935926
textInput = (
936927
<AndroidTextInput
937928
ref={this._setNativeRef}
938-
{...props}
929+
{...this.props}
930+
autoCapitalize={autoCapitalize}
939931
mostRecentEventCount={0}
940932
onFocus={this._onFocus}
941933
onBlur={this._onBlur}
942934
onChange={this._onChange}
943935
onSelectionChange={this._onSelectionChange}
944936
onTextInput={this._onTextInput}
937+
selection={selection}
938+
style={style}
945939
text={this._getText()}
946940
children={children}
947941
disableFullscreenUI={this.props.disableFullscreenUI}

0 commit comments

Comments
 (0)