@cavlyn/react-native-sdk 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,7 @@ React Native native bridge for Cavlyn dynamic links, Universal Links routing, Ap
17
17
  s.source_files = 'ios/**/*.{h,m,mm,swift}'
18
18
  s.swift_version = '5.9'
19
19
  s.weak_frameworks = 'AdServices'
20
+ s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES' }
20
21
 
21
22
  s.dependency 'React-Core'
22
23
  end
@@ -1,12 +1,17 @@
1
+ def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '2.0.21'
2
+
3
+ // Only declare plugin classpaths when built standalone; as a dependency of a host app,
4
+ // the app's own AGP / Kotlin plugin versions are used (avoids version clashes).
1
5
  buildscript {
2
- ext.kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : '2.0.21'
3
- repositories {
4
- google()
5
- mavenCentral()
6
- }
7
- dependencies {
8
- classpath 'com.android.tools.build:gradle:8.7.3'
9
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
6
+ if (project == rootProject) {
7
+ repositories {
8
+ google()
9
+ mavenCentral()
10
+ }
11
+ dependencies {
12
+ classpath 'com.android.tools.build:gradle:8.7.3'
13
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21"
14
+ }
10
15
  }
11
16
  }
12
17
 
@@ -39,6 +39,7 @@ class CavlynReactNativeModule(
39
39
  @Volatile private var apiKey: String = ""
40
40
  @Volatile private var apiBaseUrl: String = DEFAULT_API_BASE_URL
41
41
  @Volatile private var listenerCount = 0
42
+ @Volatile private var pendingEmit: ParsedLink? = null
42
43
 
43
44
  init {
44
45
  reactContext.addActivityEventListener(this)
@@ -181,6 +182,12 @@ class CavlynReactNativeModule(
181
182
  @ReactMethod
182
183
  fun addListener(eventName: String) {
183
184
  listenerCount += 1
185
+ // Deliver a link (e.g. cold-start) that arrived before JS subscribed.
186
+ val pending = pendingEmit
187
+ if (pending != null) {
188
+ pendingEmit = null
189
+ emitLinkToJs(pending)
190
+ }
184
191
  }
185
192
 
186
193
  @ReactMethod
@@ -232,7 +239,10 @@ class CavlynReactNativeModule(
232
239
  }
233
240
 
234
241
  private fun emitLinkToJs(link: ParsedLink) {
235
- if (listenerCount <= 0 || !reactContext.hasActiveReactInstance()) return
242
+ if (listenerCount <= 0 || !reactContext.hasActiveReactInstance()) {
243
+ pendingEmit = link
244
+ return
245
+ }
236
246
  reactContext
237
247
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
238
248
  .emit(EVENT_LINK_RECEIVED, link.toWritableMap())
@@ -28,6 +28,7 @@ public final class CavlynReactNative: RCTEventEmitter {
28
28
  private var apiBaseUrl: String = "https://api.cavlyn.com"
29
29
  private var isInitialized = false
30
30
  private var hasListeners = false
31
+ private var pendingEmit: [String: Any]?
31
32
 
32
33
  public override init() {
33
34
  super.init()
@@ -48,7 +49,13 @@ public final class CavlynReactNative: RCTEventEmitter {
48
49
  public override func startObserving() {
49
50
  lock.lock()
50
51
  hasListeners = true
52
+ let pending = pendingEmit
53
+ pendingEmit = nil
51
54
  lock.unlock()
55
+ // Deliver a link (e.g. cold-start) that arrived before JS subscribed.
56
+ if let pending = pending {
57
+ sendEvent(withName: Self.eventNameLinkReceived, body: pending)
58
+ }
52
59
  }
53
60
 
54
61
  public override func stopObserving() {
@@ -316,6 +323,7 @@ public final class CavlynReactNative: RCTEventEmitter {
316
323
  }
317
324
  defaults.set(url.absoluteString, forKey: Self.currentUriKey)
318
325
  let shouldEmit = hasListeners
326
+ if !shouldEmit { pendingEmit = link }
319
327
  lock.unlock()
320
328
 
321
329
  if isFirstLink, let linkId = link["linkId"] as? String {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavlyn/react-native-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "React Native SDK for Cavlyn dynamic links, Universal Links / App Links routing, deferred link resolution, and install/conversion/commerce attribution.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",