【问题标题】:Why the wrap buttons block by the below components in react-native?为什么包装按钮被 react-native 中的以下组件阻塞?
【发布时间】:2017-05-09 17:44:34
【问题描述】:

我有一个视图包装了许多按钮,并且仍然通过 textinpt 持续创建更多按钮,下面的 clode,现在的结果,它向底部创建了新的 line 按钮,但是 textinpt 组件会空白,为什么?,任何人都知道怎么解决?

我的目标是自动挤压 textinpt 向下移动并让它显示整个 bottons。

const styles = {
  interests:{
    flexDirection: 'column',
    justifyContent: "space-between",
    paddingRight: 10,
    paddingLeft: 10,
  },
  editSection: {
      //flex: 1,
    flexDirection: 'row', 
    justifyContent: 'center', 
    alignItems: 'center',
    backgroundColor: '#fff',
  },
  editIcon: {
    flex: 0.05,
    paddingTop: 25
  },
  input: {
    flex: 0.95
  },
  popularTag:{
    flexWrap: 'wrap',
    flexDirection: 'row-reverse',
    justifyContent: 'flex-end',
    paddingTop: 10,
  }
}

return(
  <View style = { styles.interests }>
    <View style = { styles.popularTag }>
      { this.renderShowLists() }
    </View> 
    <View style = { styles.editSection }>
      <View style = { styles.input }>
        <TextInput
          placeholder = "Type your Interests"
          onSubmitEditing = { this.onKeyPress }     
          onChangeText = { (text) => this.setState({ text }) }
          value = { this.state.text }
        /> 
      </View>
      <View style = { styles.editIcon }>
        <Icon name = "border-color" color = "#000000" size = { 20 } />  
      </View>    
    </View>
  </View>  
)

实际上是三行,第二行由textinput分块

【问题讨论】:

    标签: javascript reactjs react-native


    【解决方案1】:

    您可以尝试为“popularTag”和“editSection”设置 flex 值(也为它们的父级设置 flex 值)。

    这 2 个包含在一个共同的父级中(“interests”,其 flexDirection 为 column,因此为 flex 设置 2),其中 2 个可能每个的 flex 值为 1 (这样“popularTag”和“editSection”的高度将相等,即基于其父级的 50% - flex: 2)

    的“兴趣”
      interests:{
        flex: 2,
      },
      editSection:{
        flex: 1,
      }
      popularTag:{
        flex: 1,
      }
    

    如果还不行,请在这里再发一张图片或一些错误,因为我没有时间运行所有代码,谢谢

    也请在这里查看我对另一个类似问题的回答,这也是关于 flexbox 值的,仅供参考:

    Why do my react-native components overlap

    【讨论】:

      猜你喜欢
      • 2017-01-26
      • 2014-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      • 2017-07-30
      • 1970-01-01
      相关资源
      最近更新 更多