Advertisement
Guest User

Untitled

a guest
Aug 7th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =====================================MainScreen.js=========================
  2. import React from 'react'
  3. import { HeaderButtons, Item } from 'react-navigation-header-buttons'
  4. import { DATA } from '../data'
  5. import { Post } from '../components/Post'
  6. import { AppHeaderIcon } from '../components/AppHeaderIcon'
  7. import { PostList } from '../components/PostList'
  8.  
  9.  
  10. export const MainScreen = ({navigation}) => {
  11.  
  12.   const openPostHandler = (post) => {
  13.     navigation.navigate('Post', {postId: post.id, date: post.date, booked: post.booked})
  14.   }
  15.  
  16.   navigation.setOptions({
  17.     title: 'Мои посты',
  18.     headerRight: () => (
  19.       <HeaderButtons HeaderButtonComponent={AppHeaderIcon}>
  20.         <Item
  21.           title='Take photo'
  22.           iconName='ios-camera'
  23.           onPress={() => navigation.push('Create')}
  24.           />
  25.       </HeaderButtons>
  26.     ),
  27.     headerLeft: () => (
  28.       <HeaderButtons HeaderButtonComponent={AppHeaderIcon}>
  29.         <Item
  30.           title='Toggle Drawer'
  31.           iconName='ios-menu'
  32.           onPress={() => navigation.toggleDrawer()}
  33.           />
  34.       </HeaderButtons>
  35.     )
  36.   })
  37.  
  38.   return(
  39.     <PostList data={DATA} onOpen={openPostHandler} />
  40.   )
  41. }
  42.  
  43. =====================================AppNavigation.js=========================
  44. import React from 'react';
  45. import {createAppContainer} from 'react-navigation'
  46. import { NavigationContainer } from '@react-navigation/native'
  47. import { createStackNavigator } from '@react-navigation/stack'
  48. import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'
  49. import { createDrawerNavigator } from '@react-navigation/drawer'
  50. import { createMaterialBottomTabNavigator } from '@react-navigation/material-bottom-tabs'
  51. import { MainScreen } from '../screens/MainScreen'
  52. import { PostScreen } from '../screens/PostScreen'
  53. import { BookedScreen } from '../screens/BookedScreen'
  54. import { AboutScreen } from '../screens/AboutScreen'
  55. import { CreateScreen } from '../screens/CreateScreen'
  56. import { Ionicons } from '@expo/vector-icons'
  57. import { THEME } from '../theme'
  58. import { Platform } from 'react-native'
  59.  
  60.  
  61. const navigatorOptions = {
  62.   headerStyle:{
  63.   backgroundColor: Platform.OS === 'android' ? THEME.MAIN_COLOR : '#fff'
  64.   },
  65.   headerTintColor: Platform.OS === 'android' ? '#fff' : THEME.MAIN_COLOR
  66. }
  67.  
  68. const PostStack = createStackNavigator()
  69.  
  70.  
  71. const PostStackScreen = () => {
  72.   return (
  73.       <PostStack.Navigator
  74.         screenOptions={navigatorOptions}
  75.         >
  76.         <PostStack.Screen
  77.           name='Main'
  78.           component={MainScreen}
  79.           />
  80.         <PostStack.Screen
  81.           name='Post'
  82.           component={PostScreen}
  83.           />
  84.       </PostStack.Navigator>
  85.       )
  86. }
  87.  
  88. const BookedStack = createStackNavigator()
  89.  
  90. const BookStackScreen = () => {
  91.   return (
  92.     <BookedStack.Navigator
  93.       screenOptions={navigatorOptions}
  94.       >
  95.         <BookedStack.Screen
  96.           name='Booked'
  97.           component={BookedScreen}
  98.           />
  99.         <BookedStack.Screen
  100.           name='Post'
  101.           component={PostScreen}
  102.         />
  103.     </BookedStack.Navigator>
  104.   )
  105. }
  106.  
  107. const configStyleForPlatform = Platform.OS === 'android'
  108.   ? {
  109.     activeTintColor: THEME.MAIN_COLOR,
  110.     inactiveTintColor: 'gray',
  111.   }
  112.   : {
  113.     activeTintColor: '#fff',
  114.   }
  115.  
  116. const barStyleconfig = Platform.OS === 'android'
  117.  ? {
  118.    backgroundColor: THEME.MAIN_COLOR,
  119.  
  120.  }
  121.  : {}
  122.  
  123.  
  124.  
  125.  
  126. const BottomNavigator = Platform.OS === 'android'
  127. ? createMaterialBottomTabNavigator()
  128. : createBottomTabNavigator()
  129.  
  130.  
  131.  
  132. const bottomTabsConfig = (
  133.       <BottomNavigator.Navigator
  134.         tabBarOptions={configStyleForPlatform}
  135.         barStyle = {barStyleconfig}
  136.         shifting={true}
  137.         >
  138.         <BottomNavigator.Screen
  139.           name='Все' component={PostStackScreen}
  140.           options={{
  141.             tabBarIcon: (info) => (
  142.               <Ionicons name='ios-albums' size={25} color={info.color}/>
  143.             ),
  144.           }}
  145.           />
  146.         <BottomNavigator.Screen
  147.           name='Избранное'
  148.           component={BookStackScreen}
  149.           options={{
  150.             tabBarIcon: (info) => (
  151.               <Ionicons name='ios-star' size={25} color={info.color}/>
  152.             ),
  153.           }}
  154.           />
  155.       </BottomNavigator.Navigator>
  156. )
  157.  
  158.  
  159. const BottomNavigatorStackScreen = () => {
  160.   return (
  161.     bottomTabsConfig
  162.   )
  163. }
  164.  
  165. const AboutStack = createStackNavigator()
  166.  
  167. const AboutStackScreen = () => {
  168.   return (
  169.     <AboutStack.Navigator
  170.       screenOptions={navigatorOptions}
  171.  
  172.       >
  173.       <AboutStack.Screen name='About' component={AboutScreen}/>
  174.  
  175.     </AboutStack.Navigator>
  176.   )
  177. }
  178.  
  179. const CreateStack = createStackNavigator()
  180.  
  181. const CreateStackScreen = () => {
  182.   return(
  183.     <CreateStack.Navigator
  184.       screenOptions={navigatorOptions}
  185.       >
  186.       <CreateStack.Screen
  187.         name='Create'
  188.         component={CreateScreen}/>
  189.  
  190.     </CreateStack.Navigator>
  191.   )
  192. }
  193.  
  194. const MainNavigator = createDrawerNavigator()
  195.  
  196. export const AppNavigation = () => {
  197.   return (
  198.     <NavigationContainer>
  199.       <MainNavigator.Navigator
  200.  
  201.       >
  202.       <MainNavigator.Screen name='PostScreenNav' component={BottomNavigatorStackScreen}/>
  203.       <MainNavigator.Screen name='AboutScreen' component={AboutStackScreen}/>
  204.       <MainNavigator.Screen name='CreateScreen' component={CreateStackScreen}/>
  205.  
  206.  
  207.  
  208.       </MainNavigator.Navigator>
  209.     </NavigationContainer>
  210.   )
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement