-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathApp.js
77 lines (69 loc) · 1.77 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
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { Constants } from 'expo';
// You can import from local files
import AssetExample from './components/AssetExample';
// or any pure javascript modules available in npm
import { Card } from 'react-native-paper';
import * as Kittens from './services/kittens';
import presetKittens from './presetKittens';
export default class App extends React.Component {
state = {
localDocs: []
}
renderKittens() {
return this.state.localDocs.map(item => {
return (
<Text key={item.key} style={styles.developmentModeText}>
{item.kitten.name}
</Text>
);
});
}
async loadKittens() {
await Promise.all(presetKittens.map(function (kit) {
return Kittens.addIfNew(kit);
}));
await Kittens.duplicate();
let allKittens = await Kittens.getAll();
await this.promisedSetState({localDocs: allKittens});
}
promisedSetState = (newState) => {
return new Promise((resolve) => {
this.setState(newState, () => {
resolve()
});
});
}
async componentDidMount() {
await this.loadKittens();
}
render() {
return (
<View style={styles.container}>
<Text style={styles.paragraph}>
This is a demo of working with PouchDB within Expo on React Native.
</Text>
{this.renderKittens()}
<Card>
<AssetExample />
</Card>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});