Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

javascript - React Native parent view size is changing when adding a child view

I have a settings for language selection in my app. As you can see below, when I choose another language, the row height of the selected language is increasing a little bit. I would like to keep it fixed, and choosing a language should not have an effect on the row height. How can I achieve this?

enter image description here

      <FlatList
        data={availableLanguages}
        ItemSeparatorComponent={this.renderSeparator}
        renderItem={({ item }) => {
          return (
            <TouchableOpacity onPress={() => this.onChangeLang(item)}>
              <View style={styles.flatlistItem} >
                <Text style={styles.languageListitem} >{t('settings:' + item)}</Text>
                {appLanguage === item ? <View style={styles.listIconRightEnd}><CheckActiveLightMode width={25} /></View> : null}
              </View>
            </TouchableOpacity>
          )
        }}
        keyExtractor={(item, index) => index}
      />

Styles:

  flatlistItem: {
    margin: 4,
    paddingLeft: 10,
    paddingVertical: 7,
    backgroundColor: '#FFF',
    width: '100%',
    flex: 1,
    alignSelf: 'center',
    flexDirection: 'row',
    borderRadius: 0,
  },

  languageListitem: {
    color: 'rgb(48,49,147)',
    fontSize: 16,
    paddingLeft: 10,
    flex: 1,
  },

  listIconRightEnd: {
    paddingRight: 20,
  },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Solved with maxHeight:

 listIconRightEnd: {
   paddingRight: 20,
   maxHeight: 10,
 },

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...