Initialization
XpressPlug needs to be initialized from ReactNative so that it can be invoked correctly.
To initialize XpressPlug from reactNative, you need to invoke the XpressPlugInitializer class. This Kotlin class was designed to invoke the SDK's initializer and manage responses callbacks. This class implements the StartAction.Callback interface, which enables you to manage every initialization event, such as the resources download process, the progress or errors management.
Important
To allow XpressPlug to integrate correctly in its execution environment, the initializer requires contextual parameters, such as references to the main Application and the current Activity.
Follow the steps below to initialize XpressPlug:
Invoke the XpressPlugInitializer class:
class XpressPlugInitializer(private var promise: Promise?) : StartAction.Callback { fun execute() { XpressPlugConstants.init() XpressPlug.init( MainApplication.context, XpressPlugConstants.getConstants(), listOf() ) XpressPlug.start(MainApplication.mainActivity, this) } override fun onProgressMessageUpdate(message: String?) { Log.i("XpressPlugModule", "---- XpressPlugInitializer onProgressMessageUpdate: $message") } override fun onXpressPlugNeedsUpdate() { Log.i("XpressPlugModule", "---- XpressPlugInitializer onXpressPlugNeedsUpdate") } override fun onProgressPercentageUpdate(percentage: Int) { Log.i( "XpressPlugModule", "---- XpressPlugInitializer onProgressPercentageUpdate: $percentage" ) } override fun onFinish() { Log.i("XpressPlugModule", "---- XpressPlugInitializer onFinish") promise?.resolve("true") promise = null } override fun onError(code: Int, message: String?) { val error = listOf("$code", message).joinToString(" - ") Log.i("XpressPlugModule", "---- XpressPlugInitializer onError: $error") promise?.reject("$code", message) promise = null } }
Initialize and execute the XpressPlugInitializer class from XpressPlugModule:
class XpressPlugModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { private var initializer: XpressPlugInitializer? = null private var entryPoint: XpressPlugEntryPoint? = null override fun getName(): String { return "XpressPlugModule" } @ReactMethod fun initialize(promise: Promise) { Log.i("XpressPlugModule", "---- XpressPlugModule did receive call initialize") initializer = XpressPlugInitializer(promise) initializer?.execute() } }
To obtain the Activity and Application parameters that XpressPlug requires, it is recommended to use two static variables within the MainApplication class in your Android project, as shown below: