-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuizScreen.js
58 lines (53 loc) · 1.47 KB
/
QuizScreen.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
import React from 'react';
import { StyleSheet, View, Button, ActivityIndicator } from 'react-native';
// eslint-disable-next-line import/no-extraneous-dependencies
// import { Ionicons } from '@expo/vector-icons';
export default class QuizScreen extends React.Component {
state = {
loading: false,
};
startQuiz = () => {
const { loading } = this.state;
const { navigation } = this.props;
this.setState({ loading: !loading });
fetch(
'https://opentdb.com/api.php?amount=10&category=18&difficulty=easy&type=multiple&encode=base64',
)
.then(response => response.json())
.then(({ results }) => {
this.setState({ loading: false });
navigation.navigate('Questions', { questions: results });
})
.catch(err => {
console.log('ERR->', err);
// eslint-disable-next-line no-alert
alert(`ERROR:${err.message}`);
this.setState({ loading: false });
});
};
render() {
const { loading } = this.state;
return (
<View style={styles.container}>
{loading ? (
<ActivityIndicator size="large" color="#008080" />
) : (
<Button
onPress={() => this.startQuiz()}
title="Start Quiz"
color="#008080"
/>
)}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
paddingTop: 30,
justifyContent: 'center',
alignItems: 'center',
},
});