Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import {
  3. TouchableHighlight,
  4. View,
  5. ScrollView,
  6. Image,
  7. Platform,
  8. StyleSheet,
  9. } from 'react-native';
  10.  
  11. import {
  12. RkStyleSheet,
  13. RkText,
  14. RkTheme,
  15. } from 'react-native-ui-kitten';
  16.  
  17. import Icon from 'react-native-vector-icons/Ionicons';
  18.  
  19. import Routes from '../../config/navigation/routes';
  20.  
  21. import logo from '../../assets/smallLogo.png';
  22.  
  23. export default function SideNavigation(props) {
  24. const onMenuItemPressed = item => {
  25. props.navigation.navigate(item.id);
  26. };
  27.  
  28. const renderIcon = () => (<Image style={styles.image} source={logo}/>);
  29.  
  30. const renderMenuItem = item => (
  31. <TouchableHighlight style={styles.container} key={item.id} underlayColor={RkTheme.current.colors.button.underlay} activeOpacity={1} onPress={() => onMenuItemPressed(item)}>
  32. <View style={styles.content}>
  33. <View style={styles.content}>
  34. <RkText style={styles.icon} rkType='moon primary xlarge'><Icon name={item.icon} size={25}/></RkText>
  35. <RkText rkType='regular'>{item.title}</RkText>
  36. </View>
  37. {/*<RkText rkType='awesome secondaryColor small'>{FontAwesome.chevronRight}</RkText>*/}
  38. </View>
  39. </TouchableHighlight>
  40. );
  41.  
  42. const renderMenu = () => Routes.map(renderMenuItem);
  43.  
  44. return (
  45. <View style={styles.root}>
  46. <ScrollView showsVerticalScrollIndicator={false}>
  47. <View style={[styles.container, styles.content]}>
  48. {renderIcon()}
  49. </View>
  50. {renderMenu()}
  51. </ScrollView>
  52. </View>
  53. )
  54. }
  55.  
  56. const styles = RkStyleSheet.create(theme => ({
  57. container: {
  58. height: 60,
  59. paddingHorizontal: 16,
  60. borderTopWidth: StyleSheet.hairlineWidth,
  61. borderColor: theme.colors.border.base,
  62. },
  63. root: {
  64. paddingTop: Platform.OS === 'ios' ? 20 : 0,
  65. backgroundColor: theme.colors.screen.base
  66. },
  67. content: {
  68. flex: 1,
  69. flexDirection: 'row',
  70. alignItems: 'center',
  71. },
  72. icon: {
  73. marginRight: 13,
  74. },
  75. image:{
  76. resizeMode: 'contain',
  77. maxWidth: 125
  78. }
  79. }));
  80.  
  81. import React, {Component} from 'react';
  82. import { View, Text} from 'react-native';
  83. import Login from './screens/login';
  84. import PasswordRecovery from './screens/passwordRecovery';
  85. import Home from './screens/home';
  86.  
  87. import SideNavigator from './components/sideMenu';
  88.  
  89. import { bootstrap } from './config/bootstrap';
  90. import {
  91. createDrawerNavigator,
  92. createStackNavigator,
  93. createAppContainer
  94. } from 'react-navigation';
  95. import { withRkTheme } from 'react-native-ui-kitten';
  96. import NavBar from './components/navBar';
  97. import AppRoutes from './config/navigation/routesBuilder';
  98. import Splash from './screens/splash';
  99.  
  100. bootstrap();
  101.  
  102. const renderHeader = (navigation, props) => {
  103. const ThemedNavigationBar = withRkTheme(NavBar);
  104. return (
  105. <ThemedNavigationBar navigation={navigation} headerProps={props} />
  106. );
  107. };
  108.  
  109. const App = createStackNavigator({
  110. Splash: Splash,
  111. Login: Login,
  112. PasswordRecovery: PasswordRecovery,
  113. Main: createDrawerNavigator({
  114. ...AppRoutes
  115. },{
  116. contentComponent: props => {
  117. const SideNav = withRkTheme(SideNavigator);
  118. return <SideNav {...props}/>
  119. }
  120. }),
  121. },
  122. {
  123. headerMode: 'none',
  124. })
  125.  
  126. export default createAppContainer(App);
  127.  
  128. import React from 'react';
  129. import _ from 'lodash';
  130. import { createStackNavigator } from 'react-navigation';
  131. import { withRkTheme } from 'react-native-ui-kitten';
  132. import transition from './transitions';
  133.  
  134. import Routes from './routes';
  135. import NavBar from '../../components/navBar';
  136.  
  137. const main = {};
  138. const flatRoutes = {};
  139.  
  140. const routeMapping = (route) => ({
  141. screen: withRkTheme(route.screen),
  142. title: route.title,
  143. });
  144.  
  145. (Routes).forEach(route => {
  146. flatRoutes[route.id] = routeMapping(route);
  147. main[route.id] = routeMapping(route);
  148. route.children.forEach(nestedRoute => {
  149. flatRoutes[nestedRoute.id] = routeMapping(nestedRoute);
  150. });
  151. });
  152.  
  153. const renderHeader = (navigation, props) => {
  154. const ThemedNavigationBar = withRkTheme(NavBar);
  155. return (
  156. <ThemedNavigationBar navigation={navigation} headerProps={props} />
  157. );
  158. };
  159.  
  160. const DrawerRoutes = Object.keys(main).reduce((routes, name) => {
  161. const rawRoutes = routes;
  162. rawRoutes[name] = {
  163. name,
  164. screen: createStackNavigator(flatRoutes, {
  165. initialRouteName: name,
  166. headerMode: 'screen',
  167. cardStyle: { backgroundColor: 'transparent' },
  168. transitionConfig: transition,
  169. defaultNavigationOptions: ({ navigation }) => ({
  170. gesturesEnabled: false,
  171. header: (props) => renderHeader(navigation, props),
  172. }),
  173. }),
  174. };
  175. return rawRoutes;
  176. }, {});
  177.  
  178. const AppRoutes = DrawerRoutes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement