Skip to content

Commit cf17e96

Browse files
committed
feat: Rokt Embedded layout support in Android with new architecture disabled
1 parent 4b07777 commit cf17e96

24 files changed

+1008
-3792
lines changed

.npmignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ yarn.lock
5858
tsconfig.json
5959
release.sh
6060

61-
# TypeScript source files (compiled to lib/)
62-
js/
63-
6461
# Development and test files
6562
**/*.test.ts
6663
**/*.test.tsx

android/build.gradle

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ sonarqube {
2323
}
2424
}
2525

26+
def isNewArchitectureEnabled() {
27+
// React Native 0.80+ uses this standard detection approach
28+
return project.hasProperty("newArchEnabled") && project.newArchEnabled.toBoolean()
29+
}
30+
2631
def supportsNamespace() {
2732
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
2833
def major = parsed[0].toInteger()
@@ -39,6 +44,9 @@ def supportsNamespace() {
3944
// apply plugin: 'org.jlleitschuh.gradle.ktlint'
4045
apply plugin: 'com.android.library'
4146
apply plugin: 'kotlin-android'
47+
//if (isNewArchitectureEnabled()) {
48+
// apply plugin: 'com.facebook.react'
49+
//}
4250

4351
android {
4452
if (supportsNamespace()) {
@@ -57,6 +65,16 @@ android {
5765
targetSdkVersion 33
5866
versionCode 2
5967
versionName "2.0.0"
68+
//buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
69+
}
70+
sourceSets {
71+
main {
72+
//if (isNewArchitectureEnabled()) {
73+
// java.srcDirs += ['src/newarch/java']
74+
//} else {
75+
java.srcDirs += ['src/oldarch/java']
76+
//}
77+
}
6078
}
6179

6280
compileOptions {
@@ -100,6 +118,7 @@ dependencies {
100118
//
101119
// compile 'com.mparticle:android-example-kit:REPLACEME'
102120
//
121+
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.1"
103122

104123
testImplementation 'org.mockito:mockito-core:5.8.0'
105124
androidTestImplementation 'org.mockito:mockito-android:5.8.0'

android/src/main/java/com/mparticle/react/MParticleModule.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
public class MParticleModule extends ReactContextBaseJavaModule {
5151

5252

53+
public static final String MODULE_NAME = "MParticle";
5354
private final static String LOG_TAG = "MParticleModule";
5455

5556
ReactApplicationContext reactContext;
@@ -61,7 +62,7 @@ public MParticleModule(ReactApplicationContext reactContext) {
6162

6263
@Override
6364
public String getName() {
64-
return "MParticle";
65+
return MODULE_NAME;
6566
}
6667

6768
@ReactMethod

android/src/main/java/com/mparticle/react/MParticlePackage.java

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package com.mparticle.react
2+
3+
import com.facebook.react.TurboReactPackage
4+
import com.facebook.react.bridge.ModuleSpec
5+
import com.facebook.react.bridge.NativeModule
6+
import com.facebook.react.bridge.ReactApplicationContext
7+
import com.facebook.react.module.model.ReactModuleInfo
8+
import com.facebook.react.module.model.ReactModuleInfoProvider
9+
import com.facebook.react.uimanager.ViewManager
10+
import com.mparticle.react.rokt.MPRoktModule
11+
import com.mparticle.react.rokt.RoktLayoutViewManager
12+
13+
class MParticlePackage : TurboReactPackage() {
14+
15+
override fun getModule(
16+
name: String,
17+
reactContext: ReactApplicationContext,
18+
): NativeModule? {
19+
return when (name) {
20+
MParticleModule.MODULE_NAME -> {
21+
MParticleModule(reactContext)
22+
}
23+
24+
MPRoktModule.MODULE_NAME -> {
25+
MPRoktModule(reactContext)
26+
}
27+
28+
else -> null
29+
}
30+
}
31+
32+
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
33+
listOf(RoktLayoutViewManager())
34+
35+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider? = ReactModuleInfoProvider {
36+
val moduleInfos: MutableMap<String, ReactModuleInfo> =
37+
HashMap()
38+
moduleInfos.put(
39+
MParticleModule.MODULE_NAME, ReactModuleInfo(
40+
MParticleModule.MODULE_NAME,
41+
MParticleModule.MODULE_NAME,
42+
true, // canOverrideExistingModule
43+
false, // needsEagerInit
44+
true, // hasConstants
45+
false, // isCxxModule
46+
/*BuildConfig.IS_NEW_ARCHITECTURE_ENABLED*/false, // isTurboModule
47+
)
48+
)
49+
moduleInfos.put(
50+
MPRoktModule.MODULE_NAME,
51+
ReactModuleInfo(
52+
MPRoktModule.MODULE_NAME,
53+
MPRoktModule.MODULE_NAME,
54+
true, // canOverrideExistingModule
55+
false, // needsEagerInit
56+
true, // hasConstants
57+
false, // isCxxModule
58+
/*BuildConfig.IS_NEW_ARCHITECTURE_ENABLED*/false, // isTurboModule
59+
)
60+
)
61+
moduleInfos.toMap()
62+
}
63+
64+
override fun getViewManagers(reactContext: ReactApplicationContext?): List<ModuleSpec?>? =
65+
listOf(
66+
ModuleSpec.viewManagerSpec { RoktLayoutViewManager() }
67+
)
68+
}

android/src/main/java/com/mparticle/react/rokt/MPRoktModule.kt

Lines changed: 0 additions & 76 deletions
This file was deleted.

0 commit comments

Comments
 (0)