apps-sdk 1.0.187 → 1.0.188

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apps-sdk",
3
- "version": "1.0.187",
3
+ "version": "1.0.188",
4
4
  "description": "Apps SDK",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,39 @@
1
+ import React from 'react';
2
+ import { Modal, View, Button } from 'react-native';
3
+ import { WebView } from 'react-native-webview';
4
+
5
+ class Navigator extends React.Component {
6
+ constructor(props) {
7
+ super(props);
8
+ this.state = {
9
+ isVisible: props.isVisible,
10
+ url: props.url,
11
+ title: props.title,
12
+ };
13
+ }
14
+
15
+ componentDidUpdate(prevProps) {
16
+ if (prevProps.isVisible !== this.props.isVisible) {
17
+ this.setState({ isVisible: this.props.isVisible });
18
+ }
19
+ }
20
+
21
+ render() {
22
+ return (
23
+ <Modal
24
+ animationType="slide"
25
+ transparent={true}
26
+ visible={this.state.isVisible}
27
+ onRequestClose={this.props.onRequestClose}
28
+ >
29
+ <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
30
+ <WebView
31
+ source={{ uri: this.state.url }}
32
+ style={{ width: '100%', height: '100%' }}
33
+ />
34
+ <Button title="Close" onPress={this.props.onRequestClose} />
35
+ </View>
36
+ </Modal>
37
+ );
38
+ }
39
+ }
@@ -1,6 +1,7 @@
1
1
  import { adapty } from 'react-native-adapty';
2
2
  import * as config from '../../config';
3
3
  import {Session} from "./index";
4
+ import {createPaywallView} from "react-native-adapty/dist/ui";
4
5
 
5
6
  class Adapty {
6
7
  async initialize(apiKey = null) {
@@ -15,6 +16,7 @@ class Adapty {
15
16
  diskStorageSizeLimit: 100 * 1024 * 1024, // 100MB
16
17
  },
17
18
  });
19
+ const profile = await adapty.getProfile();
18
20
  } catch (error) {
19
21
  console.error('Error initializing Adapty:', error);
20
22
  }
@@ -22,10 +24,63 @@ class Adapty {
22
24
 
23
25
  async getPaywallForPlacement(placementID, lang) {
24
26
  try {
25
- config.DEBUG_MODE && console.log('Getting paywall for placement:', placementID, 'and language:', lang);
26
27
  return await adapty.getPaywall(placementID, lang);
27
28
  } catch (error) {
28
- console.error('Error getting paywall:', error);
29
+ return null;
30
+ }
31
+ }
32
+
33
+ async isActivated() {
34
+ try {
35
+ return await adapty.isActivated();
36
+ } catch (error) {
37
+ console.error('Error getting Adapty activation status:', error);
38
+ return false;
39
+ }
40
+ }
41
+
42
+ async createPaywallView(paywall) {
43
+ try {
44
+ return await createPaywallView(paywall);
45
+ } catch (error) {
46
+ console.error('Error creating paywall view:', error);
47
+ return null;
48
+ }
49
+ }
50
+
51
+ async showPaywall(placementID, lang, eventHandlers = {}) {
52
+ try {
53
+ const paywall = await this.getPaywallForPlacement(placementID, lang);
54
+ config.DEBUG_MODE && console.log('Getting paywall for placement:', placementID, 'and language:', lang, 'paywall:', paywall);
55
+ if (paywall) {
56
+ const paywallView = await this.createPaywallView(paywall);
57
+ paywallView.registerEventHandlers({
58
+ onCloseButtonPress: eventHandlers.onCloseButtonPress || (() => { return true; }),
59
+ onAndroidSystemBack: eventHandlers.onAndroidSystemBack || (() => { paywallView.dismiss(); return true; }),
60
+ onPurchaseCompleted: eventHandlers.onPurchaseCompleted || (() => { paywallView.dismiss(); return true; }),
61
+ onPurchaseStarted: eventHandlers.onPurchaseStarted || (() => { }),
62
+ onPurchaseFailed: eventHandlers.onPurchaseFailed || (() => { paywallView.dismiss(); return true; }),
63
+ onRestoreCompleted: eventHandlers.onRestoreCompleted || (() => { paywallView.dismiss(); return true; }),
64
+ onRestoreFailed: eventHandlers.onRestoreFailed || (() => { paywallView.dismiss(); return true; }),
65
+ onProductSelected: eventHandlers.onProductSelected || (() => { }),
66
+ onRenderingFailed: eventHandlers.onRenderingFailed || (() => { return true; }),
67
+ onLoadingProductsFailed: eventHandlers.onLoadingProductsFailed || (() => { paywallView.dismiss(); return true; }),
68
+ onUrlPress: eventHandlers.onUrlPress || (() => { return true; }),
69
+ });
70
+ await paywallView.present();
71
+ } else {
72
+ console.warn('Error showing paywall: paywall not found for placement', placementID, 'and language', lang);
73
+ }
74
+ } catch (error) {
75
+ console.error('Error showing paywall:', error);
76
+ }
77
+ }
78
+
79
+ async getProfile() {
80
+ try {
81
+ return await adapty.getProfile();
82
+ } catch (error) {
83
+ console.error('Error getting profile:', error);
29
84
  return null;
30
85
  }
31
86
  }
package/types/index.d.ts CHANGED
@@ -75,7 +75,7 @@ declare module 'apps-sdk' {
75
75
  getEndpoints(): any;
76
76
  setEvents(events: any): void;
77
77
  sendEvent(eventType: string, eventKeyword:string, eventData?: object, forceSend?: boolean): Promise<void>;
78
- createSubscription(): any;
78
+ createSubscription(data: any): Promise<boolean>;
79
79
  checkConnection(): Promise<boolean>;
80
80
  setImageCompression(compression: any): void;
81
81
  addPendingEvent(event: any): void;
@@ -187,9 +187,27 @@ declare module 'apps-sdk' {
187
187
  trackEventIfExist(eventKeyword: string, eventData?: object): Promise<void>;
188
188
  }
189
189
 
190
+ type PaywallEventHandlers = {
191
+ onCloseButtonPress?: () => void;
192
+ onAndroidSystemBack?: () => void;
193
+ onPurchaseCompleted?: (purchaseResult: any, product: any) => void;
194
+ onPurchaseStarted?: (product: any) => void;
195
+ onPurchaseFailed?: (error: any) => void;
196
+ onRestoreCompleted?: (profile: any) => void;
197
+ onRestoreFailed?: (error: any, product: any) => void;
198
+ onProductSelected?: (productId: string) => void;
199
+ onRenderingFailed?: (error: any) => void;
200
+ onLoadingProductsFailed?: (error: any) => void;
201
+ onUrlPress?: (url: string) => void;
202
+ };
203
+
190
204
  export class Adapty {
191
205
  initialize(apiKey: string): Promise<void>;
192
206
  getPaywallForPlacement(placementID: string, lang: string): Promise<any>;
207
+ isActivated(): Promise<boolean>;
208
+ createPaywallView(paywall: any): Promise<any>;
209
+ showPaywall(placementID: any, lang: any, eventHandlers?: PaywallEventHandlers): Promise<void>;
210
+ getProfile(): Promise<any>;
193
211
  }
194
212
 
195
213
  export class TrackingTransparency {