forked from MalesM/React-Native-Anime-Search-Engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
127 lines (92 loc) · 3.07 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import { ToastAndroid, AsyncStorage, Image, Dimensions } from 'react-native'
import { Tabs } from './appsettings/router';
import { Spinner, Container, Content, Grid, Row, Text } from 'native-base';
import firebase from './appsettings/fbconfig';
import RNFetchBlob from 'react-native-fetch-blob';
export default class App extends Component {
constructor(props) {
super(props);
this.itemsRef = firebase.database().ref();
this.state = {
isReady: false,
loadUser: false
}
console.ignoredYellowBox = [
'Setting a timer',
'Circular indeterminate'
];
let dirs = RNFetchBlob.fs.dirs
}
componentWillMount() {
this.getCurrentUser();
}
render() {
if (!this.state.loadUser || !this.state.isReady) {
return (
<Container>
<Content style={{ backgroundColor: '#FB8C00' }} contentContainerStyle={{ flex: 1, justifyContent: 'center' }}>
<Grid style={{ alignItems: 'center' }}>
<Row size={1}>
<Image source={require('./assets/animetitancover.png')}
style={{
width: Dimensions.get('window').width,
height: 170
}}></Image>
</Row>
<Grid style={{ alignItems: 'center' }}>
<Row>
<Spinner style={{ margin: 'auto', alignSelf: 'center' }} color='blue' />
</Row>
<Row>
<Text style={{ color: "white", margin: 10, fontFamily: 'robot_c', alignSelf: 'center', fontWeight: 'bold', fontSize: 18 }}>THE TITANS ARE LOADING YOUR APP.</Text>
</Row>
</Grid>
<Row size={1}>
</Row>
</Grid>
</Content>
</Container >
);
}
else return <Tabs
screenProps={{ originalItems: this.state.originaItems }}
/>;
// if (!this.state.isReady) {
// return <Spinner />
// }
}
async getCurrentUser() {
AsyncStorage.getItem('userID')
.then((value) => {
if (value !== null) {
console.log(value);
ToastAndroid.showWithGravity("Welcome Back!", ToastAndroid.SHORT, ToastAndroid.CENTER);
this.setState({ idd: value, loadUser: true });
} else {
ToastAndroid.showWithGravity("Welcome for the first time!", ToastAndroid.SHORT, ToastAndroid.CENTER);
this.setUser();
}
}).done();
await fetch('http://gomcineplex.com/data/anime/sd_android.json')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isReady: true,
originaItems: responseJson
});
// console.log(this.state.originaItems)
})
.catch((error) => {
console.error(error);
});
}
setUser() {
AsyncStorage.setItem('userID', this.itemsRef.child('Users').push().key).then(() => { this.setState({ loadUser: true }) }).done();
}
}