@loyalytics/swan-react-native-sdk 2.5.1-beta.2 → 2.5.1-beta.3

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.
@@ -160,6 +160,7 @@ function _resetClickDedup() {
160
160
 
161
161
  class SwanSDK {
162
162
  listeners = {};
163
+ coldStartCheckDone = false;
163
164
  SDK_VERSION = _version.SDK_VERSION;
164
165
  isProduction = 'STAGE';
165
166
  appId = '';
@@ -628,6 +629,16 @@ class SwanSDK {
628
629
  }
629
630
  this.listeners[event].push(callback);
630
631
 
632
+ // On first NOTIFICATION_OPENED listener, check for pending cold-start notifications.
633
+ // The native side holds click data until consumed — we just need to ask when ready.
634
+ if (event === SwanSDK.EVENTS.NOTIFICATION_OPENED && !this.coldStartCheckDone) {
635
+ this.coldStartCheckDone = true;
636
+ // Defer to next microtask so the listener is fully registered before events emit
637
+ Promise.resolve().then(() => {
638
+ this.checkPendingCarouselClick();
639
+ });
640
+ }
641
+
631
642
  // Return a subscription object for easy cleanup
632
643
  return {
633
644
  remove: () => {
@@ -958,9 +969,6 @@ class SwanSDK {
958
969
  _Logger.default.log('[SwanSDK] Tracking initial app launch event...');
959
970
  this.appLaunched();
960
971
 
961
- // Check for pending carousel click (covers killed/quit → fresh launch)
962
- this.checkPendingCarouselClick();
963
-
964
972
  // AppState listener setup (always runs)
965
973
  _Logger.default.log('[SwanSDK] Setting up AppState listener...');
966
974
  this.setupAppStateListener();
@@ -1826,11 +1834,12 @@ class SwanSDK {
1826
1834
  // Read click data from App Group (written by Content Extension)
1827
1835
  clickData = await _SharedCredentialsManager.SharedCredentialsManager.readTemplateClickData();
1828
1836
 
1829
- // If no data yet, retry after a short delay.
1830
- // The Content Extension may still be writing when the app foregrounds.
1837
+ // Exponential backoff: Content Extension may still be writing to App Group
1831
1838
  if (!clickData) {
1832
- await new Promise(r => setTimeout(r, 500));
1833
- clickData = await _SharedCredentialsManager.SharedCredentialsManager.readTemplateClickData();
1839
+ for (let attempt = 0; attempt < 4 && !clickData; attempt++) {
1840
+ await new Promise(r => setTimeout(r, 100 * Math.pow(2, attempt)));
1841
+ clickData = await _SharedCredentialsManager.SharedCredentialsManager.readTemplateClickData();
1842
+ }
1834
1843
  }
1835
1844
  }
1836
1845
  if (!clickData) return;