-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
102 lines (92 loc) · 2.66 KB
/
App.tsx
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
import React, { useEffect, useRef } from 'react';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import AudioNotification from 'react-native-audio-notification';
export default function App() {
const notRef = useRef<any>();
useEffect(() => {
const not = AudioNotification({
title: 'hello bin',
description: 'aaaaaa',
cover:
'https://cos.haxibiao.com/storage/app-haxibiao/images60d9f18cbe7f4.png',
is_play: true,
is_like: true,
});
notRef.current = not;
not?.subscribe('onClickLike', (event: any) => {
console.log('用户点击了喜欢', event);
});
not?.subscribe('onClickLast', (event: any) => {
notRef.current.setAudioConfig({
title: '这是上一首歌啦!',
description: '好听吧?',
cover: 'https://cos.haxibiao.com/storage/avatar/avatar-2.jpg',
});
notRef.current?.update();
console.log('用户点击了上一首', event);
});
not?.subscribe('onClickPlay', (event: any) => {
console.log('用户点击了播放/暂停', event);
});
not?.subscribe('onClickNext', (event: any) => {
console.log('用户点击了下一首', event);
});
not?.subscribe('onClickClose', (event: any) => {
console.log('用户点击了关闭', event);
notRef.current?.cancel();
});
}, []);
return (
<View style={styles.container}>
<TouchableOpacity
style={styles.button}
onPress={() => {
notRef.current?.notify();
}}
>
<Text style={{ color: '#FFF' }}>推送通知</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notRef.current?.cancel();
}}
>
<Text style={{ color: '#FFF' }}>关闭通知</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
notRef.current.setAudioConfig({
title: '修改成功啦!!!',
description: '你看这是已经修改好了的',
cover:
'https://cos.haxibiao.com/storage/app-haxibiao/images61206e53659ce.png',
});
notRef.current?.update();
}}
>
<Text style={{ color: '#FFF' }}>修改通知</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
button: {
paddingHorizontal: 35,
paddingVertical: 15,
borderRadius: 100,
backgroundColor: '#F76',
marginBottom: 15,
},
});