This repository has been archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
App.js
101 lines (97 loc) · 3.79 KB
/
App.js
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
93
94
95
96
97
98
99
100
101
import React from 'react';
import { Router, Stack , Scene } from "react-native-router-flux"
import { Font, Asset, AppLoading } from "expo";
import { Provider } from "react-redux"
import { AsyncStorage } from "react-native"
import fromPairs from "lodash.frompairs"
import I18n from 'ex-react-native-i18n'
import configStore from "./src/store"
import { setRecords} from "./src/store/actions/records";
import { getDemographicData } from "./src/store/actions/demographicData";
import Main from "./src/components/Main"
import OnBoarding from "./src/components/OnBoarding"
import Demographic from "./src/components/Demographic"
import About from "./src/components/About"
import DemographicForm from "./src/components/DemographicForm";
import Profile from "./src/components/Profile";
import {getAyahs} from "./src/store/actions/ayahs";
import ChangeAyah from "./src/components/ChangeAyah";
import PickSurah from "./src/components/PickSurah";
import PickAyah from "./src/components/PickAyah";
import {
getSessionId,
getTotalAyahsCount,
setContinuous,
setFontSize,
setLocale,
setNotificationIteration,
setpassedOnBoarding
} from "./src/store/actions";
import {bindNotifications} from "./src/utils/notification";
import "./src/i18n/index"
const store = configStore()
export default class App extends React.Component {
state = { loading: true }
async componentWillMount() {
await Font.loadAsync({
'Arial': require('./assets/fonts/arial.ttf'),
'Proxima-Nova-Alt-Regular': require('./assets/fonts/Proxima-Nova-Alt-Regular.ttf'),
'Proxima-Nova-Alt-SemiBold': require('./assets/fonts/Proxima-Nova-Alt-SemiBold.ttf'),
'Uthmanic': require('./assets/fonts/Uthmanic.otf'),
});
await I18n.initAsync();
bindNotifications();
store.dispatch(getSessionId())
store.dispatch(getDemographicData())
store.dispatch(getAyahs())
store.dispatch(getTotalAyahsCount())
try {
let { recordsCount, passedOnBoarding, passedOnBoardingScreen, continuous, locale, fontSize, notifications } =
fromPairs(await AsyncStorage.multiGet(["recordsCount", 'fontSize', "passedOnBoarding", "passedOnBoardingScreen", "continuous", "locale", "notifications"]))
this.setState({ loading: false, passedOnBoardingScreen })
store.dispatch(setpassedOnBoarding(passedOnBoarding))
store.dispatch(setContinuous(continuous))
store.dispatch(setRecords(Number(recordsCount)))
store.dispatch(setLocale(locale))
store.dispatch(setFontSize(fontSize))
store.dispatch(setNotificationIteration(notifications))
store.subscribe(() => {
let { locale: newLocale } = store.getState().data
if(locale) {
if(locale !== newLocale) {
locale = newLocale
this.forceUpdate()
}
}
})
}
catch(e) {
console.log(e.message)
}
// Preloading the Image in about page
Asset.fromModule(require("./assets/imgs/Logo.png")).downloadAsync();
}
render() {
const { loading, passedOnBoardingScreen } = this.state
if (loading) {
return <AppLoading />
}
return (
<Provider store={store}>
<Router>
<Stack key="root" hideNavBar>
<Scene initial={!passedOnBoardingScreen} key="onBoarding" component={OnBoarding}/>
<Scene initial={passedOnBoardingScreen} key="home" component={Main}/>
<Scene key="demographic" component={Demographic} />
<Scene key="demographicForm" component={DemographicForm} />
<Scene key="profile" component={Profile} />
<Scene key="about" component={About} />
<Scene key="change" component={ChangeAyah} />
<Scene key="picksurah" component={PickSurah} />
<Scene key="pickayah" component={PickAyah} />
</Stack>
</Router>
</Provider>
);
}
}