修复NavBar在Android上的一些兼容问题。reviewed by yuliang。
Showing
1 changed file
with
25 additions
and
2 deletions
@@ -35,6 +35,7 @@ import { | @@ -35,6 +35,7 @@ import { | ||
35 | TouchableOpacity, | 35 | TouchableOpacity, |
36 | View, | 36 | View, |
37 | Dimensions, | 37 | Dimensions, |
38 | + BackAndroid, | ||
38 | } from 'react-native'; | 39 | } from 'react-native'; |
39 | import {Actions} from 'react-native-router-flux'; | 40 | import {Actions} from 'react-native-router-flux'; |
40 | import _drawerImage from '../images/menu_burger.png'; | 41 | import _drawerImage from '../images/menu_burger.png'; |
@@ -50,7 +51,7 @@ const styles = StyleSheet.create({ | @@ -50,7 +51,7 @@ const styles = StyleSheet.create({ | ||
50 | fontWeight: '500', | 51 | fontWeight: '500', |
51 | color: '#0A0A0A', | 52 | color: '#0A0A0A', |
52 | position: 'absolute', | 53 | position: 'absolute', |
53 | - top: Platform.OS === 'ios' || Platform.Version > 19 ? 20 : 0, | 54 | + top: Platform.OS === 'ios' ? 20 : 5, |
54 | left: 0, | 55 | left: 0, |
55 | right: 0, | 56 | right: 0, |
56 | backgroundColor: 'transparent', | 57 | backgroundColor: 'transparent', |
@@ -59,7 +60,7 @@ const styles = StyleSheet.create({ | @@ -59,7 +60,7 @@ const styles = StyleSheet.create({ | ||
59 | backgroundColor: '#EFEFF2', | 60 | backgroundColor: '#EFEFF2', |
60 | paddingTop: 0, | 61 | paddingTop: 0, |
61 | top: 0, | 62 | top: 0, |
62 | - height: Platform.OS === 'ios' || Platform.Version > 19 ? 64 : 44, | 63 | + height: Platform.OS === 'ios' ? 64 : 50, |
63 | right: 0, | 64 | right: 0, |
64 | left: 0, | 65 | left: 0, |
65 | borderBottomWidth: 0.5, | 66 | borderBottomWidth: 0.5, |
@@ -175,6 +176,27 @@ class NavBar extends React.Component { | @@ -175,6 +176,27 @@ class NavBar extends React.Component { | ||
175 | this.renderTitle = this.renderTitle.bind(this); | 176 | this.renderTitle = this.renderTitle.bind(this); |
176 | } | 177 | } |
177 | 178 | ||
179 | + componentWillMount() { | ||
180 | + if (Platform.OS === 'android') { | ||
181 | + BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid); | ||
182 | + } | ||
183 | + } | ||
184 | + | ||
185 | + componentWillUnmount() { | ||
186 | + if (Platform.OS === 'android') { | ||
187 | + BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid); | ||
188 | + } | ||
189 | + } | ||
190 | + | ||
191 | + onBackAndroid = () => { | ||
192 | + let sceneKey = this.props.navigationState.sceneKey; | ||
193 | + if (CONFIG.sceneKey.root === sceneKey) { | ||
194 | + Actions.pop(); | ||
195 | + return true; | ||
196 | + } | ||
197 | + return false; | ||
198 | + } | ||
199 | + | ||
178 | renderBackButton() { | 200 | renderBackButton() { |
179 | const state = this.props.navigationState; | 201 | const state = this.props.navigationState; |
180 | const childState = state.children[state.index]; | 202 | const childState = state.children[state.index]; |
@@ -437,6 +459,7 @@ class NavBar extends React.Component { | @@ -437,6 +459,7 @@ class NavBar extends React.Component { | ||
437 | this.props.navigationBarStyle, | 459 | this.props.navigationBarStyle, |
438 | state.navigationBarStyle, | 460 | state.navigationBarStyle, |
439 | selected.navigationBarStyle, | 461 | selected.navigationBarStyle, |
462 | + CONFIG.sceneKey.user === sceneKey && styles.imageMy, | ||
440 | ]} | 463 | ]} |
441 | > | 464 | > |
442 | <Image | 465 | <Image |
-
Please register or login to post a comment