|
| 1 | +import React, { useEffect } from 'react'; |
| 2 | +import { View } from 'react-native'; |
| 3 | +import { |
| 4 | + createAppContainer, |
| 5 | + createStackNavigator, |
| 6 | + SafeAreaView, |
| 7 | +} from 'react-navigation'; |
| 8 | +import { useDispatch, useSelector } from 'react-redux'; |
| 9 | +import Loading from '~/components/Loading'; |
| 10 | +import { startup } from '../../redux/actions/startupActions'; |
| 11 | +import NavigationService from '../../services/NavigationService'; |
| 12 | +import Colors from '../../Theme/Colors'; |
| 13 | +import MainScreen from '~/containers/Main'; |
| 14 | +import SplashScreen from '../SplashScreen/SplashScreen'; |
| 15 | + |
| 16 | +/** |
| 17 | + * a root screen contem a navegacao do app |
| 18 | + * |
| 19 | + * @see https://reactnavigation.org/docs/en/hello-react-navigation.html#creating-a-stack-navigator |
| 20 | + */ |
| 21 | + |
| 22 | +// configuracao da Stack de navegacao |
| 23 | +// aplicas-se a todas as rotas |
| 24 | +const configureStack = { |
| 25 | + // Splash screen é exibida por default durante a execucao do startup() saga |
| 26 | + // ver definicao no arquivo StartupSaga.js |
| 27 | + initialRouteName: 'SplashScreen', |
| 28 | + // remove header de todas as telas |
| 29 | + // https://reactnavigation.org/docs/en/stack-navigator.html#stacknavigatorconfig |
| 30 | + headerMode: 'none', |
| 31 | + navigationOptions: { |
| 32 | + translucent: 'true', |
| 33 | + headerStyle: { |
| 34 | + backgroundColor: Colors.defaultBackground, |
| 35 | + elevation: 0, |
| 36 | + paddingTop: 40, |
| 37 | + }, |
| 38 | + headerTitleStyle: { |
| 39 | + textAlign: 'center', |
| 40 | + fontFamily: 'Geomanist-Medium', |
| 41 | + alignSelf: 'center', |
| 42 | + }, |
| 43 | + headerTintColor: Colors.headerTintColor, |
| 44 | + }, |
| 45 | +}; |
| 46 | + |
| 47 | +/** |
| 48 | + * Root navigation |
| 49 | + */ |
| 50 | +const RootNavigator = createStackNavigator( |
| 51 | + { |
| 52 | + SplashScreen, |
| 53 | + MainScreen, |
| 54 | + }, |
| 55 | + configureStack, |
| 56 | +); |
| 57 | + |
| 58 | +/** |
| 59 | + * Configure App Container - for react-navigation 3+ |
| 60 | + */ |
| 61 | +const AppContainer = createAppContainer(RootNavigator); |
| 62 | + |
| 63 | +/** |
| 64 | + * Define main RootScreen component |
| 65 | + */ |
| 66 | +const RootScreen = () => { |
| 67 | + const { loading } = useSelector(state => state.api); |
| 68 | + const dispatch = useDispatch(); |
| 69 | + |
| 70 | + useEffect(() => { |
| 71 | + // Executa startup saga quando aplicacao inicia |
| 72 | + dispatch(startup()); |
| 73 | + }, []); |
| 74 | + |
| 75 | + return ( |
| 76 | + <SafeAreaView |
| 77 | + style={{ flex: 1, backgroundColor: Colors.defaultBackground }} |
| 78 | + > |
| 79 | + <View style={{ flex: 1 }}> |
| 80 | + <Loading visible={loading} animation="fade" /> |
| 81 | + <AppContainer |
| 82 | + // Utilizando NavigationService para permitir navegar de onde navigation props nao for acessível |
| 83 | + // Permite navegar direto de um Saga, por exemplo |
| 84 | + // NavigationService (https://reactnavigation.org/docs/en/navigating-without-navigation-prop.html) |
| 85 | + ref={(navigatorRef) => { |
| 86 | + NavigationService.setTopLevelNavigator(navigatorRef); |
| 87 | + }} |
| 88 | + /> |
| 89 | + </View> |
| 90 | + </SafeAreaView> |
| 91 | + ); |
| 92 | +}; |
| 93 | + |
| 94 | +export default RootScreen; |
0 commit comments