-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
112 lines (90 loc) · 3.05 KB
/
index.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
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
const { ScreenStatusDetect: NativeScreenStatusDetect } = NativeModules;
let LISTENERS = {};
let ID = 0;
let META = '__listener_id';
/**
* @return {string}
*/
function GetKey(listener) {
if (!listener.hasOwnProperty(META)) {
if (!Object.isExtensible(listener)) {
return 'F';
}
Object.defineProperty(listener, META, {
value: `L${++ID}`
});
}
return listener[META];
}
export default class ScreenStatusDetect {
static async getCurrentStatus() {
return await NativeScreenStatusDetect.getCurrentStatus();
}
static async checkIsBlueStacks() {
return await NativeScreenStatusDetect.checkIsBlueStacks();
}
static addListener(callback) {
if (typeof callback === 'function') {
let key = GetKey(callback);
if (Platform.OS === 'android') {
NativeScreenStatusDetect.subscribe();
}
LISTENERS[key] = DeviceEventEmitter.addListener('screenStatusChange', callback);
} else {
console.error('callback is not a function');
}
}
static removeListener(callback) {
if (typeof callback === 'function') {
let key = GetKey(callback);
if (Platform.OS === 'android') {
NativeScreenStatusDetect.unsubscribe();
}
if (LISTENERS[key]) {
LISTENERS[key].remove();
LISTENERS[key] = null;
}
} else {
console.error('callback is not a function');
}
}
static async getCertificateFingerprint() {
if (Platform.OS === 'android') {
return await NativeScreenStatusDetect.getCertificateFingerprint();
} else {
console.log('(getCertificateFingerprint) this method is only available on android platform');
}
return null;
}
static async getCertificateValue() {
if (Platform.OS === 'android') {
return await NativeScreenStatusDetect.getCertificateValue();
} else {
console.log('(getCertificateValue) this method is only available on android platform');
}
return null;
}
static async isEmulator() {
if (Platform.OS === 'android') {
return await NativeScreenStatusDetect.isEmulator();
} else {
console.log('(isEmulator) this method is only available on android platform');
}
return null;
}
static enableSecureScreen() {
if (Platform.OS === 'android') {
NativeScreenStatusDetect.enableSecureScreen();
} else {
console.log('(enableSecureScreen) this method is only available on android platform');
}
}
static disableSecureScreen() {
if (Platform.OS === 'android') {
NativeScreenStatusDetect.disableSecureScreen();
} else {
console.log('(disableSecureScreen) this method is only available on android platform');
}
}
}