/
App.js
144 lines (132 loc) · 4.14 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import React, { Component } from 'react'
import { ScrollView, View } from 'react-native'
import { ThemeProvider, Card, Input, CheckBox, Button } from 'react-native-elements'
import codePush from 'react-native-code-push'
// import Crashes from 'appcenter-crashes'
// import Analytics from 'appcenter-analytics'
let codePushOptions = {
updateDialog: true,
checkFrequency: codePush.CheckFrequency.ON_APP_START,
installMode: codePush.InstallMode.IMMEDIATE
}
class App extends Component {
constructor (props) {
super(props)
this.state = {
list: [],
textInput: ''
}
}
// async componentDidMount () {
// const didCrash = await Crashes.hasCrashedInLastSession()
// if (didCrash) {
// alert('Achievement unlocked: App crashed during a presentation')
// }
// }
codePushStatusDidChange (status) {
switch (status) {
case codePush.SyncStatus.CHECKING_FOR_UPDATE:
console.log('Checking for updates.')
break
case codePush.SyncStatus.DOWNLOADING_PACKAGE:
console.log('Downloading package.')
break
case codePush.SyncStatus.INSTALLING_UPDATE:
console.log('Installing update.')
break
case codePush.SyncStatus.UP_TO_DATE:
console.log('Up-to-date.')
break
case codePush.SyncStatus.UPDATE_INSTALLED:
console.log('Update installed.')
break
}
}
codePushDownloadDidProgress (progress) {
console.log(progress.receivedBytes + ' of ' + progress.totalBytes + ' received.')
}
addItem () {
if (this.state.textInput.trim().length !== 0) {
// Analytics.trackEvent('Add new item', { Task: this.state.textInput })
// Creating new task item
let newTask = {title: this.state.textInput, completed: false}
// Updating task list
let newTaskList = this.state.list
newTaskList.push(newTask)
// Updating state with new task list
this.setState({
list: newTaskList,
textInput: ''
})
}
}
updateItem (index, itemStatus) {
// Updating completed status of task item
let updatedTaskItem = {
...this.state.list[index],
completed: !itemStatus
}
// Updating task list with updated task item
let newTaskList = this.state.list
newTaskList.splice(index, 1, updatedTaskItem)
// Updating state with updated task list
this.setState({
list: newTaskList
})
}
render () {
return (
<ThemeProvider>
<ScrollView>
<View accessibilityLabel='testview'>
<Card
title='Welcome to GAB 2019!'
// image={require('./resources/gab_logo.png')}
image={require('./resources/ms_logo.jpg')}
imageProps={{resizeMode: 'contain'}} />
<Card>
<Input
label={'Add a to-do item'}
value={this.state.textInput}
placeholder={'+'}
onChangeText={(textInput) => this.setState({textInput})}
onSubmitEditing={() => this.addItem()}
returnKeyType={'done'}
/>
<Button
title='Crash Button'
type='outline'
raised
containerStyle={{marginTop: 20}}
onPress={() => {
throw new Error('This is a test javascript crash!')
}}
/>
<Button
title='Add'
type='outline'
raised
containerStyle={{marginTop: 20}}
onPress={() => this.addItem()}
/>
</Card>
{
this.state.list.length !== 0
? <Card>
{
this.state.list.map((item, index) => <CheckBox
key={index}
title={item.title}
checked={item.completed}
onPress={() => this.updateItem(index, item.completed)} />)
}
</Card>
: null
}
</View>
</ScrollView>
</ThemeProvider>
)
}
}
export default codePush(codePushOptions)(App)