react-navigation / redux-helpers

Redux middleware and utils for React Navigation
Other
296 stars 43 forks source link

this .setState does'nt work in componnent didmount anyone can help me? #102

Closed dennyfloweradvisor closed 5 years ago

dennyfloweradvisor commented 5 years ago

hi all i have a problem with navigation when i move to tab page with this.props.navigation.navigate('CART') variable setState cannnot mutable here my navigation tree :

import React from "react"; import { Platform, StatusBar } from "react-native"; import { StackNavigator, TabNavigator, SwitchNavigator } from "react-navigation"; import { FontAwesome } from "react-native-vector-icons"; import { createStackNavigator,createBottomTabNavigator ,StackActions, createSwitchNavigator,createTabNavigator,NavigationActions,TabBarBottom } from 'react-navigation';

import Ic from 'react-native-vector-icons/FontAwesome'; import Mat from 'react-native-vector-icons/MaterialCommunityIcons';

//import product from '../Category/product.android'; //import SignUp from "./screens/SignUp"; import SignIn from "./Screens/signin";
//import MainHome from './Screens/home' import Home from "./Screens/home"; import product from './Screens/product'
import Category from './Screens/category-filter' //import DetailS from '../SignOut' import Search from './Screens/Search' import Cart from './Screens/cart'; import Cart1 from './Screens/cart1' import Checkout from './Screens/CheckOut' import feat from './Screens/FeatureCategory' import Profile from "./Screens/profile"; import WebV from './Screens/WebV'
import WebPayment from './Screens/WebVpayment' import failed from './Screens/failed' import ThankYou from './Screens/Thankyou' import Payment from './Screens/Payment' import SignOut from './Screens/SignOut'
import Register from './Screens/register' import Recover from './Screens/Recover' //import SignIn from './Screens/signin' const headerStyle = { marginTop: Platform.OS === "android" ? StatusBar.currentHeight : 0 };

/export const SignedOut = createStackNavigator({ SignUp: { screen: SignUp, navigationOptions: { title: "Sign Up", headerStyle } }, SignIn: { screen: SignIn, navigationOptions: { title: "Sign In", headerStyle } } });/

//const HomeStack=

const Profile1 = createStackNavigator({ // DetailS:{screen:DetailS},

// Profile: { screen: DetailS }, Home: { screen: Home }, Category:{screen:Category}, product:{screen:product}, checkout:{screen:Checkout}, //DetailS:{screen:DetailS} }, { headerMode: 'none', navigationOptions: { headerVisible: false, } }

); const SearchStack = createStackNavigator({ // DetailS:{screen:DetailS},

 Search: { screen: Search },
 Category:{screen:Category},
product:{screen:product},
Cart:{screen:Cart},
Cart1:{screen:Cart1},

WebV:{screen:WebV},
Home:{screen:Home},
checkout:{screen:Checkout},
   //DetailS:{screen:DetailS}
 },

 );

 const CartStack = createStackNavigator({
  // DetailS:{screen:DetailS},

    Cart:{screen:Cart},
    Cart1:{screen:Cart1},

    checkout:{screen:Checkout},

     //DetailS:{screen:DetailS}
   },
   {
     headerMode: 'none',
     navigationOptions: {
       headerVisible: false,
     }
    }

   );

const HomeStack = createStackNavigator({

 Home: { screen: Home },
  Category:{screen:Category,},
  product:{screen:product},
  Cart:{screen:Cart},
  Cart1:{screen:Cart1},

  WebV:{screen:WebV},
  feat:{screen:feat},
  checkout:{screen:Checkout},
  Search:{screen:Search},
  Payment:{screen:Payment},
  ThankYou:{screen:ThankYou},    
  failed:{screen:failed},
  WebPayment:{screen:WebPayment},

}, { headerMode: 'none', navigationOptions: { headerVisible: false, } }

);

  HomeStack.navigationOptions = ({ navigation }) => {
    let tabBarVisible=true;
    let routeName = navigation.state.routes[navigation.state.index].routeName

    if ( routeName == 'product' ) {
      tabBarVisible = false
  }

    return {
      tabBarVisible
    };
  };
  const prefix='fa://'
  const MainApp = () => <HomeStack uriPrefix={prefix} />;

  const resetAction = StackActions.reset({
    index: 0,  
    actions: [NavigationActions.navigate({ routeName:'Home'
  })],
  });  

  const resetCart = StackActions.reset({
    index: 0,  
    actions: [NavigationActions.navigate({ routeName:'Cart'
  })],
  });  

  const Tab= createBottomTabNavigator(
{
  Home: { screen: HomeStack, 

  navigationOptions: {      
    tabBarLabel: 'Home',   
    tabBarOnPress:({navigation, defaultHandler}) => {
      navigation.dispatch(resetAction);
      defaultHandler()    
    },   
  }         
  },

// Home:{screen:Home},
 Search: { screen: Search},

 Cart:{screen:CartStack, 

  navigationOptions: {      
    tabBarLabel: 'Cart',   
    tabBarOnPress:({navigation, defaultHandler}) => {
      navigation.dispatch(resetCart);
      defaultHandler()    
    }, } 
   },
 Profile:{screen:Profile

}   

},

{
  navigationOptions: ({ navigation }) => ({
   // navigationOptions: ({ navigation }) => ({

    tabBarIcon: ({ focused, tintColor }) => {
      const { routeName } = navigation.state;
      let iconName;
      if (routeName === 'Search') {
        iconName = `search${focused ? '' : ''}`;
      }  if (routeName === 'Home') {
        iconName = `home${focused ? '' : ''}`;
      }
      if (routeName === 'Cart') {
        iconName = `shopping-cart${focused ? '' : ''}`;
      }
      if(routeName==='Profile')
      {
        iconName = `user-circle${focused ? '' : ''}`;

       // return (<Mat name={iconName} size={25} color={tintColor} />)

      }

      return (<Ic name={iconName} size={25} color={tintColor} />
        )

    },

  }),

  tabBarOptions: {
    activeTintColor: 'black',
    inactiveTintColor: 'grey',
   // showLabel: false 
  },
 // lazy:false,
}

); const GeneralStack = createStackNavigator({ Tab: { screen: Tab}, product:{screen:product} , Cart:{screen:Cart}, register:{screen:Register}, recover:{screen:Recover} ,
SignIn:{screen:SignIn} }, { headerMode: 'none', navigationOptions: { headerVisible: false, } }, { initialRouteName: Tab }

);

const SignStack = createStackNavigator({ SignIn:{screen:SignIn},

register:{screen:Register}, recover:{screen:Recover} ,
}, { headerMode: 'none', navigationOptions: { headerVisible: false, } }, { initialRouteName: SignIn }

);

export const createRootNavigator = (signedIn ) => { return createSwitchNavigator( { Tab: { screen: GeneralStack }, SignedIn: { screen: SignStack } }, { initialRouteName: signedIn ? "Tab" : "SignedIn" } ); };

software version 1.0.0

react-navigation : ^2.18.0

react-native": "0.60.5 node v: 8.11.3 npm : 6.4.0

Ashoat commented 5 years ago

This package is probably unrelated to your issue. I can investigate this issue further if you can provide an MCVE that reproduces the issue, in the form of an Expo Snack or a react-native init'd repo hosted on GitHub.

dennyfloweradvisor commented 5 years ago

okeey so i must upload my project file to an expor bro?

dennyfloweradvisor commented 5 years ago

or linked @Ashoat github file repo?