forked from netbeast/react-native-android-widget-poc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidgetTask.js
42 lines (36 loc) · 814 Bytes
/
widgetTask.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
/**
* @flow
*/
import { NativeModules, ToastAndroid } from 'react-native'
import bgTimer from 'react-native-background-timer'
const { BackgroundTaskBridge } = NativeModules
const charms = [
{
id: 'uuid1',
name: 'First',
cover: 'goodmorning',
},
{
id: 'uuid2',
name: 'Second',
cover: 'night',
}
]
type TaskInfo = {
id: string,
}
export default async function widgetTask (taskData: TaskInfo) {
const {id} = taskData || {}
bgTimer.setTimeout(() => {
synchronizeWidget()
triggerCharm(id)
}, 0)
}
export function synchronizeWidget () {
ToastAndroid.show(`Initializing ...`, ToastAndroid.SHORT);
BackgroundTaskBridge.initializeWidgetBridge(charms)
}
function triggerCharm (id) {
if (!id) return
ToastAndroid.show(`Triggering ${id}...`, ToastAndroid.SHORT);
}