Skip to content

Commit cc9b365

Browse files
committed
Add spec wrapper
1 parent 36c40c6 commit cc9b365

File tree

10 files changed

+1025
-1021
lines changed

10 files changed

+1025
-1021
lines changed

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

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

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

Lines changed: 879 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class MParticlePackage : TurboReactPackage() {
4343
false, // needsEagerInit
4444
true, // hasConstants
4545
false, // isCxxModule
46-
// BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
47-
false, // isTurboModule
46+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, // isTurboModule
4847
),
4948
)
5049
moduleInfos.put(
@@ -56,8 +55,7 @@ class MParticlePackage : TurboReactPackage() {
5655
false, // needsEagerInit
5756
true, // hasConstants
5857
false, // isCxxModule
59-
// BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
60-
false, // isTurboModule
58+
BuildConfig.IS_NEW_ARCHITECTURE_ENABLED, // isTurboModule
6159
),
6260
)
6361
moduleInfos.toMap()

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
package com.mparticle.react.rokt
22

33
import com.facebook.react.bridge.ReactApplicationContext
4-
import com.facebook.react.bridge.ReactContextBaseJavaModule
54
import com.facebook.react.bridge.ReactMethod
65
import com.facebook.react.bridge.ReadableMap
76
import com.facebook.react.bridge.ReadableType
87
import com.facebook.react.bridge.UiThreadUtil
9-
import com.facebook.react.uimanager.NativeViewHierarchyManager
108
import com.facebook.react.uimanager.UIManagerHelper
11-
import com.facebook.react.uimanager.UIManagerModule
129
import com.mparticle.MParticle
1310
import com.mparticle.WrapperSdk
1411
import com.mparticle.react.NativeMPRoktSpec
Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,22 @@
11
package com.mparticle.react.rokt
22

3-
import com.facebook.react.common.MapBuilder
43
import com.facebook.react.uimanager.SimpleViewManager
54
import com.facebook.react.uimanager.ThemedReactContext
6-
import com.facebook.react.uimanager.ViewGroupManager
5+
import com.facebook.react.uimanager.annotations.ReactProp
6+
import com.facebook.react.viewmanagers.RoktNativeLayoutManagerInterface
77
import com.mparticle.rokt.RoktEmbeddedView
88

9-
class RoktLayoutViewManager : SimpleViewManager<RoktEmbeddedView>() {
9+
class RoktLayoutViewManager : SimpleViewManager<RoktEmbeddedView>(),
10+
RoktNativeLayoutManagerInterface<RoktEmbeddedView> {
1011
private val impl = RoktLayoutViewManagerImpl()
1112

1213
override fun getName(): String = impl.getName()
1314

14-
override fun createViewInstance(reactContext: ThemedReactContext): RoktEmbeddedView = impl.createViewInstance(reactContext)
15+
override fun createViewInstance(reactContext: ThemedReactContext): RoktEmbeddedView =
16+
impl.createViewInstance(reactContext)
1517

16-
override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? =
17-
MapBuilder
18-
.builder<String, Any>()
19-
.put(
20-
RoktLayoutViewManagerImpl.EVENT_HEIGHT_CHANGED,
21-
MapBuilder.of("registrationName", RoktLayoutViewManagerImpl.EVENT_HEIGHT_CHANGED),
22-
).put(
23-
RoktLayoutViewManagerImpl.EVENT_MARGIN_CHANGED,
24-
MapBuilder.of("registrationName", RoktLayoutViewManagerImpl.EVENT_MARGIN_CHANGED),
25-
).build()
26-
27-
//override fun needsCustomLayoutForChildren(): Boolean = false
28-
29-
fun setPlaceholderName(
30-
view: RoktEmbeddedView?,
31-
value: String?,
32-
) {
18+
@ReactProp(name = "placeholderName")
19+
override fun setPlaceholderName(view: RoktEmbeddedView?, value: String?) {
3320
impl.setPlaceholderName(view, value)
3421
}
3522
}
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package com.mparticle.react
2+
3+
import com.facebook.react.bridge.Callback
4+
import com.facebook.react.bridge.ReactApplicationContext
5+
import com.facebook.react.bridge.ReactContextBaseJavaModule
6+
import com.facebook.react.bridge.ReadableArray
7+
import com.facebook.react.bridge.ReadableMap
8+
9+
abstract class NativeMParticleSpec(reactContext: ReactApplicationContext) :
10+
ReactContextBaseJavaModule(reactContext) {
11+
12+
companion object {
13+
private const val MODULE_NAME = "MPRokt"
14+
}
15+
16+
override fun getName(): String {
17+
return MODULE_NAME
18+
}
19+
20+
abstract fun upload()
21+
22+
abstract fun setUploadInterval(uploadInterval: Double)
23+
24+
abstract fun logEvent(
25+
eventName: String,
26+
eventType: Double,
27+
attributes: ReadableMap?
28+
)
29+
30+
abstract fun logMPEvent(event: ReadableMap?)
31+
32+
abstract fun logCommerceEvent(commerceEvent: ReadableMap?)
33+
34+
abstract fun logScreenEvent(
35+
screenName: String,
36+
attributes: ReadableMap?,
37+
shouldUploadEvent: Boolean
38+
)
39+
40+
abstract fun setATTStatus(status: Double)
41+
42+
abstract fun setATTStatusWithCustomTimestamp(status: Double, timestamp: Double)
43+
44+
abstract fun setOptOut(optOut: Boolean)
45+
46+
abstract fun getOptOut(callback: Callback)
47+
48+
abstract fun addGDPRConsentState(
49+
consent: ReadableMap?,
50+
purpose: String
51+
)
52+
53+
abstract fun removeGDPRConsentStateWithPurpose(purpose: String)
54+
55+
abstract fun setCCPAConsentState(consent: ReadableMap?)
56+
57+
abstract fun removeCCPAConsentState()
58+
59+
abstract fun isKitActive(kitId: Double, callback: Callback)
60+
61+
abstract fun getAttributions(callback: Callback)
62+
63+
abstract fun logPushRegistration(token: String?, senderId: String?)
64+
65+
abstract fun getSession(callback: Callback)
66+
67+
abstract fun setLocation(latitude: Double, longitude: Double)
68+
69+
abstract fun setUserAttribute(
70+
mpid: String,
71+
key: String,
72+
value: String
73+
)
74+
75+
abstract fun setUserAttributeArray(
76+
mpid: String,
77+
key: String,
78+
value: ReadableArray?
79+
)
80+
81+
abstract fun getUserAttributes(
82+
mpid: String,
83+
callback: Callback
84+
)
85+
86+
abstract fun setUserTag(mpid: String, tag: String)
87+
88+
abstract fun incrementUserAttribute(
89+
mpid: String,
90+
key: String,
91+
value: Double
92+
)
93+
94+
abstract fun removeUserAttribute(mpid: String, key: String)
95+
96+
abstract fun getUserIdentities(
97+
mpid: String,
98+
callback: Callback
99+
)
100+
101+
abstract fun getFirstSeen(mpid: String, callback: Callback)
102+
103+
abstract fun getLastSeen(mpid: String, callback: Callback)
104+
105+
abstract fun getCurrentUserWithCompletion(callback: Callback)
106+
107+
abstract fun identify(
108+
identityRequest: ReadableMap?,
109+
callback: Callback
110+
)
111+
112+
abstract fun login(
113+
identityRequest: ReadableMap?,
114+
callback: Callback
115+
)
116+
117+
abstract fun logout(
118+
identityRequest: ReadableMap?,
119+
callback: Callback
120+
)
121+
122+
abstract fun modify(
123+
identityRequest: ReadableMap?,
124+
callback: Callback
125+
)
126+
127+
abstract fun aliasUsers(
128+
aliasRequest: ReadableMap?,
129+
callback: Callback
130+
)
131+
}

js/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { NativeModules } from 'react-native';
21
import {
32
Rokt,
43
RoktConfigBuilder,
@@ -7,8 +6,9 @@ import {
76
} from './rokt/rokt';
87
import RoktLayoutView from './rokt/rokt-layout-view';
98
import type { Spec } from './specs/NativeMParticle';
9+
import NativeMParticle from './specs/NativeMParticle';
1010

11-
const MParticleModule: Spec = NativeModules.MParticle;
11+
const MParticleModule: Spec = NativeMParticle;
1212

1313
// ******** Types ********
1414
export interface UserAttributes {
@@ -241,7 +241,7 @@ class User {
241241
return this.userId;
242242
}
243243

244-
setUserAttribute(key: string, value: string | number | boolean | string[]) {
244+
setUserAttribute(key: string, value: string) {
245245
if (Array.isArray(value)) {
246246
MParticleModule.setUserAttributeArray(this.userId, key, value);
247247
} else {

js/specs/NativeMParticle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export interface Spec extends TurboModule {
137137
setLocation(latitude: number, longitude: number): void;
138138

139139
// User Methods
140-
setUserAttribute(mpid: string, key: string, value: Object): void;
140+
setUserAttribute(mpid: string, key: string, value: string): void;
141141
setUserAttributeArray(mpid: string, key: string, value: Array<string>): void;
142142
getUserAttributes(mpid: string, callback: (error: CallbackError | null, result: UserAttributes | null) => void): void;
143143
setUserTag(mpid: string, tag: string): void;
File renamed without changes.

sample/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
3232
# your application. You should enable this flag either if you want
3333
# to write custom TurboModules/Fabric components OR use libraries that
3434
# are providing them.
35-
newArchEnabled=false
35+
newArchEnabled=true
3636

3737
# Use this property to enable or disable the Hermes JS engine.
3838
# If set to false, you will be using JSC instead.

0 commit comments

Comments
 (0)