summaryrefslogtreecommitdiff
path: root/frontend/app/app.js
blob: f469e15904af51e28e838b4f852d030d53bc1206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import React from 'react';
import { View } from 'react-native';
import {
    AppLoading,
    Font,
} from 'expo';
import {
    createDrawerNavigator,
    createStackNavigator,
} from 'react-navigation';
import { withRkTheme } from 'react-native-ui-kitten';
import { AppRoutes } from './config/navigation/routesBuilder';
import * as Screens from './screens';
import { bootstrap } from './config/bootstrap';
import track from './config/analytics';
import { data } from './data';

bootstrap();
data.populateData();

const KittenApp = createStackNavigator({
    First: {
        screen: Screens.SplashScreen,
    },
    Home: {
        screen: createDrawerNavigator(
            {
                ...AppRoutes,
            },
            {
                contentComponent: (props) => {
                    const SideMenu = withRkTheme(Screens.SideMenu);
                    return <SideMenu {...props} />;
                },
            },
        ),
    },
}, {
    headerMode: 'none',
});

export default class App extends React.Component {
    state = {
        isLoaded: false,
    };

    componentWillMount() {
        this.loadAssets();
    }

    onNavigationStateChange = (previous, current) => {
        const screen = {
            current: this.getCurrentRouteName(current),
            previous: this.getCurrentRouteName(previous),
        };
        if (screen.previous !== screen.current) {
            track(screen.current);
        }
    };

    getCurrentRouteName = (navigation) => {
        const route = navigation.routes[navigation.index];
        return route.routes ? this.getCurrentRouteName(route) : route.routeName;
    };

    loadAssets = async () => {
        await Font.loadAsync({
            fontawesome: require('./assets/fonts/fontawesome.ttf'),
            icomoon: require('./assets/fonts/icomoon.ttf'),
            'Righteous-Regular': require('./assets/fonts/Righteous-Regular.ttf'),
            'Roboto-Bold': require('./assets/fonts/Roboto-Bold.ttf'),
            'Roboto-Medium': require('./assets/fonts/Roboto-Medium.ttf'),
            'Roboto-Regular': require('./assets/fonts/Roboto-Regular.ttf'),
            'Roboto-Light': require('./assets/fonts/Roboto-Light.ttf'),
        });
        this.setState({ isLoaded: true });
    };

    renderLoading = () => (
      <AppLoading />
    );

    renderApp = () => (
      <View style={{ flex: 1 }}>
        <KittenApp onNavigationStateChange={this.onNavigationStateChange} />
      </View>
    );

    render = () => (this.state.isLoaded ? this.renderApp() : this.renderLoading());
}

Expo.registerRootComponent(App);