简体   繁体   中英

TextInput Width - React Native

I have a TextInput in my React Native App. All this while I was using simulator "iPhone X" and it was working fine. Now I changed my simulator to "iPhone 5" and the width doesn't match.

                  <TextInput  
                    value={value} 
                    placeholder='Search Here...'
                    onChangeText={(text)=>{this.handleSearch(text)}
                    onTouchStart={()=>{this.setTempNotifications()}
                    style={{ height: 40, width: 290}}
                    autoCapitalize='none'
                    selectTextOnFocus={true}
                  />


I had set the width to "290". How do I make my TextInput width flexible???? It has to fit all phone screens and I do not have to fix a width.

You don't really have to give a width value. Only the height is enough to make the TextInput span across its parent.

export default function App() {
  return (
    <View style={{flex: 1}}>
        <TextInput  
          placeholder='Search Here...'                  
          style={{ height: 40, borderWidth: 1}}
          autoCapitalize='none'
          selectTextOnFocus={true}
          />
    </View>
  );
}

The containing view can have padding or margin for appropriate gutter space

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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