-
Notifications
You must be signed in to change notification settings - Fork 15
chore: remove old architecture support in Android implementation #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
55708cc
chore: remove old arch listener callbacks
mrehan27 618ba94
chore: remove old arch support android
mrehan27 a835779
post rebase
mrehan27 025f9ec
Revert "chore: remove old arch listener callbacks"
mrehan27 b20e274
make logger lazy
mrehan27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
78 changes: 78 additions & 0 deletions
78
android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackage.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package io.customer.reactnative.sdk | ||
|
|
||
| import com.facebook.react.BaseReactPackage | ||
| import com.facebook.react.bridge.NativeModule | ||
| import com.facebook.react.bridge.ReactApplicationContext | ||
| import com.facebook.react.module.model.ReactModuleInfo | ||
| import com.facebook.react.module.model.ReactModuleInfoProvider | ||
| import com.facebook.react.uimanager.ViewManager | ||
| import io.customer.reactnative.sdk.logging.NativeCustomerIOLoggingModule | ||
| import io.customer.reactnative.sdk.messaginginapp.InlineInAppMessageViewManager | ||
| import io.customer.reactnative.sdk.messaginginapp.NativeMessagingInAppModule | ||
| import io.customer.reactnative.sdk.messagingpush.NativeMessagingPushModule | ||
| import io.customer.reactnative.sdk.util.assertNotNull | ||
|
|
||
| /** | ||
| * React Native package for Customer.io SDK that registers all TurboModules and ViewManagers. | ||
| * Implements new architecture support for React Native. | ||
| */ | ||
| class CustomerIOReactNativePackage : BaseReactPackage() { | ||
| /** | ||
| * Creates the list of view managers for the Customer.io React Native SDK. | ||
| */ | ||
| override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> { | ||
| return listOf(InlineInAppMessageViewManager()) | ||
| } | ||
|
|
||
| override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
| // Debugging reveals that this method is never called for ViewManagers. | ||
| // But since ReactNative docs recommend overriding it, we do so here for ViewManagers. | ||
| // See: https://reactnative.dev/docs/fabric-native-components-introduction?platforms=android#4-write-the-reactwebviewpackage | ||
| return when (name) { | ||
| InlineInAppMessageViewManager.NAME -> InlineInAppMessageViewManager() | ||
| NativeCustomerIOLoggingModule.NAME -> NativeCustomerIOLoggingModule(reactContext) | ||
| NativeCustomerIOModule.NAME -> NativeCustomerIOModule(reactContext = reactContext) | ||
| NativeMessagingInAppModule.NAME -> NativeMessagingInAppModule(reactContext) | ||
| NativeMessagingPushModule.NAME -> NativeMessagingPushModule(reactContext) | ||
| else -> assertNotNull<NativeModule>(value = null) { "Unknown module name: $name" } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Creates a ReactModuleInfo for React module registration with the given configuration. | ||
| * Using positional arguments instead of named arguments as named args break on RN 0.76. | ||
| */ | ||
| private fun createReactModuleInfo( | ||
| name: String, | ||
| className: String = name, | ||
| canOverrideExistingModule: Boolean = false, | ||
| needsEagerInit: Boolean = false, | ||
| isCxxModule: Boolean = false, | ||
| isTurboModule: Boolean = true, | ||
| ) = ReactModuleInfo( | ||
| name, | ||
| className, | ||
| canOverrideExistingModule, | ||
| needsEagerInit, | ||
| isCxxModule, | ||
| isTurboModule, | ||
| ) | ||
|
|
||
| override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
| // List of all Fabric ViewManagers and TurboModules registered in this package. | ||
| // Used by React Native to identify and instantiate the modules. | ||
| val moduleNames: List<String> = listOf( | ||
| InlineInAppMessageViewManager.NAME, | ||
| NativeCustomerIOLoggingModule.NAME, | ||
| NativeCustomerIOModule.NAME, | ||
| NativeMessagingInAppModule.NAME, | ||
| NativeMessagingPushModule.NAME, | ||
| ) | ||
| return ReactModuleInfoProvider { | ||
| // Register all ViewManagers and TurboModules | ||
| moduleNames.associateWith { moduleName -> | ||
| createReactModuleInfo(name = moduleName) | ||
| } | ||
| } | ||
| } | ||
| } | ||
49 changes: 0 additions & 49 deletions
49
android/src/main/java/io/customer/reactnative/sdk/CustomerIOReactNativePackageImpl.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,8 +8,8 @@ import io.customer.datapipelines.config.ScreenView | |
| import io.customer.reactnative.sdk.constant.Keys | ||
| import io.customer.reactnative.sdk.extension.getTypedValue | ||
| import io.customer.reactnative.sdk.extension.toMap | ||
| import io.customer.reactnative.sdk.messaginginapp.NativeMessagingInAppModuleImpl | ||
| import io.customer.reactnative.sdk.messagingpush.NativeMessagingPushModuleImpl | ||
| import io.customer.reactnative.sdk.messaginginapp.NativeMessagingInAppModule | ||
| import io.customer.reactnative.sdk.messagingpush.NativeMessagingPushModule | ||
| import io.customer.reactnative.sdk.util.assertNotNull | ||
| import io.customer.sdk.CustomerIO | ||
| import io.customer.sdk.CustomerIOBuilder | ||
|
|
@@ -22,13 +22,12 @@ import io.customer.sdk.events.TrackMetric | |
| import io.customer.sdk.events.serializedName | ||
|
|
||
| /** | ||
| * Shared implementation logic for Customer.io Native SDK communication in React Native. | ||
| * Contains actual business logic used by both old and new architecture [NativeCustomerIOModule] classes. | ||
| * Handles SDK initialization, user identification, event tracking, and device management. | ||
| * React Native module implementation for Customer.io Native SDK | ||
| * using TurboModules with new architecture. | ||
| */ | ||
| internal object NativeCustomerIOModuleImpl { | ||
| const val NAME = "NativeCustomerIO" | ||
|
|
||
| class NativeCustomerIOModule( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not entirely new file, but just merged version of new arch + common implementation of |
||
| private val reactContext: ReactApplicationContext, | ||
| ) : NativeCustomerIOSpec(reactContext) { | ||
| private val logger: Logger | ||
| get() = SDKComponent.logger | ||
|
|
||
|
|
@@ -45,11 +44,8 @@ internal object NativeCustomerIOModuleImpl { | |
| logger.error("CustomerIO SDK is not initialized. Please call initialize() first.") | ||
| } | ||
|
|
||
| fun initialize( | ||
| reactContext: ReactApplicationContext, | ||
| sdkConfig: ReadableMap?, | ||
| promise: Promise? | ||
| ) { | ||
|
|
||
| override fun initialize(config: ReadableMap?, args: ReadableMap?, promise: Promise?) { | ||
| // Skip initialization if already initialized | ||
| if (getSDKInstanceOrNull() != null) { | ||
| logger.info("CustomerIO SDK is already initialized. Skipping initialization.") | ||
|
|
@@ -58,7 +54,7 @@ internal object NativeCustomerIOModuleImpl { | |
| } | ||
|
|
||
| try { | ||
| val packageConfig = sdkConfig.toMap() | ||
| val packageConfig = config.toMap() | ||
| val cdpApiKey = packageConfig.getTypedValue<String>( | ||
| Keys.Config.CDP_API_KEY | ||
| ) ?: throw IllegalArgumentException("CDP API Key is required to initialize Customer.io") | ||
|
|
@@ -90,14 +86,14 @@ internal object NativeCustomerIOModuleImpl { | |
|
|
||
| // Configure push messaging module based on config provided by customer app | ||
| packageConfig.getTypedValue<Map<String, Any>>(key = "push").let { pushConfig -> | ||
| NativeMessagingPushModuleImpl.addNativeModuleFromConfig( | ||
| NativeMessagingPushModule.addNativeModuleFromConfig( | ||
| builder = this, | ||
| config = pushConfig ?: emptyMap() | ||
| ) | ||
| } | ||
| // Configure in-app messaging module based on config provided by customer app | ||
| packageConfig.getTypedValue<Map<String, Any>>(key = "inApp")?.let { inAppConfig -> | ||
| NativeMessagingInAppModuleImpl.addNativeModuleFromConfig( | ||
| NativeMessagingInAppModule.addNativeModuleFromConfig( | ||
| builder = this, | ||
| config = inAppConfig, | ||
| region = region | ||
|
|
@@ -113,11 +109,7 @@ internal object NativeCustomerIOModuleImpl { | |
| } | ||
| } | ||
|
|
||
| fun clearIdentify() { | ||
| requireSDKInstance()?.clearIdentify() | ||
| } | ||
|
|
||
| fun identify(params: ReadableMap?) { | ||
| override fun identify(params: ReadableMap?) { | ||
| val userId = params?.getString("userId") | ||
| val traits = params?.getMap("traits") | ||
|
|
||
|
|
@@ -129,59 +121,67 @@ internal object NativeCustomerIOModuleImpl { | |
| userId?.let { | ||
| requireSDKInstance()?.identify(userId, traits.toMap()) | ||
| } ?: run { | ||
| requireSDKInstance()?.profileAttributes = traits.toMap() | ||
| requireSDKInstance()?.setProfileAttributes(traits.toMap()) | ||
| } | ||
| } | ||
|
|
||
| fun track(name: String?, properties: ReadableMap?) { | ||
| override fun clearIdentify() { | ||
| requireSDKInstance()?.clearIdentify() | ||
| } | ||
|
|
||
| override fun track(name: String?, properties: ReadableMap?) { | ||
| val eventName = assertNotNull(name) ?: return | ||
|
|
||
| requireSDKInstance()?.track(eventName, properties.toMap()) | ||
| } | ||
|
|
||
| fun setDeviceAttributes(attributes: ReadableMap?) { | ||
| requireSDKInstance()?.deviceAttributes = attributes.toMap() | ||
| } | ||
| override fun screen(title: String?, properties: ReadableMap?) { | ||
| val screenTitle = assertNotNull(title) ?: return | ||
|
|
||
| fun setProfileAttributes(attributes: ReadableMap?) { | ||
| requireSDKInstance()?.profileAttributes = attributes.toMap() | ||
| requireSDKInstance()?.screen(screenTitle, properties.toMap()) | ||
| } | ||
|
|
||
| fun screen(title: String?, properties: ReadableMap?) { | ||
| val screenTitle = assertNotNull(title) ?: return | ||
| override fun setProfileAttributes(attributes: ReadableMap?) { | ||
| requireSDKInstance()?.setProfileAttributes(attributes.toMap()) | ||
| } | ||
|
|
||
| requireSDKInstance()?.screen(screenTitle, properties.toMap()) | ||
| override fun setDeviceAttributes(attributes: ReadableMap?) { | ||
| requireSDKInstance()?.setDeviceAttributes(attributes.toMap()) | ||
| } | ||
|
|
||
| fun registerDeviceToken(token: String?) { | ||
| override fun registerDeviceToken(token: String?) { | ||
| val deviceToken = assertNotNull(token) ?: return | ||
|
|
||
| requireSDKInstance()?.registerDeviceToken(deviceToken) | ||
| } | ||
|
|
||
| fun trackMetric(deliveryId: String?, deviceToken: String?, eventName: String?) { | ||
| override fun trackMetric(deliveryID: String?, deviceToken: String?, event: String?) { | ||
| try { | ||
| if (deliveryId == null || deviceToken == null || eventName == null) { | ||
| if (deliveryID == null || deviceToken == null || event == null) { | ||
| throw IllegalArgumentException("Missing required parameters") | ||
| } | ||
|
|
||
| val event = Metric.values().find { | ||
| it.serializedName.equals(eventName, true) | ||
| val metric = Metric.values().find { | ||
| it.serializedName.equals(event, true) | ||
| } ?: throw IllegalArgumentException("Invalid metric event name") | ||
|
|
||
| requireSDKInstance()?.trackMetric( | ||
| event = TrackMetric.Push( | ||
| deliveryId = deliveryId, | ||
| deliveryId = deliveryID, | ||
| deviceToken = deviceToken, | ||
| metric = event | ||
| metric = metric | ||
| ) | ||
| ) | ||
| } catch (e: Exception) { | ||
| logger.error("Error tracking push metric: ${e.message}") | ||
| } | ||
| } | ||
|
|
||
| fun deleteDeviceToken() { | ||
| override fun deleteDeviceToken() { | ||
| requireSDKInstance()?.deleteDeviceToken() | ||
| } | ||
|
|
||
| companion object { | ||
| internal const val NAME = "NativeCustomerIO" | ||
| } | ||
| } | ||
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely new file, but just merged version of new arch + common implementation of
CustomerIOReactNativePackage