怎么创建一个react native工程

2026年09月28日 09:42
有1个网友回答
网友(1):

  添加一个ListView
  React Native 有一个叫做 ListView 的组件,可以显示滚动的行数据,基本上是 ios 项目上的一个术语表视图。首先,按照所显示的修改解构的声明以包含多个组件,然后就可以使用。
  var {
Image,
StyleSheet,
Text,
View,
Component,
ListView,
TouchableHighlight
} = React;

  添加以下风格样式表:
  separator: {
height: 1,
backgroundColor: '#dddddd'
}

  添加以下BookList类构造函数:
  constructor(props) {
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2
})
};
}

  然后添加以下功能:
  componentDidMount() {
var books = FAKE_BOOK_DATA;
this.setState({
dataSource: this.state.dataSource.cloneWithRows(books)
});
}