width null在react-native中表示什么?

Har*_*uja 9 react-native

我在SO和几个应用程序上遇到了几个问题,我遇到了以下样式配置: -

  container: {
    flex:1,
    width: null,
  },
Run Code Online (Sandbox Code Playgroud)

我想知道width:null这里的用途是什么.有人可以帮忙吗?

Ash*_*k R 8

<Image source={require('./images/MacWallPaper.jpg')} style={styles.container}>

</Image>
Run Code Online (Sandbox Code Playgroud)

如果未指定width: nullheight: null组件提取源图像的​​实际宽度和高度.

container: {
   flex: 1,
   justifyContent: 'center',
   alignItems: 'center',
   backgroundColor: 'rgba(0, 0, 0, 0)',
}
Run Code Online (Sandbox Code Playgroud)

当您明确指定width: null并且height: null组件不会使用图像的实际宽度和高度时.

container: {
   flex: 1,
   justifyContent: 'center',
   alignItems: 'center',
   backgroundColor: 'rgba(0, 0, 0, 0)',
   // remove width and height to override fixed static size
   width: null,
   height: null,
}
Run Code Online (Sandbox Code Playgroud)

观看视频

  • 在TypeScript中,它的类型是未定义的或数字,我们在TS中如何做到这一点? (2认同)