-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
137 lines (127 loc) · 2.99 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
import React, {
Component
} from 'react'
import {
Text,
View,
Image,
ScrollView,
} from 'react-native'
import WhatsappStickers from 'react-native-whatsapp-stickers-android'
const Button = props => (
<View
style={{
alignItems: 'center',
backgroundColor: '#5998ff',
padding: 15,
margin: 10,
marginBottom: 5,
borderRadius: 4,
flexBasis: 300,
flexGrow: 1,
}}
{...props}
>
<Text>
{props.children}
</Text>
</View>
)
const Stickers = ({ children: stickers }) => (
stickers.map(sticker =>
<View
key={sticker.imageFileName}
style={{
backgroundColor: '#e6ecef',
borderRadius: 5,
padding: 10,
alignItems: 'center',
flexBasis: 100,
flexShrink: 1,
margin: 10,
}}
>
<Image
source={{ uri: `asset:/cup/${sticker.imageFileName}`}}
style={{
height: 96,
width: 96,
}}
resizeMode="contain"
/>
</View>
)
)
class App extends Component {
state = {
installed: null,
stickers: [],
stickers2: [],
}
componentDidMount = () => {
WhatsappStickers.isStickerPackInstalled('cup')
.then((installed) => {
this.setState({ installed })
})
.catch((error) => {
console.error(error)
})
WhatsappStickers.fetchStickerPacks()
.then((stickerPackList) => {
console.log('stickerPackList HAPA', stickerPackList)
let firstStickerPack = stickerPackList[0]
let secondStickerPack = stickerPackList[1] //
this.setState({ stickers: firstStickerPack.stickers })
this.setState({ stickers2: secondStickerPack.stickers }) //
})
.catch((error) => {
console.error(error)
})
}
render() {
const { installed, stickers, stickers2 } = this.state
return (
<ScrollView
contentContainerStyle={{
flexDirection: 'row',
display: 'flex',
flexWrap: 'wrap',
justifyContent: 'space-evenly'
}}
>
{
installed === null
? <Text>
Loading...
</Text>
: (
!installed &&
<Button
onTouchStart={() => {
let identifier = 'cup'
let name = 'test sticker pack'
WhatsappStickers.addStickerPack(identifier, name)
.then(() => {
this.setState({ installed: true })
})
.catch((error) => {
console.warn(error)
})
}}
>
Add sticker pack
</Button>
)
}
<Stickers>
{stickers}
</Stickers>
<Text>Stickers 2 </Text>
<Stickers>
{stickers2}
</Stickers>
</ScrollView>
)
}
}
export default App