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,6 +58,7 @@ class FirstTabScreen extends Component {
58 58
         break;
59 59
     }
60 60
   }
61
+
61 62
   render() {
62 63
     return (
63 64
       <View style={{flex: 1, padding: 20}}>

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

@@ -21,7 +21,6 @@ class LoginScreen extends Component {
21 21
 
22 22
   constructor(props) {
23 23
     super(props);
24
-    console.log(props);
25 24
   }
26 25
 
27 26
   render() {

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

@@ -23,6 +23,7 @@ class SecondTabScreen extends Component {
23 23
     super(props);
24 24
     this.buttonsCounter = 0;
25 25
   }
26
+
26 27
   render() {
27 28
     return (
28 29
       <ScrollView style={{flex: 1}}>
@@ -44,14 +45,50 @@ class SecondTabScreen extends Component {
44 45
           <Text style={{fontWeight: '500'}}>Object prop: {this.props.obj.str}</Text>
45 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 52
         </View>
48 53
 
49 54
       </ScrollView>
50 55
     );
51 56
   }
57
+
52 58
   onIncrementPress() {
53 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 94
 const styles = StyleSheet.create({