-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathMainApplication.kt
61 lines (51 loc) · 2.36 KB
/
MainApplication.kt
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
package com.klaviyoreactnativesdkexample
import android.app.Application
import android.util.Log
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.react.flipper.ReactNativeFlipper
import com.facebook.soloader.SoLoader
import com.google.firebase.messaging.FirebaseMessaging
import com.klaviyo.analytics.Klaviyo
class MainApplication : Application(), ReactApplication {
override val reactNativeHost: ReactNativeHost =
object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> {
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
return PackageList(this).packages
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
}
override val reactHost: ReactHost
get() = getDefaultReactHost(this.applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
ReactNativeFlipper.initializeFlipper(this, reactNativeHost.reactInstanceManager)
if (BuildConfig.INITIALIZE_KLAVIYO_FROM_NATIVE) {
// Android Installation Step 3: Initialize the SDK with public key and context, if initializing from native code
Klaviyo.initialize(BuildConfig.PUBLIC_API_KEY, this)
if (BuildConfig.USE_NATIVE_FIREBASE) {
// Android Installation Step 4a: Collect push token and pass it to Klaviyo, if handling push tokens natively
FirebaseMessaging.getInstance().token.addOnSuccessListener {
Log.d("KlaviyoSampleApp", "Push token set: $it")
Klaviyo.setPushToken(it)
}
}
}
}
}