From 5373c6b787bfe2578ad506a94b951851f7fb989a Mon Sep 17 00:00:00 2001 From: parkerdan Date: Sat, 4 Feb 2017 20:12:12 -0600 Subject: [PATCH] push test --- app/tabBar/reducer.js | 15 +++----- app/tabBar/views/TabBarNavigation.js | 45 +++++++++++++++--------- app/tabOne/views/TabOneNavigation.js | 4 +-- app/tabOne/views/TabOneScreenOne.js | 10 +++++- app/tabThree/reducer.js | 10 ++++++ app/tabThree/views/TabThreeNavigation.js | 4 +-- app/tabThree/views/TabThreeScreenOne.js | 29 ++++++++++++++- app/tabTwo/views/TabTwoNavigation.js | 4 +-- package.json | 2 +- 9 files changed, 87 insertions(+), 36 deletions(-) diff --git a/app/tabBar/reducer.js b/app/tabBar/reducer.js index 6d330d5..a66766e 100644 --- a/app/tabBar/reducer.js +++ b/app/tabBar/reducer.js @@ -5,11 +5,11 @@ import findRouteIndexByName from '../helperFunctions/findRouteIndexByName' const defaultState = { index:0, - routes: routeStack + routes: routeStack, } const reducer = (state=defaultState,action) => { switch (action.type) { - case 'Navigate': + case 'Navigation/NAVIGATE': var index = findRouteIndexByName(routeStack,action.routeName) if ( index !== -1 ) { return { ...state, index: index } @@ -18,14 +18,9 @@ const reducer = (state=defaultState,action) => { } break; - case 'Back': - if (action.key === 'TabBarBack') { - var currentIndex = state.index - return { ...state, index: currentIndex - 1 } - } else { - return state - } - + case 'Navigation/BACK': + var currentIndex = state.index + return { ...state, index: currentIndex - 1 } break; } return state diff --git a/app/tabBar/views/TabBarNavigation.js b/app/tabBar/views/TabBarNavigation.js index 8cf0bf4..2ceaac2 100644 --- a/app/tabBar/views/TabBarNavigation.js +++ b/app/tabBar/views/TabBarNavigation.js @@ -1,7 +1,7 @@ 'use strict' // React import React from 'react' -import { BackAndroid } from 'react-native' +import { BackAndroid, View } from 'react-native' // Navigation import { TabNavigator, addNavigationHelpers } from 'react-navigation' import { routeConfiguration, tabBarConfiguration } from '../navigationConfiguration' @@ -10,7 +10,10 @@ import { connect } from 'react-redux' const TabBar = TabNavigator(routeConfiguration,tabBarConfiguration) const mapStateToProps = (state) => { return { - navigationState: state.tabBar + navigationState: state.tabBar, + // tabOneIndex: state.tabOne.index, + // tabTwoIndex: state.tabTwo.index, + // tabThreeIndex: state.tabThree.index, } } const mapDispatchToProps = (dispatch) => { @@ -27,26 +30,34 @@ class TabBarNavigation extends React.Component { } handleBackAction = () => { - if (this.props.navigationState.index === 0) { - return false - } else { - this.navigator.props.navigation.goBack('TabBarBack') - return true - } + // const { navigationState: {index: tabIndex}, tabOneIndex, tabTwoIndex, tabThreeIndex } = this.props + // + // const tabIndexArray = [ tabOneIndex, tabTwoIndex, tabThreeIndex ] + // + // if ( tabIndex === 0 && tabIndexArray[tabIndex] === 0) { + // return false + // } else if ( tabIndexArray[tabIndex] === 0 ) { + // this.navigator.props.navigation.goBack() + // return true + // } else { + // return true + // } } render(){ const { dispatch, navigationState } = this.props return ( - this.navigator = ref } - navigation={ - addNavigationHelpers({ - dispatch: dispatch, - state: navigationState, - }) - } - /> + + this.navigator = ref } + navigation={ + addNavigationHelpers({ + dispatch: dispatch, + state: navigationState, + }) + } + /> + ) } } diff --git a/app/tabOne/views/TabOneNavigation.js b/app/tabOne/views/TabOneNavigation.js index af523a3..38e7f1a 100644 --- a/app/tabOne/views/TabOneNavigation.js +++ b/app/tabOne/views/TabOneNavigation.js @@ -13,7 +13,7 @@ import { connect } from 'react-redux' // Icon import Icon from 'react-native-vector-icons/FontAwesome' -const Navigator = StackNavigator(routeConfiguration,stackNavigatorConfiguration) +const NavigatorTabOne = StackNavigator(routeConfiguration,stackNavigatorConfiguration) const mapStateToProps = (state) => { return { @@ -36,7 +36,7 @@ class TabOneNavigation extends React.Component { render(){ const { dispatch, navigationState} = this.props return ( - + console.log('pressed!') } + style={{ + padding:20, + backgroundColor:'yellow' + }}> + { 'Hi' } + { 'Tab One Screen One' } ) diff --git a/app/tabThree/reducer.js b/app/tabThree/reducer.js index 3d16d32..867cd1b 100644 --- a/app/tabThree/reducer.js +++ b/app/tabThree/reducer.js @@ -1,5 +1,6 @@ 'use strict' import { routeStack } from './navigationConfiguration' +import findRouteIndexByName from '../helperFunctions/findRouteIndexByName' const defaultState = { index: 0, previousIndex:0, @@ -7,6 +8,15 @@ const defaultState = { } const reducer = (state=defaultState,action) => { switch (action.type) { + case 'Navigation/NAVIGATE': + var newIndex = findRouteIndexByName(routeStack,action.routeName) + if ( newIndex !== -1 ) { + var previousIndex = state.index + return { ...state, index: newIndex, previousIndex: previousIndex } + } else { + return state + } + break; } return state } diff --git a/app/tabThree/views/TabThreeNavigation.js b/app/tabThree/views/TabThreeNavigation.js index d6f2edd..a3a9dde 100644 --- a/app/tabThree/views/TabThreeNavigation.js +++ b/app/tabThree/views/TabThreeNavigation.js @@ -6,7 +6,7 @@ import { StackNavigator, addNavigationHelpers } from 'react-navigation' import { routeConfiguration, stackNavigatorConfiguration } from '../navigationConfiguration' //Redux import { connect } from 'react-redux' -const Navigator = StackNavigator(routeConfiguration,stackNavigatorConfiguration) +const NavigatorTabThree = StackNavigator(routeConfiguration,stackNavigatorConfiguration) const mapStateToProps = (state) => { return { navigationState: state.tabThree @@ -19,7 +19,7 @@ class TabThreeNavigation extends React.Component { render(){ const { dispatch, navigationState} = this.props return ( - + console.log('hi') } + style={{ + padding:30, + backgroundColor:'deeppink' + }}> + + {'TouchableHighlight'} + + + + { + console.log('hi, new screen please') + // this.props.navigation.navigate('TabThreeScreenTwo') + } + } + style={{ + padding:20, + backgroundColor:'red', + borderRadius:20, + marginBottom:50, + zIndex:99 + }}> + {' Go to Screen Two '} + { 'Tab Three Screen One' } ) diff --git a/app/tabTwo/views/TabTwoNavigation.js b/app/tabTwo/views/TabTwoNavigation.js index e7efb2a..12b58ab 100644 --- a/app/tabTwo/views/TabTwoNavigation.js +++ b/app/tabTwo/views/TabTwoNavigation.js @@ -6,7 +6,7 @@ import { StackNavigator, addNavigationHelpers } from 'react-navigation' import { routeConfiguration, stackNavigatorConfiguration } from '../navigationConfiguration' //Redux import { connect } from 'react-redux' -const Navigator = StackNavigator(routeConfiguration,stackNavigatorConfiguration) +const NavigatorTabTwo = StackNavigator(routeConfiguration,stackNavigatorConfiguration) const mapStateToProps = (state) => { return { navigationState: state.tabTwo @@ -19,7 +19,7 @@ class TabTwoNavigation extends React.Component { render(){ const { dispatch, navigationState} = this.props return ( -