css - React Native 边距作用于对象内部,而不是外部

标签 css reactjs react-native flexbox

转到 https://snack.expo.io/HJV601djf并打开 login_screen/components/Form.js。如您所见,textInput 具有样式

  textInput: {
    flex:1,
    height: 50,
    marginBottom: 20
  }

您可以看到用户图标未与文本输入对齐。如果我取出 marginBottom ,一切正常,但是使用 marginBottom: 20 图标会被取消对齐。我可能也可以通过使文本输入也垂直对齐来解决这个问题,但我不知道问题的原因。

如果只在外部添加空间,marginBottom 会如何影响 UserInput 的内部?

如果您不想等待加载应用程序,请打印屏幕:

enter image description here

最佳答案

发生这种情况是因为,在您的 UserInput.js 中,您试图合并 textInput 的样式,而 图像/图标 样式保持不变,因此未对齐

解决这个问题的最佳方法是向组件添加一个 textInputContainer 样式,并将边距设置为

TextInput.js

<View style={mergeObjects(this.props.containerStyle ? StyleSheet.flatten(this.props.containerStyle) : {}, StyleSheet.flatten(styles.inputWrapper))}>

Form.js

<UserInput
          containerStyle={styles.textInputContainer}
          style={styles.textInput}
          source={{uri:'http://www.free-icons-download.net/images/user-icon-74490.png'}}
          placeholder="e-mail"
          autoCapitalize={'none'}
          returnKeyType={'done'}
          autoCorrect={false}
        />

样式

textInputContainer : {
        marginBottom: 20
  },

这是 snack同样

关于css - React Native 边距作用于对象内部,而不是外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49722006/

相关文章:

reactjs - React 16 类型 'DetailedHTMLProps, HTMLDivElement>' 上不存在属性

css - 在 React Native 中显示像 Instagram 一样的图像部分?

javascript - 带有 React Native 的 Typescript 2.0

c# - 更改 DataGridTemplateColumn 内容样式

reactjs - ag-Grid React applyTransaction 不是函数

javascript - 将组件连接到 redux 全局状态 vs 将 props 传递给 React-Native 中的子组件

ios - 如何在 React Native 中处理图像序列

css - 奇怪的 Safari 跨浏览器间距问题

css - 显示伪元素但不显示父元素

css - 如何在 Bootstrap 中定位 img 元素