【问题标题】:Skipping Views in React Native render function在 React Native 渲染函数中跳过视图
【发布时间】:2016-05-18 15:02:04
【问题描述】:

我正在尝试使用两个 TextInput 组件来呈现视图。 这是我的渲染函数:

 render () {
   return (
  <View style={styles.container}>

     <TextInput ref='title'
                placeholder="Untitled"
                style={styles.textInput, styles.title}
                autoFocus={true}
                onSubmitEditing={(event) => {this.refs.body.focus()}}
                />



     <TextInput ref='body'
         autoFocus={true}
         multiline={true}
         placeholder="Start typing"
         style={styles.textInput, styles.body}
         />

  </View>
);

现在,我想在每个 TextInput 下添加一个下划线。为了做到这一点,我将每个 TextInputs 包装在一个 View 组件中,并以这种方式将一个borderBottom 添加到 View 的样式中:

render () {
   return (
  <View style={styles.container}>
    <View style={styles.inputContainer}>
     <TextInput ref='title'
                placeholder="Untitled"
                style={styles.textInput, styles.title}
                autoFocus={true}
                onSubmitEditing={(event) => {this.refs.body.focus()}}
                />
    </View>

    <View style={styles.inputContainer}>
     <TextInput ref='body'
         autoFocus={true}
         multiline={true}
         placeholder="Start typing"
         style={styles.textInput, styles.body}
         />
    </View>
  </View>
);

这些都是我的风格:

var styles = StyleSheet.create({
 container: {
   flex: 1,
   justifyContent: 'center',
   alignItems: 'center',
   marginTop: 64
 },
  title: {
    height: 40
  },
  body: {
    flex: 1
  },

 inputContainer: {
   borderBottomColor: '#9E7CE3',
   borderBottomWidth: 1,
   flexDirection: 'row',
   marginBottom: 10
 },

 textInput: { 
   flex: 1,
   fontSize: 16,
 },

});

但是两个 TextInputs 消失了,我不明白为什么 (注:使用 ES6)

【问题讨论】:

  • 嘿嘿..你能分享你用过的所有样式吗...
  • 我编辑了我的帖子以显示我正在使用的所有样式

标签: javascript react-native


【解决方案1】:

注释flexDirection: 'row',这行,就会出现TextInputs。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-21
    相关资源
    最近更新 更多