Last active
April 22, 2024 07:58
-
-
Save tmodoux/c5c47ba4c6e14c64177c79e2942f03be to your computer and use it in GitHub Desktop.
MainApplication kotlin code for twilio voice sdk integration in android app built with React native
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.androidapp | |
import android.app.Application | |
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.twiliovoicereactnative.VoiceApplicationProxy | |
class MainApplication : Application(), ReactApplication { | |
override val reactNativeHost: ReactNativeHost = | |
object : DefaultReactNativeHost(this) { | |
override fun getPackages(): List<ReactPackage> = | |
PackageList(this).packages.apply { | |
// Packages that cannot be autolinked yet can be added manually here, for example: | |
// add(MyReactNativePackage()) | |
} | |
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) | |
private val mReactNativeHost = MainReactNativeHost(this) | |
private val voiceApplicationProxy = VoiceApplicationProxy(mReactNativeHost) | |
override fun onCreate() { | |
super.onCreate() | |
voiceApplicationProxy.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) | |
} | |
override fun onTerminate() { | |
voiceApplicationProxy.onTerminate() | |
super.onTerminate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment