diff --git a/android/build.gradle b/android/build.gradle index 04cf221..20ab42f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -44,14 +44,16 @@ def supportsNamespace() { apply plugin: 'org.jlleitschuh.gradle.ktlint' apply plugin: 'com.android.library' apply plugin: 'kotlin-android' -//if (isNewArchitectureEnabled()) { -// apply plugin: 'com.facebook.react' -//} +if (isNewArchitectureEnabled()) { + apply plugin: 'com.facebook.react' +} android { if (supportsNamespace()) { namespace 'com.mparticle.react' - buildFeatures.buildConfig = true + buildFeatures { + buildConfig = true + } sourceSets { main { manifest.srcFile "src/main/AndroidManifestNew.xml" @@ -65,15 +67,15 @@ android { targetSdkVersion 33 versionCode 2 versionName "2.0.0" - //buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() + buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() } sourceSets { main { - //if (isNewArchitectureEnabled()) { - // java.srcDirs += ['src/newarch/java'] - //} else { + if (isNewArchitectureEnabled()) { + java.srcDirs += ['src/newarch/java'] + } else { java.srcDirs += ['src/oldarch/java'] - //} + } } } diff --git a/android/gradle.properties b/android/gradle.properties index 418c55f..b53206e 100644 --- a/android/gradle.properties +++ b/android/gradle.properties @@ -24,32 +24,3 @@ android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true - -# Version of flipper SDK to use with React Native -FLIPPER_VERSION=0.125.0 - -# Use this property to specify which architecture you want to build. -# You can also override it from the CLI using -# ./gradlew -PreactNativeArchitectures=x86_64 -reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 - -# Use this property to enable support to the new architecture. -# This will allow you to use TurboModules and the Fabric render in -# your application. You should enable this flag either if you want -# to write custom TurboModules/Fabric components OR use libraries that -# are providing them. -newArchEnabled=false - -# The hosted JavaScript engine -# Supported values: expo.jsEngine = "hermes" | "jsc" -expo.jsEngine=jsc - -# Enable GIF support in React Native images (~200 B increase) -expo.gif.enabled=true -# Enable webp support in React Native images (~85 KB increase) -expo.webp.enabled=true -# Enable animated webp support (~3.4 MB increase) -# Disabled by default because iOS doesn't support animated webp -expo.webp.animated=false - -sonar.gradle.skipCompile=true diff --git a/android/src/main/java/com/mparticle/react/MParticleModule.kt b/android/src/main/java/com/mparticle/react/MParticleModule.kt index 8b7456e..cb6b827 100644 --- a/android/src/main/java/com/mparticle/react/MParticleModule.kt +++ b/android/src/main/java/com/mparticle/react/MParticleModule.kt @@ -5,7 +5,6 @@ import android.util.Log import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.Callback import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap @@ -29,49 +28,48 @@ import com.mparticle.identity.IdentityApiRequest import com.mparticle.identity.IdentityHttpResponse import com.mparticle.identity.MParticleUser import com.mparticle.internal.Logger -import javax.annotation.Nullable class MParticleModule( - reactContext: ReactApplicationContext, -) : ReactContextBaseJavaModule(reactContext) { + private val reactContext: ReactApplicationContext, +) : NativeMParticleSpec(reactContext) { companion object { - const val MODULE_NAME = "MParticle" + const val MODULE_NAME = "RNMParticle" private const val LOG_TAG = "MParticleModule" } override fun getName(): String = MODULE_NAME @ReactMethod - fun upload() { + override fun upload() { MParticle.getInstance()?.upload() } @ReactMethod - fun setUploadInterval(uploadInterval: Int) { - MParticle.getInstance()?.setUpdateInterval(uploadInterval) + override fun setUploadInterval(uploadInterval: Double) { + MParticle.getInstance()?.setUpdateInterval(uploadInterval.toInt()) } @ReactMethod - fun setLocation( + override fun setLocation( latitude: Double, longitude: Double, ) { val newLocation = Location("").apply { - this.latitude = latitude - this.longitude = longitude + setLatitude(latitude) + setLongitude(longitude) } MParticle.getInstance()?.setLocation(newLocation) } @ReactMethod - fun logEvent( - name: String, - type: Int, - attributesMap: ReadableMap?, + override fun logEvent( + eventName: String, + eventType: Double, + attributes: ReadableMap?, ) { - val attributes = convertStringMap(attributesMap) - val eventType = convertEventType(type) + val attributes = convertStringMap(attributes) + val eventType = convertEventType(eventType.toInt()) val event = MPEvent @@ -82,72 +80,83 @@ class MParticleModule( } @ReactMethod - fun logMPEvent(attributesMap: ReadableMap?) { - val event = convertMPEvent(attributesMap) - if (event != null) { - MParticle.getInstance()?.logEvent(event) + override fun logMPEvent(event: ReadableMap?) { + val convertedEvent = convertMPEvent(event) + if (convertedEvent != null) { + MParticle.getInstance()?.logEvent(convertedEvent) } } @ReactMethod - fun logCommerceEvent(map: ReadableMap?) { - if (map != null) { - val commerceEvent = convertCommerceEvent(map) - if (commerceEvent != null) { - MParticle.getInstance()?.logEvent(commerceEvent) + override fun logCommerceEvent(commerceEvent: ReadableMap?) { + commerceEvent?.let { + val convertedCommerceEvent = convertCommerceEvent(it) + if (convertedCommerceEvent != null) { + MParticle.getInstance()?.logEvent(convertedCommerceEvent) } } } @ReactMethod - fun logScreenEvent( - eventName: String, - attributesMap: ReadableMap?, + override fun logScreenEvent( + screenName: String, + attributes: ReadableMap?, shouldUploadEvent: Boolean, ) { - val attributes = convertStringMap(attributesMap) - MParticle.getInstance()?.logScreen(eventName, attributes, shouldUploadEvent) + val convertedAttributes = convertStringMap(attributes) + MParticle.getInstance()?.logScreen(screenName, convertedAttributes, shouldUploadEvent) + } + + override fun setATTStatus(status: Double) { + // Not implemented + } + + override fun setATTStatusWithCustomTimestamp( + status: Double, + timestamp: Double, + ) { + // Not implemented } @ReactMethod - fun setUserAttribute( - userId: String, - userAttribute: String, + override fun setUserAttribute( + mpid: String, + key: String, value: String, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) - selectedUser?.setUserAttribute(userAttribute, value) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) + selectedUser?.setUserAttribute(key, value) } @ReactMethod - fun setUserAttributeArray( - userId: String, + override fun setUserAttributeArray( + mpid: String, key: String, - values: ReadableArray?, + value: ReadableArray?, ) { - if (values != null) { + value?.let { val list = mutableListOf() - for (i in 0 until values.size()) { - values.getString(i)?.let { list.add(it) } + for (i in 0 until it.size()) { + it.getString(i)?.let { element -> list.add(element) } } - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) selectedUser?.setUserAttributeList(key, list) } } @ReactMethod - fun getUserAttributes( - userId: String, - completion: Callback, + override fun getUserAttributes( + mpid: String, + callback: Callback, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) if (selectedUser != null) { selectedUser.getUserAttributes( object : UserAttributeListener { override fun onUserAttributesReceived( - userAttributes: MutableMap?, - userAttributeLists: MutableMap>?, + userAttributes: Map?, + userAttributeLists: Map>?, mpid: Long?, ) { val resultMap = WritableNativeMap() @@ -165,143 +174,148 @@ class MParticleModule( resultMap.putArray(key, resultArray) } } - completion.invoke(null, resultMap) + callback.invoke(null, resultMap) } }, ) } else { - completion.invoke() + callback.invoke() } } @ReactMethod - fun setUserTag( - userId: String, + override fun setUserTag( + mpid: String, tag: String, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) selectedUser?.setUserTag(tag) } @ReactMethod - fun removeUserAttribute( - userId: String, + override fun removeUserAttribute( + mpid: String, key: String, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) selectedUser?.removeUserAttribute(key) } @ReactMethod - fun incrementUserAttribute( - userId: String, + override fun incrementUserAttribute( + mpid: String, key: String, - value: Int, + value: Double, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) selectedUser?.incrementUserAttribute(key, value) } @ReactMethod - fun identify( - requestMap: ReadableMap?, - completion: Callback, + override fun identify( + identityRequest: ReadableMap?, + callback: Callback, ) { - val request = convertIdentityAPIRequest(requestMap) + val request = convertIdentityAPIRequest(identityRequest) MParticle .getInstance() ?.Identity() ?.identify(request) ?.addFailureListener { identityHttpResponse -> - completion.invoke(convertIdentityHttpResponse(identityHttpResponse), null) + callback.invoke(convertIdentityHttpResponse(identityHttpResponse), null) }?.addSuccessListener { identityApiResult -> val user = identityApiResult.user val userID = user.id.toString() - completion.invoke(null, userID) + callback.invoke(null, userID) } } @ReactMethod - fun login( - requestMap: ReadableMap?, - completion: Callback, + override fun login( + identityRequest: ReadableMap?, + callback: Callback, ) { - val request = convertIdentityAPIRequest(requestMap) + val request = convertIdentityAPIRequest(identityRequest) MParticle .getInstance() ?.Identity() ?.login(request) ?.addFailureListener { identityHttpResponse -> - completion.invoke(convertIdentityHttpResponse(identityHttpResponse), null) + callback.invoke(convertIdentityHttpResponse(identityHttpResponse), null) }?.addSuccessListener { identityApiResult -> val user = identityApiResult.user val userId = user.id.toString() val previousUser = identityApiResult.previousUser val previousUserId = previousUser?.id?.toString() - completion.invoke(null, userId, previousUserId) + callback.invoke(null, userId, previousUserId) } } @ReactMethod - fun logout( - requestMap: ReadableMap?, - completion: Callback, + override fun logout( + identityRequest: ReadableMap?, + callback: Callback, ) { - val request = convertIdentityAPIRequest(requestMap) + val request = convertIdentityAPIRequest(identityRequest) MParticle .getInstance() ?.Identity() ?.logout(request) ?.addFailureListener { identityHttpResponse -> - completion.invoke(convertIdentityHttpResponse(identityHttpResponse), null) + callback.invoke(convertIdentityHttpResponse(identityHttpResponse), null) }?.addSuccessListener { identityApiResult -> val user = identityApiResult.user val userID = user.id.toString() - completion.invoke(null, userID) + callback.invoke(null, userID) } } @ReactMethod - fun modify( - requestMap: ReadableMap?, - completion: Callback, + override fun modify( + identityRequest: ReadableMap?, + callback: Callback, ) { - val request = convertIdentityAPIRequest(requestMap) + val request = convertIdentityAPIRequest(identityRequest) MParticle .getInstance() ?.Identity() ?.modify(request) ?.addFailureListener { identityHttpResponse -> - completion.invoke(convertIdentityHttpResponse(identityHttpResponse), null) + callback.invoke(convertIdentityHttpResponse(identityHttpResponse), null) }?.addSuccessListener { identityApiResult -> val user = identityApiResult.user val userID = user.id.toString() - completion.invoke(null, userID) + callback.invoke(null, userID) } } @ReactMethod - fun getCurrentUserWithCompletion(completion: Callback) { + override fun getCurrentUserWithCompletion(callback: Callback) { val currentUser = MParticle.getInstance()?.Identity()?.currentUser if (currentUser != null) { val userID = currentUser.id.toString() - completion.invoke(null, userID) + callback.invoke(null, userID) } else { - completion.invoke(null, null) + callback.invoke(null, null) } } @ReactMethod - fun aliasUsers( - readableMap: ReadableMap?, - completion: Callback, + override fun aliasUsers( + aliasRequest: ReadableMap?, + callback: Callback, ) { - val identityApi = MParticle.getInstance()?.Identity() ?: return - val iterator = readableMap?.keySetIterator() ?: return + val identityApi = MParticle.getInstance()?.Identity() + if (identityApi == null || aliasRequest == null) { + callback.invoke(false, "MParticle not initialized") + return + } + + val iterator = aliasRequest.keySetIterator() var destinationMpid: Long? = null var sourceMpid: Long? = null var startTime: Long? = null @@ -309,29 +323,37 @@ class MParticleModule( while (iterator.hasNextKey()) { try { - when (iterator.nextKey()) { - "destinationMpid" -> destinationMpid = Utils.getLong(readableMap, "destinationMpid", false) - "sourceMpid" -> sourceMpid = Utils.getLong(readableMap, "sourceMpid", false) - "startTime" -> startTime = Utils.getLong(readableMap, "startTime", true) - "endTime" -> endTime = Utils.getLong(readableMap, "endTime", true) + when (val key = iterator.nextKey()) { + "destinationMpid" -> + destinationMpid = + Utils.getLong(aliasRequest, "destinationMpid", false) + + "sourceMpid" -> sourceMpid = Utils.getLong(aliasRequest, "sourceMpid", false) + "startTime" -> startTime = Utils.getLong(aliasRequest, "startTime", true) + "endTime" -> endTime = Utils.getLong(aliasRequest, "endTime", true) } } catch (ex: NumberFormatException) { Logger.error(ex.message) - completion.invoke(false, ex.message) + callback.invoke(false, ex.message) return } } if (startTime == null && endTime == null) { - val sourceUser: MParticleUser? = sourceMpid?.let { identityApi.getUser(it) } - val destinationUser: MParticleUser? = destinationMpid?.let { identityApi.getUser(it) } + var sourceUser: MParticleUser? = null + var destinationUser: MParticleUser? = null + sourceMpid?.let { sourceUser = identityApi.getUser(it) } + destinationMpid?.let { destinationUser = identityApi.getUser(it) } if (sourceUser != null && destinationUser != null) { - val request = AliasRequest.builder(sourceUser, destinationUser).build() + val request = AliasRequest.builder(sourceUser!!, destinationUser!!).build() val success = MParticle.getInstance()?.Identity()?.aliasUsers(request) ?: false - completion.invoke(success) + callback.invoke(success) } else { - completion.invoke(false, "MParticleUser could not be found for provided sourceMpid and destinationMpid") + callback.invoke( + false, + "MParticleUser could not be found for provided sourceMpid and destinationMpid", + ) } } else { val request = @@ -343,62 +365,62 @@ class MParticleModule( .endTime(endTime ?: 0) .build() val success = identityApi.aliasUsers(request) - completion.invoke(success) + callback.invoke(success) } } @ReactMethod - fun getSession(completion: Callback) { + override fun getSession(callback: Callback) { val session = MParticle.getInstance()?.currentSession if (session != null) { val sessionId = session.sessionUUID - completion.invoke(sessionId) + callback.invoke(sessionId) } else { - completion.invoke() + callback.invoke() } } @ReactMethod - fun getUserIdentities( - userId: String, - completion: Callback, + override fun getUserIdentities( + mpid: String, + callback: Callback, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(parseMpid(mpid)) if (selectedUser != null) { - completion.invoke(null, convertToUserIdentities(selectedUser.userIdentities)) + callback.invoke(null, convertToUserIdentities(selectedUser.userIdentities)) } else { - completion.invoke() + callback.invoke() } } @ReactMethod - fun getFirstSeen( - userId: String, - completion: Callback, + override fun getFirstSeen( + mpid: String, + callback: Callback, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(Utils.parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(Utils.parseMpid(mpid)) if (selectedUser != null) { - completion.invoke(selectedUser.firstSeenTime.toString()) + callback.invoke(selectedUser.firstSeenTime.toString()) } else { - completion.invoke() + callback.invoke() } } @ReactMethod - fun getLastSeen( - userId: String, - completion: Callback, + override fun getLastSeen( + mpid: String, + callback: Callback, ) { - val selectedUser = MParticle.getInstance()?.Identity()?.getUser(Utils.parseMpid(userId)) + val selectedUser = MParticle.getInstance()?.Identity()?.getUser(Utils.parseMpid(mpid)) if (selectedUser != null) { - completion.invoke(selectedUser.lastSeenTime.toString()) + callback.invoke(selectedUser.lastSeenTime.toString()) } else { - completion.invoke() + callback.invoke() } } @ReactMethod - fun getAttributions(completion: Callback) { + override fun getAttributions(callback: Callback) { val attributionResultMap = MParticle.getInstance()?.attributionResults val map = Arguments.createMap() attributionResultMap?.let { resultMap -> @@ -412,52 +434,52 @@ class MParticleModule( map.putMap(key.toString(), attributeMap) } } - completion.invoke(map) + callback.invoke(map) } @ReactMethod - fun setOptOut(optOut: Boolean) { + override fun setOptOut(optOut: Boolean) { MParticle.getInstance()?.setOptOut(optOut) } @ReactMethod - fun getOptOut(completion: Callback) { + override fun getOptOut(callback: Callback) { val optedOut = MParticle.getInstance()?.optOut ?: false - completion.invoke(optedOut) + callback.invoke(optedOut) } @ReactMethod - fun isKitActive( - kitId: Int, - completion: Callback, + override fun isKitActive( + kitId: Double, + callback: Callback, ) { - val isActive = MParticle.getInstance()?.isKitActive(kitId) ?: false - completion.invoke(isActive) + val isActive = MParticle.getInstance()?.isKitActive(kitId.toInt()) ?: false + callback.invoke(isActive) } @ReactMethod - fun logPushRegistration( - instanceId: String?, + override fun logPushRegistration( + token: String?, senderId: String?, ) { - if (!instanceId.isNullOrEmpty() && !senderId.isNullOrEmpty()) { - MParticle.getInstance()?.logPushRegistration(instanceId, senderId) + if (!token.isNullOrEmpty() && !senderId.isNullOrEmpty()) { + MParticle.getInstance()?.logPushRegistration(token, senderId) } } @ReactMethod - fun addGDPRConsentState( - map: ReadableMap?, + override fun addGDPRConsentState( + consent: ReadableMap?, purpose: String, ) { val currentUser = MParticle.getInstance()?.Identity()?.currentUser - if (currentUser != null) { - val consent = convertToGDPRConsent(map) - if (consent != null) { + if (currentUser != null && consent != null) { + val gDPRConsent = convertToGDPRConsent(consent) + if (gDPRConsent != null) { val consentState = ConsentState .withConsentState(currentUser.consentState) - .addGDPRConsentState(purpose, consent) + .addGDPRConsentState(purpose, gDPRConsent) .build() currentUser.setConsentState(consentState) Logger.info("GDPRConsentState added, \n\t\"purpose\": $purpose\n$consentState") @@ -468,7 +490,7 @@ class MParticleModule( } @ReactMethod - fun removeGDPRConsentStateWithPurpose(purpose: String) { + override fun removeGDPRConsentStateWithPurpose(purpose: String) { val currentUser = MParticle.getInstance()?.Identity()?.currentUser if (currentUser != null) { val consentState = @@ -481,15 +503,15 @@ class MParticleModule( } @ReactMethod - fun setCCPAConsentState(map: ReadableMap?) { + override fun setCCPAConsentState(consent: ReadableMap?) { val currentUser = MParticle.getInstance()?.Identity()?.currentUser - if (currentUser != null) { - val consent = convertToCCPAConsent(map) - if (consent != null) { + if (currentUser != null && consent != null) { + val cCPAConsent = convertToCCPAConsent(consent) + if (cCPAConsent != null) { val consentState = ConsentState .withConsentState(currentUser.consentState) - .setCCPAConsentState(consent) + .setCCPAConsentState(cCPAConsent) .build() currentUser.setConsentState(consentState) Logger.info("CCPAConsentState added, \n$consentState") @@ -500,7 +522,7 @@ class MParticleModule( } @ReactMethod - fun removeCCPAConsentState() { + override fun removeCCPAConsentState() { val currentUser = MParticle.getInstance()?.Identity()?.currentUser if (currentUser != null) { val consentState = @@ -525,11 +547,10 @@ class MParticleModule( if (map?.hasKey("name") == true && map.hasKey("type")) { val name = map.getString("name") ?: return null val type = map.getInt("type") - val builder = MPEvent.Builder(name, convertEventType(type)) if (map.hasKey("category")) { - builder.category(map.getString("category")) + map.getString("category")?.let { builder.category(it) } } if (map.hasKey("duration")) { @@ -545,8 +566,10 @@ class MParticleModule( if (map.hasKey("customFlags")) { val customFlagsMap = map.getMap("customFlags") val customFlags = convertStringMap(customFlagsMap) - for ((key, value) in customFlags) { - builder.addCustomFlag(key, value) + if (customFlags != null) { + for ((key, value) in customFlags) { + builder.addCustomFlag(key, value) + } } } @@ -588,100 +611,102 @@ class MParticleModule( return null } - var builder: CommerceEvent.Builder? - - when { - isProductAction -> { - val productActionInt = map.getInt("productActionType") - val productAction = convertProductActionType(productActionInt) - val productsArray = map.getArray("products") ?: return null - val productMap = productsArray.getMap(0) - val product = convertProduct(productMap) ?: return null - val transactionAttributesMap = map.getMap("transactionAttributes") - val transactionAttributes = convertTransactionAttributes(transactionAttributesMap) - - builder = CommerceEvent.Builder(productAction, product) - transactionAttributes?.let { builder?.transactionAttributes(it) } + val builder = + when { + isProductAction -> { + val productActionInt = map.getInt("productActionType") + val productAction = convertProductActionType(productActionInt) + val productsArray = map.getArray("products") ?: return null + val productMap = productsArray.getMap(0) + val product = convertProduct(productMap) ?: return null + val transactionAttributesMap = map.getMap("transactionAttributes") + val transactionAttributes = convertTransactionAttributes(transactionAttributesMap) + val builder = + transactionAttributes?.let { + CommerceEvent.Builder(productAction, product).transactionAttributes(it) + } - for (i in 1 until productsArray.size()) { - val nextProductMap = productsArray.getMap(i) - val nextProduct = convertProduct(nextProductMap) - if (nextProduct != null) { - builder.addProduct(nextProduct) + for (i in 1 until productsArray.size()) { + val nextProductMap = productsArray.getMap(i) + val nextProduct = convertProduct(nextProductMap) + if (nextProduct != null) { + builder?.addProduct(nextProduct) + } } + builder } - } - isPromotion -> { - val promotionActionTypeInt = map.getInt("promotionActionType") - val promotionAction = convertPromotionActionType(promotionActionTypeInt) - val promotionsReadableArray = map.getArray("promotions") ?: return null - val promotionMap = promotionsReadableArray.getMap(0) - val promotion = convertPromotion(promotionMap) - builder = CommerceEvent.Builder(promotionAction, promotion) - - for (i in 1 until promotionsReadableArray.size()) { - val nextPromotionMap = promotionsReadableArray.getMap(i) - val nextPromotion = convertPromotion(nextPromotionMap) - builder.addPromotion(nextPromotion) + + isPromotion -> { + val promotionActionTypeInt = map.getInt("promotionActionType") + val promotionAction = convertPromotionActionType(promotionActionTypeInt) + val promotionsReadableArray = map.getArray("promotions") ?: return null + val promotionMap = promotionsReadableArray.getMap(0) + val promotion = convertPromotion(promotionMap) ?: return null + val builder = CommerceEvent.Builder(promotionAction, promotion) + + for (i in 1 until promotionsReadableArray.size()) { + val nextPromotionMap = promotionsReadableArray.getMap(i) + val nextPromotion = convertPromotion(nextPromotionMap) + if (nextPromotion != null) { + builder.addPromotion(nextPromotion) + } + } + builder } - } - else -> { - val impressionsArray = map.getArray("impressions") ?: return null - val impressionMap = impressionsArray.getMap(0) - val impression = convertImpression(impressionMap) ?: return null - builder = CommerceEvent.Builder(impression) - - for (i in 1 until impressionsArray.size()) { - val nextImpressionMap = impressionsArray.getMap(i) - val nextImpression = convertImpression(nextImpressionMap) - if (nextImpression != null) { - builder.addImpression(nextImpression) + + else -> { + val impressionsArray = map.getArray("impressions") ?: return null + val impressionMap = impressionsArray.getMap(0) + val impression = convertImpression(impressionMap) ?: return null + val builder = CommerceEvent.Builder(impression) + + for (i in 1 until impressionsArray.size()) { + val nextImpressionMap = impressionsArray.getMap(i) + val nextImpression = convertImpression(nextImpressionMap) + if (nextImpression != null) { + builder.addImpression(nextImpression) + } } + builder } } - } - return builder.let { b -> - if (map.hasKey("shouldUploadEvent")) { - b.shouldUploadEvent(map.getBoolean("shouldUploadEvent")) - } - if (map.hasKey("customAttributes")) { - b.customAttributes(convertStringMap(map.getMap("customAttributes"))) - } - if (map.hasKey("currency")) { - b.currency(map.getString("currency")) - } - if (map.hasKey("checkoutStep")) { - b.checkoutStep(map.getInt("checkoutStep")) - } - if (map.hasKey("checkoutOptions")) { - b.checkoutOptions(map.getString("checkoutOptions")) - } - b.build() + if (map.hasKey("shouldUploadEvent")) { + builder?.shouldUploadEvent(map.getBoolean("shouldUploadEvent")) + } + if (map.hasKey("customAttributes")) { + builder?.customAttributes(convertStringMap(map.getMap("customAttributes"))) + } + if (map.hasKey("currency")) { + map.getString("currency")?.let { builder?.currency(it) } } + if (map.hasKey("checkoutStep")) { + builder?.checkoutStep(map.getInt("checkoutStep")) + } + if (map.hasKey("checkoutOptions")) { + map.getString("checkoutOptions")?.let { builder?.checkoutOptions(it) } + } + + return builder?.build() } private fun convertProduct(map: ReadableMap?): Product? { if (map == null) return null - val name = map.getString("name") ?: return null val sku = map.getString("sku") ?: return null val unitPrice = map.getDouble("price") val builder = Product.Builder(name, sku, unitPrice) if (map.hasKey("brand")) { - val brand = map.getString("brand") - builder.brand(brand) + map.getString("brand")?.let { builder.brand(it) } } if (map.hasKey("category")) { - val category = map.getString("category") - builder.category(category) + map.getString("category")?.let { builder.category(it) } } if (map.hasKey("couponCode")) { - val couponCode = map.getString("couponCode") - builder.couponCode(couponCode) + map.getString("couponCode")?.let { builder.couponCode(it) } } if (map.hasKey("customAttributes")) { @@ -691,18 +716,15 @@ class MParticleModule( } if (map.hasKey("position")) { - val position = map.getInt("position") - builder.position(position) + builder.position(map.getInt("position")) } if (map.hasKey("quantity")) { - val quantity = map.getDouble("quantity") - builder.quantity(quantity) + builder.quantity(map.getDouble("quantity")) } if (map.hasKey("variant")) { - val variant = map.getString("variant") - builder.variant(variant) + map.getString("variant")?.let { builder.variant(it) } } return builder.build() @@ -717,7 +739,7 @@ class MParticleModule( val transactionAttributes = TransactionAttributes(transactionId) if (map.hasKey("affiliation")) { - transactionAttributes.affiliation = map.getString("affiliation") + map.getString("affiliation")?.let { transactionAttributes.affiliation = it } } if (map.hasKey("revenue")) { @@ -733,31 +755,30 @@ class MParticleModule( } if (map.hasKey("couponCode")) { - transactionAttributes.couponCode = map.getString("couponCode") + map.getString("couponCode")?.let { transactionAttributes.couponCode = it } } return transactionAttributes } - private fun convertPromotion(map: ReadableMap?): Promotion { + private fun convertPromotion(map: ReadableMap?): Promotion? { + if (map == null) return null val promotion = Promotion() - map?.let { m -> - if (m.hasKey("id")) { - promotion.id = m.getString("id") - } + if (map.hasKey("id")) { + map.getString("id")?.let { promotion.id = it } + } - if (m.hasKey("name")) { - promotion.name = m.getString("name") - } + if (map.hasKey("name")) { + map.getString("name")?.let { promotion.name = it } + } - if (m.hasKey("creative")) { - promotion.creative = m.getString("creative") - } + if (map.hasKey("creative")) { + map.getString("creative")?.let { promotion.creative = it } + } - if (m.hasKey("position")) { - promotion.position = m.getString("position") - } + if (map.hasKey("position")) { + map.getString("position")?.let { promotion.position = it } } return promotion @@ -765,7 +786,6 @@ class MParticleModule( private fun convertImpression(map: ReadableMap?): Impression? { if (map == null) return null - val listName = map.getString("impressionListName") ?: return null val productsArray = map.getArray("products") ?: return null val productMap = productsArray.getMap(0) @@ -783,52 +803,51 @@ class MParticleModule( return impression } - private fun convertStringMap(readableMap: ReadableMap?): Map { - val map = mutableMapOf() + private fun convertStringMap(readableMap: ReadableMap?): Map? { + if (readableMap == null) return null - readableMap?.let { rm -> - val iterator = rm.keySetIterator() - while (iterator.hasNextKey()) { - val key = iterator.nextKey() - when (rm.getType(key)) { - ReadableType.Null -> map[key] = "" - ReadableType.Boolean -> map[key] = rm.getBoolean(key).toString() - ReadableType.Number -> { + val map = mutableMapOf() + val iterator = readableMap.keySetIterator() + while (iterator.hasNextKey()) { + val key = iterator.nextKey() + when (readableMap.getType(key)) { + ReadableType.Null -> map[key] = "" + ReadableType.Boolean -> map[key] = readableMap.getBoolean(key).toString() + ReadableType.Number -> { + try { + map[key] = readableMap.getInt(key).toString() + } catch (e: Exception) { try { - map[key] = rm.getInt(key).toString() - } catch (_: Exception) { - try { - map[key] = rm.getDouble(key).toString() - } catch (_: Exception) { - Logger.warning("Unable to parse value for \"$key\"") - } + map[key] = readableMap.getDouble(key).toString() + } catch (ex: Exception) { + Logger.warning("Unable to parse value for \"$key\"") } } - ReadableType.String -> map[key] = rm.getString(key) ?: "" - ReadableType.Map -> Logger.warning("Maps are not supported Attribute value types") - ReadableType.Array -> Logger.warning("Lists are not supported Attribute value types") } + + ReadableType.String -> map[key] = readableMap.getString(key) ?: "" + ReadableType.Map -> Logger.warning("Maps are not supported Attribute value types") + ReadableType.Array -> Logger.warning("Lists are not supported Attribute value types") } } - return map } private fun convertUserIdentities(readableMap: ReadableMap?): Map { val map = mutableMapOf() - readableMap?.let { rm -> - val iterator = rm.keySetIterator() + if (readableMap != null) { + val iterator = readableMap.keySetIterator() while (iterator.hasNextKey()) { val key = iterator.nextKey() val identity = when (key) { "email" -> MParticle.IdentityType.Email "customerId" -> MParticle.IdentityType.CustomerId - else -> MParticle.IdentityType.parseInt(key.toIntOrNull() ?: 0) + else -> MParticle.IdentityType.parseInt(key.toInt()) } - identity.let { identityType -> - rm.getString(key)?.let { value -> - map[identityType] = value + identity.let { + readableMap.getString(key)?.let { value -> + map[it] = value } } } @@ -881,21 +900,18 @@ class MParticleModule( private fun parseMpid(longString: String): Long = try { longString.toLong() - } catch (_: NumberFormatException) { + } catch (ex: NumberFormatException) { 0L } - @Nullable - private fun convertToGDPRConsent(map: ReadableMap?): GDPRConsent? { - if (map == null) return null - - val consented: Boolean = + private fun convertToGDPRConsent(map: ReadableMap): GDPRConsent? { + val consented = try { when (map.getType("consented")) { ReadableType.Boolean -> map.getBoolean("consented") else -> map.getString("consented")?.toBoolean() ?: false } - } catch (_: Exception) { + } catch (ex: Exception) { Logger.error("failed to convert \"consented\" value to a Boolean, unable to process addGDPRConsentState") return null } @@ -903,40 +919,34 @@ class MParticleModule( val builder = GDPRConsent.builder(consented) if (map.hasKey("document")) { - val document = map.getString("document") - builder.document(document) + map.getString("document")?.let { builder.document(it) } } if (map.hasKey("hardwareId")) { - val hardwareId = map.getString("hardwareId") - builder.hardwareId(hardwareId) + map.getString("hardwareId")?.let { builder.hardwareId(it) } } if (map.hasKey("location")) { - val location = map.getString("location") - builder.location(location) + map.getString("location")?.let { builder.location(it) } } if (map.hasKey("timestamp")) { try { val timestampString = map.getString("timestamp") val timestamp = timestampString?.toLong() timestamp?.let { builder.timestamp(it) } - } catch (_: Exception) { + } catch (ex: Exception) { Logger.warning("failed to convert \"timestamp\" value to Long") } } return builder.build() } - @Nullable - private fun convertToCCPAConsent(map: ReadableMap?): CCPAConsent? { - if (map == null) return null - - val consented: Boolean = + private fun convertToCCPAConsent(map: ReadableMap): CCPAConsent? { + val consented = try { when (map.getType("consented")) { ReadableType.Boolean -> map.getBoolean("consented") else -> map.getString("consented")?.toBoolean() ?: false } - } catch (_: Exception) { + } catch (ex: Exception) { Logger.error("failed to convert \"consented\" value to a Boolean, unable to process addCCPAConsentState") return null } @@ -944,23 +954,20 @@ class MParticleModule( val builder = CCPAConsent.builder(consented) if (map.hasKey("document")) { - val document = map.getString("document") - builder.document(document) + map.getString("document")?.let { builder.document(it) } } if (map.hasKey("hardwareId")) { - val hardwareId = map.getString("hardwareId") - builder.hardwareId(hardwareId) + map.getString("hardwareId")?.let { builder.hardwareId(it) } } if (map.hasKey("location")) { - val location = map.getString("location") - builder.location(location) + map.getString("location")?.let { builder.location(it) } } if (map.hasKey("timestamp")) { try { val timestampString = map.getString("timestamp") val timestamp = timestampString?.toLong() timestamp?.let { builder.timestamp(it) } - } catch (_: Exception) { + } catch (ex: Exception) { Logger.warning("failed to convert \"timestamp\" value to Long") } } diff --git a/android/src/main/java/com/mparticle/react/MParticlePackage.kt b/android/src/main/java/com/mparticle/react/MParticlePackage.kt index 54e5dd0..b6f412b 100644 --- a/android/src/main/java/com/mparticle/react/MParticlePackage.kt +++ b/android/src/main/java/com/mparticle/react/MParticlePackage.kt @@ -43,8 +43,7 @@ class MParticlePackage : TurboReactPackage() { false, // needsEagerInit true, // hasConstants false, // isCxxModule - // BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - false, // isTurboModule + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, // isTurboModule ), ) moduleInfos.put( @@ -56,8 +55,7 @@ class MParticlePackage : TurboReactPackage() { false, // needsEagerInit true, // hasConstants false, // isCxxModule - // BuildConfig.IS_NEW_ARCHITECTURE_ENABLED - false, // isTurboModule + BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, // isTurboModule ), ) moduleInfos.toMap() diff --git a/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt b/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt index e6340e3..632e2ca 100644 --- a/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt +++ b/android/src/main/java/com/mparticle/react/rokt/MPRoktModuleImpl.kt @@ -241,6 +241,6 @@ class MPRoktModuleImpl( companion object { const val MAX_LISTENERS = 5 - const val MODULE_NAME = "MPRokt" + const val MODULE_NAME = "RNMPRokt" } } diff --git a/android/src/newarch/java/com/mparticle/react/rokt/MPRoktModule.kt b/android/src/newarch/java/com/mparticle/react/rokt/MPRoktModule.kt new file mode 100644 index 0000000..3c6c3b6 --- /dev/null +++ b/android/src/newarch/java/com/mparticle/react/rokt/MPRoktModule.kt @@ -0,0 +1,124 @@ +package com.mparticle.react.rokt + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactMethod +import com.facebook.react.bridge.ReadableMap +import com.facebook.react.bridge.ReadableType +import com.facebook.react.bridge.UiThreadUtil +import com.facebook.react.uimanager.UIManagerHelper +import com.mparticle.MParticle +import com.mparticle.WrapperSdk +import com.mparticle.react.NativeMPRoktSpec +import com.mparticle.rokt.RoktEmbeddedView +import com.mparticle.internal.Logger +import java.lang.ref.WeakReference +import java.util.concurrent.CountDownLatch + +class MPRoktModule( + private val reactContext: ReactApplicationContext, +) : NativeMPRoktSpec(reactContext) { + init { + MParticle.getInstance()?.setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "") + } + + private val impl = MPRoktModuleImpl(reactContext) + + override fun getName(): String = impl.getName() + + @ReactMethod + override fun selectPlacements( + identifier: String, + attributes: ReadableMap?, + placeholders: ReadableMap?, + roktConfig: ReadableMap?, + fontFilesMap: ReadableMap?, + ) { + if (identifier.isBlank()) { + Logger.warning("selectPlacements failed. identifier cannot be empty") + return + } + MParticle.getInstance()?.Rokt()?.events(identifier)?.let { + impl.startRoktEventListener(it, reactContext.currentActivity, identifier) + } + + // Process placeholders for Fabric + val placeholdersMap = processPlaceholders(placeholders) + val config = roktConfig?.let { impl.buildRoktConfig(it) } + + MParticle.getInstance()?.Rokt()?.selectPlacements( + identifier = identifier, + attributes = impl.readableMapToMapOfStrings(attributes), + callbacks = impl.createRoktCallback(), + embeddedViews = placeholdersMap, + fontTypefaces = null, // TODO + config = config, + ) + } + + + /** + * Process placeholders from ReadableMap to a map of Widgets for use with Rokt. + * This method handles the Fabric-specific view resolution. + */ + private fun processPlaceholders(placeholders: ReadableMap?): Map> { + val placeholdersMap = HashMap>() + + if (placeholders != null) { + // Use CountDownLatch to wait for UI thread processing + val latch = CountDownLatch(1) + + // Run view resolution on UI thread + UiThreadUtil.runOnUiThread { + try { + val iterator = placeholders.keySetIterator() + while (iterator.hasNextKey()) { + val key = iterator.nextKey() + try { + // Get the tag value as an integer + val reactTag = + when { + placeholders.getType(key) == ReadableType.Number -> + placeholders.getDouble(key).toInt() + + else -> { + Logger.warning("Invalid view tag for key: $key") + continue + } + } + + // Get the UIManager for this specific tag + val uiManager = + UIManagerHelper.getUIManagerForReactTag(reactContext, reactTag) + if (uiManager == null) { + Logger.warning("UIManager not found for tag: $reactTag") + continue + } + + // Resolve the view using the manager (now on UI thread) + val view = uiManager.resolveView(reactTag) + if (view is RoktEmbeddedView) { + placeholdersMap[key] = WeakReference(view) + Logger.debug("Successfully found Widget for key: $key with tag: $reactTag") + } else { + Logger.warning("View with tag $reactTag is not a Widget: ${view?.javaClass?.simpleName}") + } + } catch (e: Exception) { + Logger.warning("Error processing placeholder for key $key: ${e.message}") + } + } + } finally { + latch.countDown() + } + } + + try { + // Wait for UI thread to finish processing + latch.await() + } catch (e: InterruptedException) { + Logger.warning("Interrupted while waiting for UI thread: ${e.message}") + } + } + + return placeholdersMap + } +} diff --git a/android/src/newarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt b/android/src/newarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt new file mode 100644 index 0000000..96c430f --- /dev/null +++ b/android/src/newarch/java/com/mparticle/react/rokt/RoktLayoutViewManager.kt @@ -0,0 +1,22 @@ +package com.mparticle.react.rokt + +import com.facebook.react.uimanager.SimpleViewManager +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.annotations.ReactProp +import com.facebook.react.viewmanagers.RoktNativeLayoutManagerInterface +import com.mparticle.rokt.RoktEmbeddedView + +class RoktLayoutViewManager : SimpleViewManager(), + RoktNativeLayoutManagerInterface { + private val impl = RoktLayoutViewManagerImpl() + + override fun getName(): String = impl.getName() + + override fun createViewInstance(reactContext: ThemedReactContext): RoktEmbeddedView = + impl.createViewInstance(reactContext) + + @ReactProp(name = "placeholderName") + override fun setPlaceholderName(view: RoktEmbeddedView?, value: String?) { + impl.setPlaceholderName(view, value) + } +} diff --git a/android/src/oldarch/java/com/mparticle/react/NativeMPRoktSpec.kt b/android/src/oldarch/java/com/mparticle/react/NativeMPRoktSpec.kt new file mode 100644 index 0000000..a91be5f --- /dev/null +++ b/android/src/oldarch/java/com/mparticle/react/NativeMPRoktSpec.kt @@ -0,0 +1,23 @@ +package com.mparticle.react + +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReadableMap + +abstract class NativeMPRoktSpec( + reactContext: ReactApplicationContext, +) : ReactContextBaseJavaModule(reactContext) { + companion object { + private const val MODULE_NAME = "RNMPRokt" + } + + override fun getName(): String = MODULE_NAME + + abstract fun selectPlacements( + identifier: String, + attributes: ReadableMap?, + placeholders: ReadableMap?, + roktConfig: ReadableMap?, + fontFilesMap: ReadableMap?, + ) +} diff --git a/android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt b/android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt new file mode 100644 index 0000000..a81e9fd --- /dev/null +++ b/android/src/oldarch/java/com/mparticle/react/NativeMParticleSpec.kt @@ -0,0 +1,153 @@ +package com.mparticle.react + +import com.facebook.react.bridge.Callback +import com.facebook.react.bridge.ReactApplicationContext +import com.facebook.react.bridge.ReactContextBaseJavaModule +import com.facebook.react.bridge.ReadableArray +import com.facebook.react.bridge.ReadableMap + +abstract class NativeMParticleSpec( + reactContext: ReactApplicationContext, +) : ReactContextBaseJavaModule(reactContext) { + companion object { + private const val MODULE_NAME = "RNMParticle" + } + + override fun getName(): String = MODULE_NAME + + abstract fun upload() + + abstract fun setUploadInterval(uploadInterval: Double) + + abstract fun logEvent( + eventName: String, + eventType: Double, + attributes: ReadableMap?, + ) + + abstract fun logMPEvent(event: ReadableMap?) + + abstract fun logCommerceEvent(commerceEvent: ReadableMap?) + + abstract fun logScreenEvent( + screenName: String, + attributes: ReadableMap?, + shouldUploadEvent: Boolean, + ) + + abstract fun setATTStatus(status: Double) + + abstract fun setATTStatusWithCustomTimestamp( + status: Double, + timestamp: Double, + ) + + abstract fun setOptOut(optOut: Boolean) + + abstract fun getOptOut(callback: Callback) + + abstract fun addGDPRConsentState( + consent: ReadableMap?, + purpose: String, + ) + + abstract fun removeGDPRConsentStateWithPurpose(purpose: String) + + abstract fun setCCPAConsentState(consent: ReadableMap?) + + abstract fun removeCCPAConsentState() + + abstract fun isKitActive( + kitId: Double, + callback: Callback, + ) + + abstract fun getAttributions(callback: Callback) + + abstract fun logPushRegistration( + token: String?, + senderId: String?, + ) + + abstract fun getSession(callback: Callback) + + abstract fun setLocation( + latitude: Double, + longitude: Double, + ) + + abstract fun setUserAttribute( + mpid: String, + key: String, + value: String, + ) + + abstract fun setUserAttributeArray( + mpid: String, + key: String, + value: ReadableArray?, + ) + + abstract fun getUserAttributes( + mpid: String, + callback: Callback, + ) + + abstract fun setUserTag( + mpid: String, + tag: String, + ) + + abstract fun incrementUserAttribute( + mpid: String, + key: String, + value: Double, + ) + + abstract fun removeUserAttribute( + mpid: String, + key: String, + ) + + abstract fun getUserIdentities( + mpid: String, + callback: Callback, + ) + + abstract fun getFirstSeen( + mpid: String, + callback: Callback, + ) + + abstract fun getLastSeen( + mpid: String, + callback: Callback, + ) + + abstract fun getCurrentUserWithCompletion(callback: Callback) + + abstract fun identify( + identityRequest: ReadableMap?, + callback: Callback, + ) + + abstract fun login( + identityRequest: ReadableMap?, + callback: Callback, + ) + + abstract fun logout( + identityRequest: ReadableMap?, + callback: Callback, + ) + + abstract fun modify( + identityRequest: ReadableMap?, + callback: Callback, + ) + + abstract fun aliasUsers( + aliasRequest: ReadableMap?, + callback: Callback, + ) +} diff --git a/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt b/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt index 15135bc..dd44640 100644 --- a/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt +++ b/android/src/oldarch/java/com/mparticle/react/rokt/MPRoktModule.kt @@ -1,19 +1,20 @@ package com.mparticle.react.rokt import com.facebook.react.bridge.ReactApplicationContext -import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableMap import com.facebook.react.uimanager.NativeViewHierarchyManager import com.facebook.react.uimanager.UIManagerModule import com.mparticle.MParticle import com.mparticle.WrapperSdk +import com.mparticle.internal.Logger +import com.mparticle.react.NativeMPRoktSpec import com.mparticle.rokt.RoktEmbeddedView import java.lang.ref.WeakReference class MPRoktModule( private val reactContext: ReactApplicationContext, -) : ReactContextBaseJavaModule(reactContext) { +) : NativeMPRoktSpec(reactContext) { init { MParticle.getInstance()?.setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "") } @@ -23,7 +24,7 @@ class MPRoktModule( override fun getName(): String = impl.getName() @ReactMethod - fun selectPlacements( + override fun selectPlacements( identifier: String, attributes: ReadableMap?, placeholders: ReadableMap?, @@ -31,6 +32,7 @@ class MPRoktModule( fontFilesMap: ReadableMap?, ) { if (identifier.isBlank()) { + Logger.warning("selectPlacements failed. identifier cannot be empty") return } val uiManager = reactContext.getNativeModule(UIManagerModule::class.java) diff --git a/ios/RNMParticle/RNMPRokt.m b/ios/RNMParticle/RNMPRokt.m index 95585c6..fcb61b8 100644 --- a/ios/RNMParticle/RNMPRokt.m +++ b/ios/RNMParticle/RNMPRokt.m @@ -34,7 +34,7 @@ @implementation RNMPRokt RCT_EXTERN void RCTRegisterModule(Class); + (NSString *)moduleName { - return @"MPRokt"; + return @"RNMPRokt"; } + (void)load { diff --git a/js/index.tsx b/js/index.tsx index e8bd3e7..31dfcd4 100644 --- a/js/index.tsx +++ b/js/index.tsx @@ -17,7 +17,7 @@ import type { import { getNativeModule } from './utils/architecture'; const MParticleModule: NativeMParticleInterface = - getNativeModule('RNMParticle', 'MParticle'); + getNativeModule('RNMParticle'); // ******** Types ******** export interface UserAttributes extends NativeUserAttributes { diff --git a/js/rokt/rokt.ts b/js/rokt/rokt.ts index 6bfc145..3c62d88 100644 --- a/js/rokt/rokt.ts +++ b/js/rokt/rokt.ts @@ -2,7 +2,7 @@ import { NativeModules } from 'react-native'; import { getNativeModule } from '../utils/architecture'; import type { Spec as NativeMPRoktInterface } from '../codegenSpecs/rokt/NativeMPRokt'; -const MPRokt = getNativeModule('MPRokt', 'MPRokt'); +const MPRokt = getNativeModule('RNMPRokt'); export abstract class Rokt { /** diff --git a/js/utils/architecture.ts b/js/utils/architecture.ts index 52200eb..beb9297 100644 --- a/js/utils/architecture.ts +++ b/js/utils/architecture.ts @@ -8,16 +8,12 @@ export const isNewArchitecture = global.__turboModuleProxy != null; /** * Gets the native module for both old and new architectures - * @param turboModuleName The name of the module in new architecture - * @param legacyModuleName The name of the module in old architecture + * @param moduleName The name of the module * @returns The native module */ -export function getNativeModule( - turboModuleName: string, - legacyModuleName: string -): T { +export function getNativeModule(moduleName: string): T { if (isNewArchitecture) { - return TurboModuleRegistry.getEnforcing(turboModuleName); + return TurboModuleRegistry.getEnforcing(moduleName); } - return NativeModules[legacyModuleName] as T; + return NativeModules[moduleName] as T; } diff --git a/sample/android/gradle.properties b/sample/android/gradle.properties index 9fb1566..5e24e3a 100644 --- a/sample/android/gradle.properties +++ b/sample/android/gradle.properties @@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 # your application. You should enable this flag either if you want # to write custom TurboModules/Fabric components OR use libraries that # are providing them. -newArchEnabled=false +newArchEnabled=true # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead.