Browse Source

Added example for setting buttons

Yedidya Kennard 8 years ago
parent
commit
14428e0652

+ 1
- 0
example-redux/src/screens/FirstTabScreen.js View File

58
         break;
58
         break;
59
     }
59
     }
60
   }
60
   }
61
+
61
   render() {
62
   render() {
62
     return (
63
     return (
63
       <View style={{flex: 1, padding: 20}}>
64
       <View style={{flex: 1, padding: 20}}>

+ 0
- 1
example-redux/src/screens/LoginScreen.js View File

21
 
21
 
22
   constructor(props) {
22
   constructor(props) {
23
     super(props);
23
     super(props);
24
-    console.log(props);
25
   }
24
   }
26
 
25
 
27
   render() {
26
   render() {

+ 37
- 0
example-redux/src/screens/SecondTabScreen.js View File

23
     super(props);
23
     super(props);
24
     this.buttonsCounter = 0;
24
     this.buttonsCounter = 0;
25
   }
25
   }
26
+
26
   render() {
27
   render() {
27
     return (
28
     return (
28
       <ScrollView style={{flex: 1}}>
29
       <ScrollView style={{flex: 1}}>
44
           <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
45
           <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
45
           <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text>
46
           <Text style={{fontWeight: '500'}}>Array prop: {this.props.obj.arr[0].str}</Text>
46
 
47
 
48
+          <TouchableOpacity onPress={ this.onSetButton.bind(this) }>
49
+            <Text style={styles.button}>Set a button</Text>
50
+          </TouchableOpacity>
51
+
47
         </View>
52
         </View>
48
 
53
 
49
       </ScrollView>
54
       </ScrollView>
50
     );
55
     );
51
   }
56
   }
57
+
52
   onIncrementPress() {
58
   onIncrementPress() {
53
     this.props.dispatch(counterActions.increment());
59
     this.props.dispatch(counterActions.increment());
54
   }
60
   }
61
+
62
+  onSetButton() {
63
+    this.props.navigator.setButtons({
64
+      rightButtons: [
65
+        {
66
+          title: 'Right',
67
+          icon: require('../../img/navicon_add.png'),
68
+          id: 'right'
69
+        }
70
+      ],
71
+      leftButtons: [
72
+        {
73
+          title: 'Left',
74
+          icon: require('../../img/navicon_add.png'),
75
+          id: 'left'
76
+        }
77
+      ]
78
+    });
79
+    this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent.bind(this));
80
+  }
81
+
82
+  onNavigatorEvent(event) {
83
+    switch (event.id) {
84
+      case 'left':
85
+        Alert.alert('NavBar', 'Left button pressed');
86
+        break;
87
+      case 'right':
88
+        Alert.alert('NavBar', 'Right button pressed');
89
+        break;
90
+    }
91
+  }
55
 }
92
 }
56
 
93
 
57
 const styles = StyleSheet.create({
94
 const styles = StyleSheet.create({