-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
130 lines (109 loc) · 4.72 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { NativeModules, Platform } from 'react-native'
const { RNBranch } = NativeModules
import createBranchUniversalObject from './branchUniversalObject'
import BranchEvent from './BranchEvent'
import BranchSubscriber from './BranchSubscriber'
const packageFile = require('./../package.json')
export const VERSION = packageFile.version
class Branch {
key = null;
_checkCachedEvents = true;
_debug = false;
constructor(options = {}) {
if (options.debug) this._debug = true
console.info('Initializing react-native-branch v. ' + VERSION)
}
subscribe(options) {
if (typeof options === 'function') {
/*
* Support for legacy API, passing a single callback function:
* branch.subscribe(({params, error, uri}) => { ... }). This is
* the same as the onOpenComplete callback.
*/
options = {
onOpenComplete: options,
}
}
/*
* You can specify checkCachedEvents in the subscribe options to control
* this per subscriber.
*/
if (!('checkCachedEvents' in options)) {
options.checkCachedEvents = this._checkCachedEvents
}
this._checkCachedEvents = false
const subscriber = new BranchSubscriber(options)
subscriber.subscribe()
return () => subscriber.unsubscribe()
}
skipCachedEvents() {
/*** Sets to ignore cached events. ***/
this._checkCachedEvents = false
}
/*** Tracking related methods ***/
disableTracking = (disable) => RNBranch.disableTracking(disable)
isTrackingDisabled = RNBranch.isTrackingDisabled
/*** RNBranch singleton methods ***/
setDebug = () => { throw 'setDebug() is not supported in the RN SDK. For other solutions, please see https://rnbranch.app.link/setDebug' }
getLatestReferringParams = (synchronous = false) => RNBranch.getLatestReferringParams(synchronous)
getFirstReferringParams = RNBranch.getFirstReferringParams
lastAttributedTouchData = (attributionWindow = {}) => RNBranch.lastAttributedTouchData(attributionWindow)
setIdentity = (identity) => RNBranch.setIdentity(identity)
setIdentityAsync = (identity) => RNBranch.setIdentityAsync(identity)
setRequestMetadata = (key, value) => {
console.info('[Branch] setRequestMetadata has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the metadata.')
return RNBranch.setRequestMetadataKey(key, value)
}
addFacebookPartnerParameter = (name, value) => {
console.info('[Branch] addFacebookPartnerParameter has limitations when called from JS. Some network calls are made prior to the JS layer being available, those calls will not have the partner parameters.')
return RNBranch.addFacebookPartnerParameter(name, value)
}
clearPartnerParameters = RNBranch.clearPartnerParameters
logout = RNBranch.logout
userCompletedAction = (event, state = {}) => RNBranch.userCompletedAction(event, state)
getShortUrl = RNBranch.getShortUrl
sendCommerceEvent = (revenue, metadata) => {
console.info('[Branch] sendCommerceEvent is deprecated. Please use the BranchEvent class instead.')
return RNBranch.sendCommerceEvent('' + revenue, metadata)
}
openURL = (url, options = {}) => {
return Platform.select({
android: () => RNBranch.openURL(url, options),
ios: () => RNBranch.openURL(url)
})()
}
handleATTAuthorizationStatus = (ATTAuthorizationStatus) => {
if (Platform.OS != 'ios') return;
let normalizedAttAuthorizationStatus = -1
switch(ATTAuthorizationStatus) {
case 'authorized':
normalizedAttAuthorizationStatus = 3;
break;
case 'denied':
normalizedAttAuthorizationStatus = 2;
break;
case 'undetermined':
normalizedAttAuthorizationStatus = 0;
break;
case 'restricted':
normalizedAttAuthorizationStatus = 1;
break;
}
if (normalizedAttAuthorizationStatus < 0) {
console.info('[Branch] handleATTAuthorizationStatus received an unrecognized value. Value must be one of; authorized, denied, undetermined, or restricted')
return;
}
RNBranch.handleATTAuthorizationStatus(normalizedAttAuthorizationStatus)
}
/*** BranchUniversalObject ***/
createBranchUniversalObject = createBranchUniversalObject
/*** BranchQRCode ***/
getBranchQRCode = (qrCodeSettings = {}, branchUniversalObject = {}, linkProperties = {}, controlParams = {}) => {
return RNBranch.getBranchQRCode(qrCodeSettings, branchUniversalObject, linkProperties, controlParams);
}
/*** PreInstall Parameters ***/
setPreInstallCampaign = (campaign) => RNBranch.setPreinstallCampaign(campaign)
setPreInstallPartner = (partner) => RNBranch.setPreinstallPartner(partner)
}
export { Branch, BranchEvent, BranchSubscriber }
export default new Branch()