react-native-navigation的迁移库

FlatListScreen.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. const React = require('react');
  2. const { Component } = require('react');
  3. const { SafeAreaView, FlatList, View, Text } = require('react-native');
  4. const { Navigation } = require('react-native-navigation');
  5. const testIDs = require('../testIDs');
  6. const FakeListData = require('../assets/FakeListData');
  7. class FlatListScreen extends Component {
  8. static options(passProps) {
  9. return {
  10. topBar: {
  11. title: {
  12. text: 'FlatList with fake data',
  13. },
  14. searchBar: true, // iOS 11+ native UISearchBar inside topBar
  15. searchBarHiddenWhenScrolling: true,
  16. searchBarPlaceholder: 'Search', // iOS 11+ SearchBar placeholder
  17. largeTitle: {
  18. visible: true,
  19. fontSize: 30,
  20. color: 'white',
  21. fontFamily: 'Helvetica',
  22. },
  23. leftButtons: [
  24. {
  25. id: 'sideMenu',
  26. color: 'red',
  27. icon: require('../images/two.png'),
  28. }
  29. ],
  30. rightButtons: [
  31. {
  32. id: 'toggle',
  33. color: 'red',
  34. icon: require('../images/one.png'),
  35. },
  36. ],
  37. },
  38. };
  39. }
  40. constructor(props) {
  41. super(props);
  42. Navigation.events().bindComponent(this);
  43. this.state = { isFetching: false, shouldHideOnScroll: false };
  44. }
  45. navigationButtonPressed({ buttonId }) {
  46. switch (buttonId) {
  47. case 'sideMenu':
  48. Navigation.mergeOptions(this.props.componentId, {
  49. sideMenu: {
  50. left: {
  51. visible: true,
  52. },
  53. },
  54. });
  55. break;
  56. case 'toggle':
  57. const { shouldHideOnScroll } = this.state;
  58. Navigation.mergeOptions(this.props.componentId, {
  59. topBar: {
  60. hideOnScroll: !shouldHideOnScroll,
  61. drawBehind: !shouldHideOnScroll,
  62. }
  63. });
  64. this.setState({
  65. shouldHideOnScroll: !shouldHideOnScroll
  66. });
  67. alert(`hideOnScroll/drawBehind is now ${!shouldHideOnScroll}`);
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. onRefresh = () => {
  74. this.setState({ isFetching: true }, () => {
  75. setTimeout(() => {
  76. this.setState({ isFetching: false });
  77. }, 2000);
  78. });
  79. }
  80. seperatorComponent = () => <View style={styles.seperatorComponent} />;
  81. keyExtractor = item => item.id;
  82. renderItem = ({ item }) => (
  83. <View style={styles.listItem}>
  84. <Text>{item.first_name} {item.last_name}</Text>
  85. <Text>{item.email}</Text>
  86. </View>
  87. )
  88. render() {
  89. return (
  90. <SafeAreaView style={styles.root}>
  91. <FlatList
  92. data={FakeListData.data}
  93. keyExtractor={this.keyExtractor}
  94. onRefresh={this.onRefresh}
  95. ItemSeparatorComponent={this.seperatorComponent}
  96. refreshing={this.state.isFetching}
  97. renderItem={this.renderItem}
  98. />
  99. </SafeAreaView>
  100. );
  101. }
  102. }
  103. module.exports = FlatListScreen;
  104. const styles = {
  105. root: {
  106. flex: 1,
  107. backgroundColor: 'whitesmoke'
  108. },
  109. listItem: {
  110. height: 50,
  111. },
  112. seperatorComponent: {
  113. height: 5,
  114. backgroundColor: 'black',
  115. }
  116. };