Browse Source

set left button

Guy Carmeli 8 years ago
parent
commit
d9b470312a
1 changed files with 17 additions and 1 deletions
  1. 17
    1
      example-redux/src/screens/PushedScreen.js

+ 17
- 1
example-redux/src/screens/PushedScreen.js View File

10
 import {connect} from 'react-redux';
10
 import {connect} from 'react-redux';
11
 import * as counterActions from '../reducers/counter/actions';
11
 import * as counterActions from '../reducers/counter/actions';
12
 
12
 
13
+const leftButtons = ['back', 'cancel', 'accept', 'sideMenu'];
14
+
13
 // this is a traditional React component connected to the redux store
15
 // this is a traditional React component connected to the redux store
14
 class PushedScreen extends Component {
16
 class PushedScreen extends Component {
15
   static navigatorStyle = {
17
   static navigatorStyle = {
33
     super(props);
35
     super(props);
34
     this.bgColor = this.getRandomColor();
36
     this.bgColor = this.getRandomColor();
35
     console.log(`constructor ${this.bgColor}`);
37
     console.log(`constructor ${this.bgColor}`);
38
+    this.currentBackButton = 0;
36
   }
39
   }
37
 
40
 
38
   componentWillUnmount() {
41
   componentWillUnmount() {
76
           <Text style={styles.button}>Dismiss modal</Text>
79
           <Text style={styles.button}>Dismiss modal</Text>
77
         </TouchableOpacity>
80
         </TouchableOpacity>
78
 
81
 
79
-
80
         <TouchableOpacity onPress={ this.onDismissAllModalsPress.bind(this) }>
82
         <TouchableOpacity onPress={ this.onDismissAllModalsPress.bind(this) }>
81
           <Text style={styles.button}>Dismiss all modals</Text>
83
           <Text style={styles.button}>Dismiss all modals</Text>
82
         </TouchableOpacity>
84
         </TouchableOpacity>
89
           <Text style={styles.button}>New Stack</Text>
91
           <Text style={styles.button}>New Stack</Text>
90
         </TouchableOpacity>
92
         </TouchableOpacity>
91
 
93
 
94
+        <TouchableOpacity onPress={ this.onChangeLeftButtonPress.bind(this) }>
95
+          <Text style={styles.button}>Change Left Button</Text>
96
+        </TouchableOpacity>
97
+
92
         <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}/>
98
         <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}/>
93
 
99
 
94
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
100
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
176
       }
182
       }
177
     });
183
     });
178
   }
184
   }
185
+
186
+  onChangeLeftButtonPress() {
187
+    this.props.navigator.setButtons({
188
+      leftButton: {
189
+        id: leftButtons[this.currentBackButton]
190
+      }
191
+    });
192
+    this.currentBackButton += 1;
193
+    this.currentBackButton = this.currentBackButton % 4;
194
+  }
179
 }
195
 }
180
 
196
 
181
 const styles = StyleSheet.create({
197
 const styles = StyleSheet.create({