Authored by 于良

react native 版本升级 0.30.0 review by 盖剑秋

@@ -17,7 +17,7 @@ const Platform = require('Platform'); @@ -17,7 +17,7 @@ const Platform = require('Platform');
17 const PointPropType = require('PointPropType'); 17 const PointPropType = require('PointPropType');
18 const RCTScrollViewManager = require('NativeModules').ScrollViewManager; 18 const RCTScrollViewManager = require('NativeModules').ScrollViewManager;
19 const React = require('React'); 19 const React = require('React');
20 -const ReactNative = require('ReactNative'); 20 +const ReactNative = require('react/lib/ReactNative');
21 const ScrollResponder = require('ScrollResponder'); 21 const ScrollResponder = require('ScrollResponder');
22 const StyleSheet = require('StyleSheet'); 22 const StyleSheet = require('StyleSheet');
23 const StyleSheetPropType = require('StyleSheetPropType'); 23 const StyleSheetPropType = require('StyleSheetPropType');
@@ -489,7 +489,6 @@ const ScrollView = React.createClass({ @@ -489,7 +489,6 @@ const ScrollView = React.createClass({
489 !this.props.horizontal; 489 !this.props.horizontal;
490 490
491 const baseStyle = this.props.horizontal ? styles.baseHorizontal : styles.baseVertical; 491 const baseStyle = this.props.horizontal ? styles.baseHorizontal : styles.baseVertical;
492 -  
493 const props = { 492 const props = {
494 ...this.props, 493 ...this.props,
495 alwaysBounceHorizontal, 494 alwaysBounceHorizontal,
@@ -568,6 +567,7 @@ const ScrollView = React.createClass({ @@ -568,6 +567,7 @@ const ScrollView = React.createClass({
568 const styles = StyleSheet.create({ 567 const styles = StyleSheet.create({
569 baseVertical: { 568 baseVertical: {
570 flex: 1, 569 flex: 1,
  570 + flexDirection: 'column',
571 }, 571 },
572 baseHorizontal: { 572 baseHorizontal: {
573 flex: 1, 573 flex: 1,
@@ -195,27 +195,6 @@ class NavBar extends React.Component { @@ -195,27 +195,6 @@ class NavBar extends React.Component {
195 this.renderTitle = this.renderTitle.bind(this); 195 this.renderTitle = this.renderTitle.bind(this);
196 } 196 }
197 197
198 - componentDidMount() {  
199 - if (Platform.OS === 'android') {  
200 - BackAndroid.addEventListener('hardwareBackPress', this.onBackAndroid);  
201 - }  
202 - }  
203 -  
204 - componentWillUnmount() {  
205 - if (Platform.OS === 'android') {  
206 - BackAndroid.removeEventListener('hardwareBackPress', this.onBackAndroid);  
207 - }  
208 - }  
209 -  
210 - onBackAndroid = () => {  
211 - let sceneKey = this.props.navigationState.sceneKey;  
212 - if (CONFIG.sceneKey.root === sceneKey) {  
213 - Actions.pop();  
214 - return true;  
215 - }  
216 - return false;  
217 - }  
218 -  
219 renderBackButton() { 198 renderBackButton() {
220 const state = this.props.navigationState; 199 const state = this.props.navigationState;
221 const childState = state.children[state.index]; 200 const childState = state.children[state.index];
1 'use strict'; 1 'use strict';
2 2
  3 +
  4 +/******************************
  5 +*
  6 +* 注意每次更新 react-native-router-flux 版本,
  7 +* 都要检查此方法是否需要更新!!!!!!!!!
  8 +*
  9 +*******************************/
3 export function shouldShowTabBar(navigationState) { 10 export function shouldShowTabBar(navigationState) {
4 - let key = navigationState.key;  
5 - let index = key.substring(0, 1);  
6 - return index == 1; 11 + let index = getSceneIndex(navigationState);
  12 + return index == 1; // 只有从home的下一个scene返回至home时才需要显示tab bar
7 } 13 }
8 14
9 export function shouldHideTabBar(navigationState) { 15 export function shouldHideTabBar(navigationState) {
10 - let key = navigationState.key;  
11 - let index = key.substring(0, 1);  
12 - return index != 0; 16 + let index = getSceneIndex(navigationState);
  17 + return index !== 0; // 非home的scene都需要隐藏tab bar
  18 +}
  19 +
  20 +function getSceneIndex(navigationState) {
  21 + let {initial, key, parent, name, clone} = navigationState;
  22 + let index = 0;
  23 + if (initial) {
  24 + // 如果是initial是ture的scene,则key的格式是`${position}_${name}`
  25 + // 0_Home
  26 + index = key.substring(0, 1);
  27 + } else {
  28 + // 如果是initial是false
  29 + // 如果clone是true,则key的格式是`${parent}_${name}_${position}_${name}`
  30 + // root_Section_10_Section
  31 + // 如果clone是false,则key的格式是`${name}_${position}_${name}`
  32 + // Posting_11_Posting
  33 + let prefix = clone ? `${parent}_${name}_` : `${name}_`;
  34 + let start = prefix.length;
  35 + let stop = key.lastIndexOf('_');
  36 + index = key.substring(start, stop);
  37 + }
  38 +
  39 + console.log(key);
  40 + console.log(index);
  41 +
  42 + return index;
13 } 43 }
@@ -13,18 +13,17 @@ @@ -13,18 +13,17 @@
13 "moment": "^2.13.0", 13 "moment": "^2.13.0",
14 "object-assign": "^4.1.0", 14 "object-assign": "^4.1.0",
15 "query-string": "^4.2.2", 15 "query-string": "^4.2.2",
16 - "react": "15.1.0", 16 + "react": "^15.2.1",
17 "react-immutable-proptypes": "^1.7.1", 17 "react-immutable-proptypes": "^1.7.1",
18 - "react-native": "^0.28.0", 18 + "react-native": "^0.30.0",
19 "react-native-device-info": "^0.9.3", 19 "react-native-device-info": "^0.9.3",
20 - "react-native-fabric": "^0.2.2",  
21 - "react-native-progress": "^3.0.1",  
22 "react-native-fabric": "0.2.2", 20 "react-native-fabric": "0.2.2",
23 - "react-native-router-flux": "^3.30.2", 21 + "react-native-progress": "^3.0.1",
  22 + "react-native-router-flux": "^3.32.0",
24 "react-native-scrollable-mixin": "^1.0.1", 23 "react-native-scrollable-mixin": "^1.0.1",
25 - "react-native-scrollable-tab-view": "^0.5.1", 24 + "react-native-scrollable-tab-view": "^0.5.3",
26 "react-native-simple-store": "^1.0.1", 25 "react-native-simple-store": "^1.0.1",
27 - "react-native-swiper": "^1.4.5", 26 + "react-native-swiper": "^1.4.7",
28 "react-redux": "^4.4.5", 27 "react-redux": "^4.4.5",
29 "redux": "^3.5.2", 28 "redux": "^3.5.2",
30 "redux-logger": "^2.6.1", 29 "redux-logger": "^2.6.1",