8
8
*
9
9
* @providesModule TextInput
10
10
* @flow
11
+ * @format
11
12
*/
12
13
'use strict' ;
13
14
@@ -50,8 +51,14 @@ const onlyMultiline = {
50
51
if ( Platform . OS === 'android' ) {
51
52
var AndroidTextInput = requireNativeComponent ( 'AndroidTextInput' , null ) ;
52
53
} else if ( Platform . OS === 'ios' ) {
53
- var RCTMultilineTextInputView = requireNativeComponent ( 'RCTMultilineTextInputView' , null ) ;
54
- var RCTSinglelineTextInputView = requireNativeComponent ( 'RCTSinglelineTextInputView' , null ) ;
54
+ var RCTMultilineTextInputView = requireNativeComponent (
55
+ 'RCTMultilineTextInputView' ,
56
+ null ,
57
+ ) ;
58
+ var RCTSinglelineTextInputView = requireNativeComponent (
59
+ 'RCTSinglelineTextInputView' ,
60
+ null ,
61
+ ) ;
55
62
}
56
63
57
64
type Event = Object ;
@@ -279,11 +286,7 @@ const TextInput = createReactClass({
279
286
* Determines the color of the keyboard.
280
287
* @platform ios
281
288
*/
282
- keyboardAppearance : PropTypes . oneOf ( [
283
- 'default' ,
284
- 'light' ,
285
- 'dark' ,
286
- ] ) ,
289
+ keyboardAppearance : PropTypes . oneOf ( [ 'default' , 'light' , 'dark' ] ) ,
287
290
/**
288
291
* Determines how the return key should look. On Android you can also use
289
292
* `returnKeyLabel`.
@@ -448,8 +451,8 @@ const TextInput = createReactClass({
448
451
*/
449
452
secureTextEntry : PropTypes . bool ,
450
453
/**
451
- * The highlight and cursor color of the text input.
452
- */
454
+ * The highlight and cursor color of the text input.
455
+ */
453
456
selectionColor : ColorPropType ,
454
457
/**
455
458
* An instance of `DocumentSelectionState`, this is some state that is responsible for
@@ -603,8 +606,10 @@ const TextInput = createReactClass({
603
606
* Returns `true` if the input is currently focused; `false` otherwise.
604
607
*/
605
608
isFocused : function ( ) : boolean {
606
- return TextInputState . currentlyFocusedField ( ) = ==
607
- ReactNative . findNodeHandle ( this . _inputRef ) ;
609
+ return (
610
+ TextInputState . currentlyFocusedField ( ) ===
611
+ ReactNative . findNodeHandle ( this . _inputRef )
612
+ ) ;
608
613
} ,
609
614
610
615
contextTypes : {
@@ -627,13 +632,13 @@ const TextInput = createReactClass({
627
632
}
628
633
this . _focusSubscription = this . context . focusEmitter . addListener (
629
634
'focus' ,
630
- ( el ) => {
635
+ el => {
631
636
if ( this === el ) {
632
637
this . requestAnimationFrame ( this . focus ) ;
633
638
} else if ( this . isFocused ( ) ) {
634
639
this . blur ( ) ;
635
640
}
636
- }
641
+ } ,
637
642
) ;
638
643
if ( this . props . autoFocus ) {
639
644
this . context . onFocusRequested ( this ) ;
@@ -652,7 +657,7 @@ const TextInput = createReactClass({
652
657
} ,
653
658
654
659
childContextTypes : {
655
- isInAParentText : PropTypes . bool
660
+ isInAParentText : PropTypes . bool ,
656
661
} ,
657
662
658
663
/**
@@ -671,13 +676,11 @@ const TextInput = createReactClass({
671
676
} ,
672
677
673
678
_getText : function ( ) : ?string {
674
- return typeof this . props . value === 'string' ?
675
- this . props . value :
676
- (
677
- typeof this . props . defaultValue === 'string' ?
678
- this . props . defaultValue :
679
- ''
680
- ) ;
679
+ return typeof this . props . value === 'string'
680
+ ? this . props . value
681
+ : typeof this . props . defaultValue === 'string'
682
+ ? this . props . defaultValue
683
+ : '' ;
681
684
} ,
682
685
683
686
_setNativeRef : function ( ref : any ) {
@@ -691,21 +694,26 @@ const TextInput = createReactClass({
691
694
props . style = [ this . props . style ] ;
692
695
693
696
if ( props . selection && props . selection . end == null ) {
694
- props . selection = { start : props . selection . start , end : props . selection . start } ;
697
+ props . selection = {
698
+ start : props . selection . start ,
699
+ end : props . selection . start ,
700
+ } ;
695
701
}
696
702
697
703
if ( ! props . multiline ) {
698
704
if ( __DEV__ ) {
699
705
for ( var propKey in onlyMultiline ) {
700
706
if ( props [ propKey ] ) {
701
707
const error = new Error (
702
- 'TextInput prop `' + propKey + '` is only supported with multiline.'
708
+ 'TextInput prop `' +
709
+ propKey +
710
+ '` is only supported with multiline.' ,
703
711
) ;
704
712
warning ( false , '%s' , error . stack ) ;
705
713
}
706
714
}
707
715
}
708
- textContainer =
716
+ textContainer = (
709
717
< RCTSinglelineTextInputView
710
718
ref = { this . _setNativeRef }
711
719
{ ...props }
@@ -715,23 +723,28 @@ const TextInput = createReactClass({
715
723
onSelectionChange = { this . _onSelectionChange }
716
724
onSelectionChangeShouldSetResponder = { emptyFunction . thatReturnsTrue }
717
725
text = { this . _getText ( ) }
718
- /> ;
726
+ />
727
+ ) ;
719
728
} else {
720
729
var children = props . children ;
721
730
var childCount = 0 ;
722
731
React . Children . forEach ( children , ( ) => ++ childCount ) ;
723
732
invariant (
724
733
! ( props . value && childCount ) ,
725
- 'Cannot specify both value and children.'
734
+ 'Cannot specify both value and children.' ,
726
735
) ;
727
736
if ( childCount >= 1 ) {
728
- children = < Text style = { props . style } allowFontScaling = { props . allowFontScaling } > { children } </ Text > ;
737
+ children = (
738
+ < Text style = { props . style } allowFontScaling = { props . allowFontScaling } >
739
+ { children }
740
+ </ Text >
741
+ ) ;
729
742
}
730
743
if ( props . inputView ) {
731
744
children = [ children , props . inputView ] ;
732
745
}
733
746
props . style . unshift ( styles . multilineInput ) ;
734
- textContainer =
747
+ textContainer = (
735
748
< RCTMultilineTextInputView
736
749
ref = { this . _setNativeRef }
737
750
{ ...props }
@@ -746,7 +759,8 @@ const TextInput = createReactClass({
746
759
text = { this . _getText ( ) }
747
760
dataDetectorTypes = { this . props . dataDetectorTypes }
748
761
onScroll = { this . _onScroll }
749
- /> ;
762
+ />
763
+ ) ;
750
764
}
751
765
752
766
return (
@@ -779,17 +793,20 @@ const TextInput = createReactClass({
779
793
React . Children . forEach ( children , ( ) => ++ childCount ) ;
780
794
invariant (
781
795
! ( this . props . value && childCount ) ,
782
- 'Cannot specify both value and children.'
796
+ 'Cannot specify both value and children.' ,
783
797
) ;
784
798
if ( childCount > 1 ) {
785
799
children = < Text > { children} < / T e x t > ;
786
800
}
787
801
788
802
if ( props . selection && props . selection . end == null ) {
789
- props . selection = { start : props . selection . start , end : props . selection . start } ;
803
+ props . selection = {
804
+ start : props . selection . start ,
805
+ end : props . selection . start ,
806
+ } ;
790
807
}
791
808
792
- const textContainer =
809
+ const textContainer = (
793
810
< AndroidTextInput
794
811
ref = { this . _setNativeRef }
795
812
{ ...props }
@@ -804,7 +821,8 @@ const TextInput = createReactClass({
804
821
disableFullscreenUI = { this . props . disableFullscreenUI }
805
822
textBreakStrategy = { this . props . textBreakStrategy }
806
823
onScroll = { this . _onScroll }
807
- /> ;
824
+ />
825
+ ) ;
808
826
809
827
return (
810
828
< TouchableWithoutFeedback
@@ -875,22 +893,28 @@ const TextInput = createReactClass({
875
893
}
876
894
} ,
877
895
878
- componentDidUpdate: function ( ) {
896
+ componentDidUpdate : function ( ) {
879
897
// This is necessary in case native updates the text and JS decides
880
898
// that the update should be ignored and we should stick with the value
881
899
// that we have in JS.
882
900
const nativeProps = { } ;
883
901
884
- if ( this . _lastNativeText !== this . props . value && typeof this . props . value === 'string' ) {
902
+ if (
903
+ this . _lastNativeText !== this . props . value &&
904
+ typeof this . props . value === 'string'
905
+ ) {
885
906
nativeProps . text = this . props . value ;
886
907
}
887
908
888
909
// Selection is also a controlled prop, if the native value doesn't match
889
910
// JS, update to the JS value.
890
911
const { selection } = this . props ;
891
- if ( this . _lastNativeSelection && selection &&
892
- ( this . _lastNativeSelection . start !== selection . start ||
893
- this . _lastNativeSelection . end !== selection . end ) ) {
912
+ if (
913
+ this . _lastNativeSelection &&
914
+ selection &&
915
+ ( this . _lastNativeSelection . start !== selection . start ||
916
+ this . _lastNativeSelection . end !== selection . end )
917
+ ) {
894
918
nativeProps . selection = this . props . selection ;
895
919
}
896
920
0 commit comments