apps-sdk 2.0.8 → 2.1.0

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.
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Legal} from "./src/libraries";
1
+ import {NotificationsPush, Networking, Storage, Session, Utils, PayWallLogic, Rating, AdJust, TrackingTransparency, Voice, MixPanel, Adapty, HomeActions, Facebook, Firebase, Legal} from "./src/libraries";
2
2
  // import PayWall from "./src/components/PayWall"; // DEPRECATED: Use SDK.adaptyOnboarding or SDK.adapty.showPaywall() instead
3
3
  import AdaptyOnboarding from "./src/components/AdaptyOnboarding";
4
4
 
@@ -63,5 +63,6 @@ export default {
63
63
  adapty: Adapty,
64
64
  homeActions: HomeActions,
65
65
  facebook: Facebook,
66
+ firebase: Firebase,
66
67
  legal: Legal,
67
- }
68
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "2.0.8",
4
- "description": "Apps SDK - Compatible with Expo SDK 54 + React 19",
3
+ "version": "2.1.0",
4
+ "description": "Apps SDK - Compatible with Expo SDK 54 + React 19 - Firebase optional",
5
5
  "main": "index.js",
6
6
  "author": "ASD",
7
7
  "license": "ISC",
@@ -36,6 +36,10 @@
36
36
  "react-native-btr": "^2.2.1",
37
37
  "semver": "^7.6.0"
38
38
  },
39
+ "optionalDependencies": {
40
+ "@react-native-firebase/analytics": "^21.10.0",
41
+ "@react-native-firebase/app": "^21.10.0"
42
+ },
39
43
  "devDependencies": {
40
44
  "expo": "~54.0.0",
41
45
  "expo-asset": "~12.0.0",
@@ -4,6 +4,11 @@ import {Session} from "./index";
4
4
  import {createPaywallView, createOnboardingView} from "react-native-adapty/dist/ui";
5
5
 
6
6
  class Adapty {
7
+ constructor() {
8
+ this.currentPaywallView = null;
9
+ this.currentOnboardingView = null;
10
+ }
11
+
7
12
  async initialize(apiKey = null) {
8
13
  try {
9
14
  const isActivated = await this.isActivated();
@@ -64,6 +69,8 @@ class Adapty {
64
69
  return;
65
70
  }
66
71
 
72
+ this.currentPaywallView = paywallView;
73
+
67
74
  paywallView.setEventHandlers({
68
75
  onCloseButtonPress: eventHandlers.onCloseButtonPress || (() => { return true; }),
69
76
  onAndroidSystemBack: eventHandlers.onAndroidSystemBack || (() => { paywallView.dismiss(); return true; }),
@@ -115,12 +122,12 @@ class Adapty {
115
122
  }
116
123
 
117
124
  async closePaywall() {
118
- const paywallView = await adapty.getCurrentPaywallView();
119
125
  try {
120
- if (paywallView) {
121
- paywallView.dismiss();
126
+ if (this.currentPaywallView) {
127
+ await this.currentPaywallView.dismiss();
128
+ this.currentPaywallView = null;
122
129
  } else {
123
- console.warn('Error closing paywall: paywall view is null');
130
+ console.warn('Error closing paywall: no paywall view reference stored');
124
131
  }
125
132
  } catch (error) {
126
133
  console.error('Error closing paywall:', error);
@@ -142,6 +149,8 @@ class Adapty {
142
149
  async showPaywallPreloaded(paywallView, eventHandlers = {}) {
143
150
  try {
144
151
  if (paywallView) {
152
+ this.currentPaywallView = paywallView;
153
+
145
154
  paywallView.setEventHandlers({
146
155
  onCloseButtonPress: eventHandlers.onCloseButtonPress || (() => { return true; }),
147
156
  onAndroidSystemBack: eventHandlers.onAndroidSystemBack || (() => { paywallView.dismiss(); return true; }),
@@ -231,6 +240,9 @@ class Adapty {
231
240
  config.DEBUG_MODE && console.log('Getting onboarding for placement:', placementID, 'and language:', lang, 'onboarding:', onboarding);
232
241
  if (onboarding) {
233
242
  const onboardingView = await this.createOnboardingView(onboarding);
243
+
244
+ this.currentOnboardingView = onboardingView;
245
+
234
246
  onboardingView.setEventHandlers({
235
247
  onAnalytics: eventHandlers.onAnalytics || (() => { }),
236
248
  onClose: eventHandlers.onClose || (async (actionId, meta) => { await onboardingView.dismiss(); return true; }),
@@ -256,12 +268,12 @@ class Adapty {
256
268
 
257
269
 
258
270
  async closeOnboarding() {
259
- const onboardingView = await adapty.getCurrentOnboardingView();
260
271
  try {
261
- if (onboardingView) {
262
- onboardingView.dismiss();
272
+ if (this.currentOnboardingView) {
273
+ await this.currentOnboardingView.dismiss();
274
+ this.currentOnboardingView = null;
263
275
  } else {
264
- console.warn('Error closing onboarding: onboarding view is null');
276
+ console.warn('Error closing onboarding: no onboarding view reference stored');
265
277
  }
266
278
  } catch (error) {
267
279
  console.error('Error closing onboarding:', error);
@@ -271,6 +283,8 @@ class Adapty {
271
283
  async showOnboardingPreloaded(onboardingView, eventHandlers = {}) {
272
284
  try {
273
285
  if (onboardingView) {
286
+ this.currentOnboardingView = onboardingView;
287
+
274
288
  onboardingView.setEventHandlers({
275
289
  onAnalytics: eventHandlers.onAnalytics || (() => { }),
276
290
  onClose: eventHandlers.onClose || (async (actionId, meta) => { await onboardingView.dismiss(); return true; }),
@@ -1,51 +1,87 @@
1
- import analytics from '@react-native-firebase/analytics';
2
1
  import config from '../../config';
3
2
 
3
+ // Lazy load Firebase (optional dependency)
4
+ let analyticsModule = null;
5
+ let isAvailable = null;
6
+
7
+ function getAnalytics() {
8
+ if (isAvailable === false) return null;
9
+
10
+ if (analyticsModule === null && isAvailable === null) {
11
+ try {
12
+ analyticsModule = require('@react-native-firebase/analytics').default;
13
+ isAvailable = true;
14
+ } catch {
15
+ isAvailable = false;
16
+ }
17
+ }
18
+
19
+ return analyticsModule;
20
+ }
21
+
4
22
  class Firebase {
23
+ isAvailable() {
24
+ return getAnalytics() !== null;
25
+ }
26
+
5
27
  async initialize() {
28
+ const analytics = getAnalytics();
29
+ if (!analytics) return;
30
+
6
31
  try {
7
- // Firebase should already be initialized by the app
8
- config.DEBUG_MODE && console.log('Firebase Analytics is ready to use');
32
+ config.DEBUG_MODE && console.log('[SDK] Firebase Analytics initialized');
9
33
  } catch (error) {
10
- console.error('Error initializing Firebase:', error);
34
+ console.error('[SDK] Error initializing Firebase:', error);
11
35
  }
12
36
  }
13
37
 
14
38
  async getAppInstanceId() {
39
+ const analytics = getAnalytics();
40
+ if (!analytics) return null;
41
+
15
42
  try {
16
43
  const appInstanceId = await analytics().getAppInstanceId();
17
- config.DEBUG_MODE && console.log('Firebase App Instance ID:', appInstanceId);
44
+ config.DEBUG_MODE && console.log('[SDK] Firebase App Instance ID:', appInstanceId);
18
45
  return appInstanceId;
19
46
  } catch (error) {
20
- console.error('Error getting Firebase App Instance ID:', error);
47
+ console.error('[SDK] Error getting Firebase App Instance ID:', error);
21
48
  return null;
22
49
  }
23
50
  }
24
51
 
25
52
  async logEvent(eventName, params = {}) {
53
+ const analytics = getAnalytics();
54
+ if (!analytics) return;
55
+
26
56
  try {
27
57
  await analytics().logEvent(eventName, params);
28
- config.DEBUG_MODE && console.log('Firebase event logged:', eventName, params);
58
+ config.DEBUG_MODE && console.log('[SDK] Firebase event logged:', eventName, params);
29
59
  } catch (error) {
30
- console.error('Error logging Firebase event:', error);
60
+ console.error('[SDK] Error logging Firebase event:', error);
31
61
  }
32
62
  }
33
63
 
34
64
  async setUserId(userId) {
65
+ const analytics = getAnalytics();
66
+ if (!analytics) return;
67
+
35
68
  try {
36
69
  await analytics().setUserId(userId);
37
- config.DEBUG_MODE && console.log('Firebase user ID set:', userId);
70
+ config.DEBUG_MODE && console.log('[SDK] Firebase user ID set:', userId);
38
71
  } catch (error) {
39
- console.error('Error setting Firebase user ID:', error);
72
+ console.error('[SDK] Error setting Firebase user ID:', error);
40
73
  }
41
74
  }
42
75
 
43
76
  async setUserProperty(name, value) {
77
+ const analytics = getAnalytics();
78
+ if (!analytics) return;
79
+
44
80
  try {
45
81
  await analytics().setUserProperty(name, value);
46
- config.DEBUG_MODE && console.log('Firebase user property set:', name, value);
82
+ config.DEBUG_MODE && console.log('[SDK] Firebase user property set:', name, value);
47
83
  } catch (error) {
48
- console.error('Error setting Firebase user property:', error);
84
+ console.error('[SDK] Error setting Firebase user property:', error);
49
85
  }
50
86
  }
51
87
  }