Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

react-native: DatePickerIOS 组件无法展示 #8

Open
wutianmei opened this issue Aug 23, 2019 · 0 comments
Open

react-native: DatePickerIOS 组件无法展示 #8

wutianmei opened this issue Aug 23, 2019 · 0 comments

Comments

@wutianmei
Copy link
Contributor

代码

 <View style={styles.container}>
        <DatePickerIOS date={this.state.initDate} onDateChange={this.setDate} />
 </View>

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center",
    backgroundColor: "#F5FCFF"
  },
  welcome: {
    fontSize: 20,
    textAlign: "center",
    margin: 10
  },
  instructions: {
    textAlign: "center",
    color: "#333333",
    marginBottom: 5
  }
})

原因分析

由于没有给DatePickerIOS组件指定宽度,而父组件中 alignItems:center,故而导致DatePickerIOS组件的宽度为0,所以无法展示

解决办法

  • 第一种: 给DatePickerIOS指定宽度如
    <DatePickerIOS style={{ width: Dimensions.get("window").width }} date={this.state.initDate} onDateChange={this.setDate} />

  • 第二种:去掉alignItems:center,因为 alignItems的默认值是stretch (如果项目未设置高度或设为auto,将占满整个容器的高度。)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant