11import * as React from "react" ;
22import {
3- Dimensions ,
43 StyleProp ,
54 TextInput ,
65 TextInputProps ,
@@ -9,28 +8,35 @@ import {
98 Image ,
109 TouchableOpacity ,
1110 View ,
11+ TextStyle ,
1212} from "react-native" ;
1313/**
1414 * ? Local Imports
1515 */
16- import styles from "./InteractiveTextInput.style" ;
16+ import styles , { _textInputStyle } from "./InteractiveTextInput.style" ;
1717
18- const { width : ScreenWidth } = Dimensions . get ( "screen" ) ;
1918const AnimatedTextInput = Animated . createAnimatedComponent ( TextInput ) ;
2019
21- const SUCCESS_COLOR = "#008FEB" ;
20+ const MAIN_COLOR = "#008FEB" ;
2221const ORIGINAL_COLOR = "transparent" ;
23- const ORIGINAL_VALUE = 0 ;
24- const SUCCESS_VALUE = 1 ;
2522const PLACEHOLDER_COLOR = "#757575" ;
23+ const ORIGINAL_VALUE = 0 ;
24+ const ANIMATED_VALUE = 1 ;
2625
2726type CustomStyleProp = StyleProp < ViewStyle > | Array < StyleProp < ViewStyle > > ;
27+ type CustomTextStyleProp = StyleProp < TextStyle > | Array < StyleProp < TextStyle > > ;
2828
2929interface IInteractiveTextInputProps extends TextInputProps {
3030 style ?: CustomStyleProp ;
31+ textInputStyle ?: CustomTextStyleProp ;
3132 ImageComponent ?: any ;
3233 IconComponent ?: any ;
3334 enableIcon ?: boolean ;
35+ mainColor ?: string ;
36+ originalColor ?: string ;
37+ animatedPlaceholderTextColor ?: string ;
38+ onFocus ?: ( ) => void ;
39+ onBlur ?: ( ) => void ;
3440}
3541
3642interface IState { }
@@ -58,7 +64,7 @@ export default class InteractiveTextInput extends React.Component<
5864 showFocusColor = ( ) => {
5965 Animated . timing ( this . interpolatedColor , {
6066 duration : 450 ,
61- toValue : SUCCESS_VALUE ,
67+ toValue : ANIMATED_VALUE ,
6268 useNativeDriver : false ,
6369 } ) . start ( ) ;
6470 } ;
@@ -97,43 +103,40 @@ export default class InteractiveTextInput extends React.Component<
97103 } ;
98104
99105 renderAnimatedTextInput = ( ) => {
106+ const mainColor = this . props . mainColor || MAIN_COLOR ;
107+ const originalColor = this . props . originalColor || ORIGINAL_COLOR ;
108+ const animatedPlaceholderTextColor =
109+ this . props . animatedPlaceholderTextColor || PLACEHOLDER_COLOR ;
110+
100111 let borderColor = this . interpolatedColor . interpolate ( {
101- inputRange : [ ORIGINAL_VALUE , SUCCESS_VALUE ] ,
102- outputRange : [ ORIGINAL_COLOR , SUCCESS_COLOR ] ,
112+ inputRange : [ ORIGINAL_VALUE , ANIMATED_VALUE ] ,
113+ outputRange : [ originalColor , mainColor ] ,
103114 } ) ;
104115 let placeholderTextColor = this . interpolatedColor . interpolate ( {
105- inputRange : [ ORIGINAL_VALUE , SUCCESS_VALUE ] ,
106- outputRange : [ PLACEHOLDER_COLOR , SUCCESS_COLOR ] ,
116+ inputRange : [ ORIGINAL_VALUE , ANIMATED_VALUE ] ,
117+ outputRange : [ animatedPlaceholderTextColor , mainColor ] ,
107118 } ) ;
108119 return (
109120 < AnimatedTextInput
110- style = { {
111- height : 50 ,
112- width : ScreenWidth * 0.9 ,
113- backgroundColor : "#eceef5" ,
114- paddingLeft : 16 ,
115- paddingRight : 16 ,
116- borderRadius : 8 ,
117- justifyContent : "center" ,
118- borderWidth : 1 ,
119- borderColor : borderColor ,
120- } }
121121 placeholderTextColor = { placeholderTextColor }
122122 placeholder = "Email"
123+ { ...this . props }
124+ style = { [ _textInputStyle ( borderColor ) , this . props . textInputStyle ] }
123125 onFocus = { ( ) => {
124126 this . showFocusColor ( ) ;
127+ this . props . onFocus && this . props . onFocus ( ) ;
125128 } }
126129 onBlur = { ( ) => {
127130 this . showOriginColor ( ) ;
131+ this . props . onBlur && this . props . onBlur ( ) ;
128132 } }
129- { ...this . props }
130133 />
131134 ) ;
132135 } ;
133136
134137 render ( ) {
135138 return (
136- < View style = { { flexDirection : "row" , alignItems : "center" } } >
139+ < View style = { styles . container } >
137140 { this . renderAnimatedTextInput ( ) }
138141 { this . renderIcon ( ) }
139142 </ View >
0 commit comments