Skip to content

Commit 14861ba

Browse files
Merge pull request #23 from SourcePointUSA/DIA-5954_implement_user_inactive_callback
DIA-5954 implement `onMessageInactivityTimeout ` callback
2 parents 9c28f0e + 4b86ca6 commit 14861ba

File tree

10 files changed

+47
-30
lines changed

10 files changed

+47
-30
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Refer to the table below regarding the different campaigns that can be implement
8888
| `onAction(callback: (action: string) => {})` | Called when the user takes an action (e.g. Accept All) within the consent message. `action: string` is going to be replaced with an enum. |
8989
| `onSPUIFinished(callback: () => {})` | Called when the native SDKs is done removing the consent UI from the foreground. |
9090
| `onFinished(callback: () => {})` | Called when all UI and network processes are finished. User consent is stored on the local storage of each platform (`UserDefaults` for iOS and `SharedPrefs` for Android). And it is safe to retrieve consent data with `getUserData` |
91+
| `onMessageInactivityTimeout(callback: () => {})` | Called when the user becomes inactive while viewing a consent message. This allows your app to respond to user inactivity events. |
9192
| `onError(callback: (description: string) => {})` | Called if something goes wrong. |
9293
9394
### Call `loadMessages`
@@ -255,6 +256,9 @@ export default function App() {
255256
consentManager.current?.onAction(({ actionType }) => {
256257
console.log(`User took action ${actionType}`)
257258
});
259+
consentManager.current?.onMessageInactivityTimeout(() => {
260+
console.log("User became inactive")
261+
});
258262
consentManager.current?.onError(console.error)
259263

260264
consentManager.current?.loadMessage();

ReactNativeCmp.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Pod::Spec.new do |s|
1515
s.platforms = { :ios => min_ios_version_supported }
1616
s.source = { :git => "https://github.com/SourcePointUSA/react-native-sourcepoint-cmp.git", :tag => "#{s.version}" }
1717

18-
s.dependency "ConsentViewController", "7.11.1"
18+
s.dependency "ConsentViewController", "7.12.0"
1919
s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
2020
s.private_header_files = "ios/**/*.h"
2121

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies {
7777
implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3"
7878
implementation "org.jetbrains.kotlinx:kotlinx-datetime:0.6.1"
7979

80-
implementation "com.sourcepoint.cmplibrary:cmplibrary:7.15.2"
80+
implementation "com.sourcepoint.cmplibrary:cmplibrary:7.15.3"
8181
}
8282

8383
react {

android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ import com.facebook.react.bridge.Arguments.createMap
55
import com.facebook.react.bridge.Callback
66
import com.facebook.react.bridge.Promise
77
import com.facebook.react.bridge.ReactApplicationContext
8-
import com.facebook.react.bridge.ReactMethod
9-
import com.facebook.react.bridge.ReadableMap
108
import com.facebook.react.bridge.ReadableArray
11-
import com.facebook.react.module.annotations.ReactModule
12-
import com.sourcepoint.cmplibrary.NativeMessageController
9+
import com.facebook.react.bridge.ReadableMap
1310
import com.sourcepoint.cmplibrary.SpClient
1411
import com.sourcepoint.cmplibrary.SpConsentLib
15-
import com.sourcepoint.cmplibrary.core.nativemessage.MessageStructure
1612
import com.sourcepoint.cmplibrary.creation.ConfigOption.SUPPORT_LEGACY_USPSTRING
1713
import com.sourcepoint.cmplibrary.creation.SpConfigDataBuilder
1814
import com.sourcepoint.cmplibrary.creation.makeConsentLib
@@ -23,22 +19,19 @@ import com.sourcepoint.cmplibrary.util.clearAllData
2319
import com.sourcepoint.cmplibrary.util.userConsents
2420
import com.sourcepoint.reactnativecmp.arguments.BuildOptions
2521
import com.sourcepoint.reactnativecmp.arguments.toList
26-
import com.sourcepoint.reactnativecmp.consents.RNSPUserData
2722
import com.sourcepoint.reactnativecmp.consents.RNSPGDPRConsent
28-
import org.json.JSONObject
23+
import com.sourcepoint.reactnativecmp.consents.RNSPUserData
2924

3025
data class SPLoadMessageParams(val authId: String?) {
3126
constructor(fromReadableMap: ReadableMap?) : this(authId = fromReadableMap?.getString("authId"))
3227
}
3328

34-
@ReactModule(name = ReactNativeCmpModule.NAME)
3529
class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactNativeCmpSpec(reactContext),
3630
SpClient {
3731
private var spConsentLib: SpConsentLib? = null
3832

3933
override fun getName() = NAME
4034

41-
@ReactMethod
4235
override fun build(
4336
accountId: Double,
4437
propertyId: Double,
@@ -84,7 +77,6 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
8477
reactApplicationContext.runOnUiQueueThread(runnable)
8578
}
8679

87-
@ReactMethod
8880
override fun loadMessage(params: ReadableMap?) {
8981
val parsedParams = SPLoadMessageParams(fromReadableMap = params)
9082

@@ -93,22 +85,18 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
9385
}
9486
}
9587

96-
@ReactMethod
9788
override fun clearLocalData() {
9889
clearAllData(reactApplicationContext)
9990
}
10091

101-
@ReactMethod
10292
override fun getUserData(promise: Promise) {
10393
promise.resolve(userConsentsToWriteableMap(userConsents(reactApplicationContext)))
10494
}
10595

106-
@ReactMethod
10796
override fun loadGDPRPrivacyManager(pmId: String) {
10897
runOnMainThread { spConsentLib?.loadPrivacyManager(pmId, GDPR) }
10998
}
11099

111-
@ReactMethod
112100
override fun loadUSNatPrivacyManager(pmId: String) {
113101
runOnMainThread { spConsentLib?.loadPrivacyManager(pmId, USNAT) }
114102
}
@@ -125,7 +113,12 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
125113
runOnMainThread { spConsentLib?.dismissMessage() }
126114
}
127115

128-
override fun postCustomConsentGDPR(vendors: ReadableArray, categories: ReadableArray, legIntCategories: ReadableArray, callback: Callback) {
116+
override fun postCustomConsentGDPR(
117+
vendors: ReadableArray,
118+
categories: ReadableArray,
119+
legIntCategories: ReadableArray,
120+
callback: Callback
121+
) {
129122
runOnMainThread {
130123
spConsentLib?.customConsentGDPR(
131124
vendors.toList(),
@@ -142,7 +135,12 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
142135
}
143136
}
144137

145-
override fun postDeleteCustomConsentGDPR(vendors: ReadableArray, categories: ReadableArray, legIntCategories: ReadableArray, callback: Callback) {
138+
override fun postDeleteCustomConsentGDPR(
139+
vendors: ReadableArray,
140+
categories: ReadableArray,
141+
legIntCategories: ReadableArray,
142+
callback: Callback)
143+
{
146144
runOnMainThread {
147145
spConsentLib?.deleteCustomConsentTo(
148146
vendors.toList(),
@@ -177,20 +175,16 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
177175
emitOnError(createMap().apply { putString("description", error.message) })
178176
}
179177

180-
@Deprecated("onMessageReady callback will be removed in favor of onUIReady. Currently this callback is disabled.")
181-
override fun onMessageReady(message: JSONObject) {}
182-
183-
override fun onNativeMessageReady(
184-
message: MessageStructure,
185-
messageController: NativeMessageController
186-
) {}
187-
188178
override fun onNoIntentActivitiesFound(url: String) {}
189179

190180
override fun onSpFinished(sPConsents: SPConsents) {
191181
emitOnFinished()
192182
}
193183

184+
override fun onMessageInactivityTimeout() {
185+
emitOnMessageInactivityTimeout()
186+
}
187+
194188
override fun onUIFinished(view: View) {
195189
spConsentLib?.removeView(view)
196190
emitOnSPUIFinished()

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- boost (1.84.0)
3-
- ConsentViewController (7.11.1):
3+
- ConsentViewController (7.12.0):
44
- Down (~> 0.11.0)
55
- SPMobileCore (= 0.1.11)
66
- DoubleConversion (1.1.6)
@@ -1660,7 +1660,7 @@ PODS:
16601660
- React-perflogger (= 0.79.2)
16611661
- React-utils (= 0.79.2)
16621662
- ReactNativeCmp (1.0.4):
1663-
- ConsentViewController (= 7.11.1)
1663+
- ConsentViewController (= 7.12.0)
16641664
- DoubleConversion
16651665
- glog
16661666
- hermes-engine
@@ -1919,7 +1919,7 @@ EXTERNAL SOURCES:
19191919

19201920
SPEC CHECKSUMS:
19211921
boost: 7e761d76ca2ce687f7cc98e698152abd03a18f90
1922-
ConsentViewController: 6cd17ebf78b80e7d32bf3d6b0b46d20a40e8cad9
1922+
ConsentViewController: 9adf0d8de93022115c3a398e2b465870ee951a1d
19231923
DoubleConversion: cb417026b2400c8f53ae97020b2be961b59470cb
19241924
fast_float: 06eeec4fe712a76acc9376682e4808b05ce978b6
19251925
FBLazyVector: 84b955f7b4da8b895faf5946f73748267347c975
@@ -1989,7 +1989,7 @@ SPEC CHECKSUMS:
19891989
ReactAppDependencyProvider: 04d5eb15eb46be6720e17a4a7fa92940a776e584
19901990
ReactCodegen: c63eda03ba1d94353fb97b031fc84f75a0d125ba
19911991
ReactCommon: 76d2dc87136d0a667678668b86f0fca0c16fdeb0
1992-
ReactNativeCmp: 8502676551832d19d227fa2b161b4c7354cd686c
1992+
ReactNativeCmp: 5d2aee1d86992ceb88690649e0bdcf55920ca62a
19931993
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
19941994
SPMobileCore: 220d109e404cb17169f7e26f2a34c6022b80079a
19951995
Yoga: c758bfb934100bb4bf9cbaccb52557cee35e8bdf

example/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export default function App() {
8888
console.log(`action: ${actionType}`)
8989
);
9090

91+
consentManager.current?.onMessageInactivityTimeout(() => {
92+
console.log("User inactive");
93+
});
94+
9195
consentManager.current?.onError((description) => {
9296
setSDKStatus(SDKStatus.Errored);
9397
console.error(description);

ios/RNSourcepointCmp.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import React
3838
func onSPUIReady()
3939
func onSPUIFinished()
4040
func onFinished()
41+
func onMessageInactivityTimeout()
4142
func onError(description: String)
4243
}
4344

@@ -143,6 +144,10 @@ import React
143144
delegate?.onFinished()
144145
}
145146

147+
public func onMessageInactivityTimeout() {
148+
delegate?.onMessageInactivityTimeout()
149+
}
150+
146151
public func onError(error: SPError) {
147152
print("Something went wrong", error)
148153
delegate?.onError(description: error.description)
@@ -176,6 +181,10 @@ private class CMPDelegateHandler: NSObject, SPDelegate {
176181
parent?.onSPFinished(userData: userData)
177182
}
178183

184+
func onMessageInactivityTimeout() {
185+
parent?.onMessageInactivityTimeout()
186+
}
187+
179188
func onError(error: SPError) {
180189
parent?.onError(error: error)
181190
}

ios/ReactNativeCmp.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ - (void)onFinished {
136136
[self emitOnFinished];
137137
}
138138

139+
- (void)onMessageInactivityTimeout {
140+
[self emitOnMessageInactivityTimeout];
141+
}
142+
139143
- (void)onSPUIFinished {
140144
[self emitOnSPUIFinished];
141145
}

src/NativeReactNativeCmp.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ export interface Spec extends TurboModule {
233233
readonly onSPUIReady: EventEmitter<void>;
234234
readonly onSPUIFinished: EventEmitter<void>;
235235
readonly onFinished: EventEmitter<void>;
236+
readonly onMessageInactivityTimeout: EventEmitter<void>;
236237
readonly onError: EventEmitter<{ description: string }>;
237238
}
238239

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,6 @@ export default class SPConsentManager implements Spec {
8282
onSPUIReady: EventEmitter<void> = ReactNativeCmp.onSPUIReady;
8383
onSPUIFinished: EventEmitter<void> = ReactNativeCmp.onSPUIFinished;
8484
onFinished: EventEmitter<void> = ReactNativeCmp.onFinished;
85+
onMessageInactivityTimeout: EventEmitter<void> = ReactNativeCmp.onMessageInactivityTimeout;
8586
onError: EventEmitter<{ description: string }> = ReactNativeCmp.onError;
8687
}

0 commit comments

Comments
 (0)