简体   繁体   English

如何在 Input 组件的 inputContainerStyle 中将 backgroundColor 作为道具传递给本机元素

[英]How to pass backgroundColor as props in inputContainerStyle in Input component react native elements

               const AppInput = (_props: InputProps) => {

                  return(
                         <Input
                         labelStyle={styles.labelStyle}
                         inputContainerStyle={[
                         styles.inputContainerStyle,
                         {
                          borderColor: _props.placeholderTextColor,
                          borderWidth: isFocus ? 1 : 0,
                          borderBottomWidth: isFocus ? 1 : 0,
                          backgroundColor: Props.backgroundColor, //in this line i want to 
                                                        pass props from parents component

                          },
                          ]}
                          inputStyle={styles.inputStyle}

                         autoCompleteType="phone"
                         {..._props}
                         errorStyle={styles.errorStyle}
                         onFocus={() => onFocus(true)}
                         onBlur={onBlur}
                         />
                      )
                    }

Through parents components通过父组件

                       <AppInput
                      placeholder={
                      isExculde ? "Don't show recipes with..." : 'Prefer recipes with...'
                       }
                        placeholderTextColor={ isExculde ? colors.icon.danger : 
                          colors.inputSetting.success
                         }
                         keyboardType="default"
                      rightIcon={
                         <Icon
                         name="search"
                         size={24}
                         color={
                             isExculde ? colors.icon.danger : colors.inputSetting.success
                               }
                        tvParallaxProperties={undefined}
                         containerStyle={{right: 8}}
                         />
                          }
                       onChangeText={e => setShowExcludeList()}
    
                      inputContainerStyle={{backgroundColor:"red"}}
                      />

when i pass inputContainerStyle from parent comp.net its override the default style from Input component, i just want to pass backgroundcolor but not override default styles.当我从父 comp.net 传递 inputContainerStyle 时,它会覆盖 Input 组件的默认样式,我只想传递 backgroundcolor 但不覆盖默认值 styles。

Right now its look like this: https://ibb.co/GpTgDpt But i want to look like this: https://ibb.co/SfJrQ4H现在它看起来像这样: https://ibb.co/GpTgDpt但我想像这样: https://ibb.co/SfJrQ4H

       const AppInput = (props) => {
       const {inputContainerStyle} = props;

          return(
                 <Input
                 labelStyle={styles.labelStyle}
                 inputContainerStyle={{
                 ...styles.inputContainerStyle,
                 ...inputContainerStyle,
                  }}
                  inputStyle={styles.inputStyle}

                 autoCompleteType="phone"
                 {..._props}
                 errorStyle={styles.errorStyle}
                 onFocus={() => onFocus(true)}
                 onBlur={onBlur}
                 />
              )
            }

Now in your parent component send backgroudColor and other style props in inputStyle prop.现在在您的父组件中发送 backgroudColor 和 inputStyle 道具中的其他样式道具。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM