Bladeren bron

Add simple ListScreen to test collapsing bottom tabs functionality

Guy Carmeli 8 jaren geleden
bovenliggende
commit
47ef4ec83a
3 gewijzigde bestanden met toevoegingen van 104 en 1 verwijderingen
  1. 1
    1
      example-redux/package.json
  2. 101
    0
      example-redux/src/screens/ListScreen.js
  3. 2
    0
      example-redux/src/screens/index.js

+ 1
- 1
example-redux/package.json Bestand weergeven

@@ -15,7 +15,7 @@
15 15
     "redux": "^3.0.5",
16 16
     "redux-thunk": "^1.0.3",
17 17
     "seamless-immutable": "^5.0.1",
18
-    "react-native-navigation": "file:../",
18
+    "react-native-navigation": "latest",
19 19
     "babel-preset-react-native-stage-0": "*"
20 20
   }
21 21
 }

+ 101
- 0
example-redux/src/screens/ListScreen.js Bestand weergeven

@@ -0,0 +1,101 @@
1
+import React, {Component, PropTypes} from 'react';
2
+import {
3
+  Text,
4
+  View,
5
+  ScrollView,
6
+  TouchableOpacity,
7
+  StyleSheet,
8
+  ListView,
9
+} from 'react-native';
10
+import {connect} from 'react-redux';
11
+import * as counterActions from '../reducers/counter/actions';
12
+
13
+const LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud modus, putant invidunt reprehendunt ne qui.';
14
+const hashCode = function(str) {
15
+  var hash = 15;
16
+  for (var ii = str.length - 1; ii >= 0; ii--) {
17
+    hash = ((hash << 5) - hash) + str.charCodeAt(ii);
18
+  }
19
+  return hash;
20
+};
21
+
22
+class ListScreen extends Component {
23
+
24
+  static navigatorStyle = {
25
+    statusBarColor: '#7CB342',
26
+    toolBarColor: '#8BC34A',
27
+    navigationBarColor: '#8BC34A'
28
+  };
29
+
30
+  constructor(props) {
31
+    super(props);
32
+
33
+    var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
34
+    this.state = {
35
+      dataSource: ds.cloneWithRows(this._genRows({}))
36
+    }
37
+  }
38
+
39
+  componentWillMount() {
40
+    this._pressData = {};
41
+  }
42
+
43
+  render() {
44
+    return (
45
+      <ListView
46
+        dataSource={this.state.dataSource}
47
+        renderRow={this._renderRow}/>
48
+    );
49
+  }
50
+
51
+  _renderRow(rowData, sectionID, rowID) {
52
+    const rowHash = Math.abs(hashCode(rowData));
53
+    return (
54
+      <View style={styles.row}>
55
+        <Text style={styles.text}>
56
+          {rowData + ' - ' + LOREM_IPSUM.substr(0, rowHash % 301 + 10)}
57
+        </Text>
58
+      </View>
59
+    );
60
+  }
61
+
62
+  _genRows() {
63
+    var dataBlob = [];
64
+    for (var ii = 0; ii < 100; ii++) {
65
+      dataBlob.push('Row ' + ii + ' ');
66
+    }
67
+    return dataBlob;
68
+  }
69
+
70
+  _renderSeparator(sectionID, rowID) {
71
+    return (
72
+      <View
73
+        key={`${sectionID}-${rowID}`}
74
+        style={{
75
+          height: 1,
76
+          backgroundColor: rowID % 2 == 0 ? '#3B5998' : '#CCCCCC'
77
+        }}
78
+      />
79
+    );
80
+  }
81
+}
82
+
83
+export default connect()(ListScreen);
84
+
85
+const styles = StyleSheet.create({
86
+  row: {
87
+    flexDirection: 'row',
88
+    justifyContent: 'center',
89
+    padding: 10,
90
+    backgroundColor: '#F6F6F6'
91
+  },
92
+  thumb: {
93
+    width: 64,
94
+    height: 64
95
+  },
96
+  text: {
97
+    flex: 1
98
+  }
99
+});
100
+
101
+

+ 2
- 0
example-redux/src/screens/index.js Bestand weergeven

@@ -4,6 +4,7 @@ import LoginScreen from './LoginScreen';
4 4
 import FirstTabScreen from './FirstTabScreen';
5 5
 import SecondTabScreen from './SecondTabScreen';
6 6
 import PushedScreen from './PushedScreen';
7
+import ListScreen from './ListScreen';
7 8
 
8 9
 // register all screens of the app (including internal ones)
9 10
 export function registerScreens(store, Provider) {
@@ -11,4 +12,5 @@ export function registerScreens(store, Provider) {
11 12
   Navigation.registerComponent('example.FirstTabScreen', () => FirstTabScreen, store, Provider);
12 13
   Navigation.registerComponent('example.SecondTabScreen', () => SecondTabScreen, store, Provider);
13 14
   Navigation.registerComponent('example.PushedScreen', () => PushedScreen, store, Provider);
15
+  Navigation.registerComponent('example.ListScreen', () => ListScreen, store, Provider);
14 16
 }