-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
54 lines (48 loc) · 1.84 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
//
// index.js
// play-install-referrer-react-native
// version: 1.1.8
//
// Created by Uglješa Erceg (@uerceg) on 24th April 2020.
// Copyright (c) 2020-2021 uerceg. All rights reserved.
//
'use strict';
import {
NativeModules,
NativeEventEmitter,
Platform,
} from 'react-native';
var PlayInstallReferrer = {};
if (Platform.OS === 'android') {
let modulePlayInstallReferrer = NativeModules.PlayInstallReferrer;
let modulePlayInstallReferrerEmitter = new NativeEventEmitter(NativeModules.PlayInstallReferrer);
PlayInstallReferrer.getInstallReferrerInfo = function (callback) {
// subscribe to get play install referrer value if successfully read
const subscriptionValue = modulePlayInstallReferrerEmitter.addListener('play_install_referrer_value', (playInstallReferrerValue) => {
callback(playInstallReferrerValue, null);
// clean up subscriptions if they exist
if (subscriptionValue != null) {
subscriptionValue.remove();
}
if (subscriptionError != null) {
subscriptionError.remove();
}
});
// subscribe to get error in case play install referrer value reading failed
const subscriptionError = modulePlayInstallReferrerEmitter.addListener('play_install_referrer_error', (error) => {
callback(null, error);
// clean up subscriptions if they exist
if (subscriptionValue != null) {
subscriptionValue.remove();
}
if (subscriptionError != null) {
subscriptionError.remove();
}
});
// invoke native API
modulePlayInstallReferrer.getInstallReferrerInfo();
};
} else {
PlayInstallReferrer.getInstallReferrerInfo = function () {};
}
module.exports = { PlayInstallReferrer }