瀏覽代碼

Add toggleDrawer to FirstTabScreen

Guy Carmeli 8 年之前
父節點
當前提交
323c7b9367
共有 1 個檔案被更改,包括 21 行新增32 行删除
  1. 21
    32
      example-redux/src/screens/FirstTabScreen.js

+ 21
- 32
example-redux/src/screens/FirstTabScreen.js 查看文件

58
           Alert.alert('NavBar', 'Add button pressed');
58
           Alert.alert('NavBar', 'Add button pressed');
59
           break;
59
           break;
60
 
60
 
61
-        case 'selectedTabChanged':
62
-          this.onTabSelected(event.position);
61
+        case 'tabSelected':
62
+          this.onTabSelected();
63
           break;
63
           break;
64
 
64
 
65
         default:
65
         default:
95
         }
95
         }
96
       });
96
       });
97
     }
97
     }
98
-    return;
99
   }
98
   }
100
 
99
 
101
-  onTabSelected(position) {
102
-    console.log('selectedTabChanged ' + position);
103
-    let rightButtons;
104
-
105
-    switch (position) {
106
-      case 0:
107
-        rightButtons = [
108
-          {
109
-            id: 'account',
110
-            icon: require('../../img/ic_account_box_.png')
111
-          }
112
-        ];
113
-        break;
114
-
115
-      case 1:
116
-        rightButtons = [
117
-          {
118
-            id: 'account',
119
-            icon: require('../../img/ic_add_alert.png')
120
-          }
121
-        ];
122
-        break;
123
-
124
-      default:
125
-        rightButtons = [];
126
-        break;
127
-    }
128
-
129
-    this.props.navigator.setButtons({rightButtons});
100
+  onTabSelected() {
101
+    console.log('selectedTabChanged');
102
+    this.props.navigator.setButtons({rightButtons: [
103
+      {
104
+        id: 'account',
105
+        icon: require('../../img/ic_account_box_.png')
106
+      }
107
+    ]});
130
   }
108
   }
131
 
109
 
132
   render() {
110
   render() {
165
           <Text style={styles.button}>Set Two Buttons</Text>
143
           <Text style={styles.button}>Set Two Buttons</Text>
166
         </TouchableOpacity>
144
         </TouchableOpacity>
167
 
145
 
146
+        <TouchableOpacity onPress={ this.onToggleDrawerPress.bind(this) }>
147
+          <Text style={styles.button}>Toggle Drawer</Text>
148
+        </TouchableOpacity>
149
+
168
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
150
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
169
         <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
151
         <Text style={{fontWeight: '500'}}>Function prop: {this.props.fn ? this.props.fn() : ''}</Text>
170
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
152
         {this.props.obj ? <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text> : false}
259
       ]
241
       ]
260
     })
242
     })
261
   }
243
   }
244
+
245
+  onToggleDrawerPress() {
246
+    this.props.navigator.toggleDrawer({
247
+      side: 'left',
248
+      animated: true
249
+    })
250
+  }
262
 }
251
 }
263
 
252
 
264
 const styles = StyleSheet.create({
253
 const styles = StyleSheet.create({