Authored by 叶弯弯

修复NavBar在Android上的一些兼容问题。reviewed by yuliang。

... ... @@ -35,6 +35,7 @@ import {
TouchableOpacity,
View,
Dimensions,
BackAndroid,
} from 'react-native';
import {Actions} from 'react-native-router-flux';
import _drawerImage from '../images/menu_burger.png';
... ... @@ -50,7 +51,7 @@ const styles = StyleSheet.create({
fontWeight: '500',
color: '#0A0A0A',
position: 'absolute',
top: Platform.OS === 'ios' || Platform.Version > 19 ? 20 : 0,
top: Platform.OS === 'ios' ? 20 : 5,
left: 0,
right: 0,
backgroundColor: 'transparent',
... ... @@ -59,7 +60,7 @@ const styles = StyleSheet.create({
backgroundColor: '#EFEFF2',
paddingTop: 0,
top: 0,
height: Platform.OS === 'ios' || Platform.Version > 19 ? 64 : 44,
height: Platform.OS === 'ios' ? 64 : 50,
right: 0,
left: 0,
borderBottomWidth: 0.5,
... ... @@ -175,6 +176,27 @@ class NavBar extends React.Component {
this.renderTitle = this.renderTitle.bind(this);
}
componentWillMount() {
if (Platform.OS === 'android') {
BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);
}
}
componentWillUnmount() {
if (Platform.OS === 'android') {
BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);
}
}
onBackAndroid = () => {
let sceneKey = this.props.navigationState.sceneKey;
if (CONFIG.sceneKey.root === sceneKey) {
Actions.pop();
return true;
}
return false;
}
renderBackButton() {
const state = this.props.navigationState;
const childState = state.children[state.index];
... ... @@ -407,13 +429,13 @@ class NavBar extends React.Component {
if (selected.hideNavBar) {
return null;
}
while (selected.hasOwnProperty('children')) {
state = selected;
selected = selected.children[selected.index];
}
const renderLeftButton = selected.renderLeftButton ||
selected.component.renderLeftButton ||
... ... @@ -437,10 +459,11 @@ class NavBar extends React.Component {
this.props.navigationBarStyle,
state.navigationBarStyle,
selected.navigationBarStyle,
CONFIG.sceneKey.user === sceneKey && styles.imageMy,
]}
>
<Image
source={CONFIG.sceneKey.user === sceneKey ? require('../images/mybg.png') : require('../images/navbar.png')}
<Image
source={CONFIG.sceneKey.user === sceneKey ? require('../images/mybg.png') : require('../images/navbar.png')}
style={[styles.image, CONFIG.sceneKey.user === sceneKey && styles.imageMy]}
>
{renderTitle ? renderTitle(selected) : state.children.map(this.renderTitle, this)}
... ...