-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGrowingTouch.js
79 lines (68 loc) · 2.52 KB
/
GrowingTouch.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
import {NativeModules, NativeEventEmitter} from 'react-native';
const EVENT_REMINDER = 'GTouchEventReminder';
export default class GrowingTouch {
static sEventEmitter;
static sEventPopupListener;
static setEventPopupEnable(enable) {
if (enable === true) {
NativeModules.RNGrowingTouch.setEventPopupEnable(true);
} else {
NativeModules.RNGrowingTouch.setEventPopupEnable(false);
}
}
static async isEventPopupEnabled() {
const {popupEnabled} = await NativeModules.RNGrowingTouch.isEventPopupEnabled();
return popupEnabled;
}
static enableEventPopupAndGenerateAppOpenEvent() {
NativeModules.RNGrowingTouch.enableEventPopupAndGenerateAppOpenEvent();
}
static async isEventPopupShowing() {
const {popupShowing} = await NativeModules.RNGrowingTouch.isEventPopupShowing();
return popupShowing;
}
static setEventPopupListener(listener) {
this.sEventPopupListener = listener;
if (this.sEventEmitter) {
return;
}
const eventEmitter = new NativeEventEmitter(NativeModules.RNGrowingTouch);
eventEmitter.addListener(EVENT_REMINDER, (event) => {
let method = event.method;
let eventId = event.eventId;
let eventType = event.eventType;
switch (method) {
case 'onLoadSuccess':
if (this.sEventPopupListener && this.sEventPopupListener.onLoadSuccess) {
this.sEventPopupListener.onLoadSuccess(eventId, eventType);
}
break;
case 'onLoadFailed':
if (this.sEventPopupListener && this.sEventPopupListener.onLoadFailed) {
let errorCode = event.errorCode;
let description = event.description;
this.sEventPopupListener.onLoadFailed(eventId, eventType, errorCode, description);
}
break;
case 'onClicked':
if (this.sEventPopupListener && this.sEventPopupListener.onClicked) {
let penUrl = event.openUrl;
this.sEventPopupListener.onClicked(eventId, eventType, penUrl);
}
break;
case 'onCancel':
if (this.sEventPopupListener && this.sEventPopupListener.onCancel) {
this.sEventPopupListener.onCancel(eventId, eventType);
}
break;
case 'onTimeout':
if (this.sEventPopupListener && this.sEventPopupListener.onTimeout) {
this.sEventPopupListener.onTimeout(eventId, eventType);
}
break;
}
});
this.sEventEmitter = eventEmitter;
NativeModules.RNGrowingTouch.setEventPopupListener();
}
}