Skip to content

Commit 7d2bc52

Browse files
authored
Merge pull request #63 from apphud/feature/2.1.0
add paywallShown and paywallClosed methods
2 parents cd1a66f + 5341b7e commit 7d2bc52

File tree

13 files changed

+69
-15
lines changed

13 files changed

+69
-15
lines changed

android/src/main/java/com/reactnativeapphudsdk/ApphudDataTransformer.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ class ApphudDataTransformer {
5252

5353
fun getApphudPaywallMap(paywall: ApphudPaywall): WritableNativeMap {
5454
val result: WritableNativeMap = WritableNativeMap()
55-
Apphud.enableDebugLogs()
5655
result.putString("identifier", paywall.identifier)
5756
result.putBoolean("isDefault", paywall.default)
5857
result.putString("experimentName", paywall.experimentName)

android/src/main/java/com/reactnativeapphudsdk/ApphudSdkModule.kt

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
2222

2323
init {
2424
HeadersInterceptor.X_SDK = "reactnative"
25-
HeadersInterceptor.X_SDK_VERSION = "2.0.0"
25+
HeadersInterceptor.X_SDK_VERSION = "2.1.0"
2626
listener = ApphudListenerHandler(reactContext)
2727
listener?.let { Apphud.setListener(it) }
2828
}
@@ -73,6 +73,22 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
7373
}
7474
}
7575

76+
@ReactMethod
77+
fun paywallShown(identifier: String) {
78+
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
79+
paywall?.let {
80+
Apphud.paywallShown(it)
81+
}
82+
}
83+
84+
@ReactMethod
85+
fun paywallClosed(identifier: String) {
86+
val paywall = Apphud.paywalls().firstOrNull { it.identifier == identifier }
87+
paywall?.let {
88+
Apphud.paywallClosed(it)
89+
}
90+
}
91+
7692
@ReactMethod
7793
fun purchase(args: ReadableMap, promise: Promise) {
7894
val productId = args.getString("productId")
@@ -96,7 +112,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
96112

97113
val isSub = product?.productDetails?.productType?.lowercase() == "subs"
98114
val offerToken = args.getString("offerToken")
99-
val isConsumable = args.getBoolean("isConsumable")
115+
val isConsumable = if (args.hasKey("isConsumable")) args.getBoolean("isConsumable") else false
100116

101117
if (product == null) {
102118
promise.reject("Error", "Product not found")
@@ -270,6 +286,7 @@ class ApphudSdkModule(reactContext: ReactApplicationContext) : ReactContextBaseJ
270286
Apphud.collectDeviceIdentifiers()
271287
}
272288

289+
273290
@ReactMethod
274291
fun enableDebugLogs() {
275292
Apphud.enableDebugLogs()

example/ios/.xcode.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node

example/ios/ApphudSdkExample.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@
399399
);
400400
runOnlyForDeploymentPostprocessing = 0;
401401
shellPath = /bin/sh;
402-
shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
402+
shellScript = "export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
403403
};
404404
2D02E4CB1E0B4B27006451C7 /* Bundle React Native Code And Images */ = {
405405
isa = PBXShellScriptBuildPhase;

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,4 @@ SPEC CHECKSUMS:
580580

581581
PODFILE CHECKSUM: 47a16e2930bdcf8baadcf3fe4873c7f378dc927c
582582

583-
COCOAPODS: 1.14.2
583+
COCOAPODS: 1.15.2

example/src/screens/ActionsScreen.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ export default function ActionsScreen({ navigation }: Props) {
4444
const [paywalls, setPaywalls] = React.useState<Array<ApphudPaywall>>();
4545

4646
const callAll = () => {
47-
// ApphudSdk.enableDebugLogs();
47+
ApphudSdk.enableDebugLogs();
4848

4949
// ApphudSdk.setAdvertisingIdentifier('42ed88fd-b446-4eb1-81ae-83e3025c04cf')
5050

5151
// ApphudSdk.userId().then((userId) => console.log(`Apphud: userId: ${userId}`));
52-
// ApphudSdk.hasActiveSubscription().then((hasActiveSubscription) =>
53-
// console.log(`Apphud: hasActiveSubscription: ${hasActiveSubscription}`)
54-
// );
55-
// ApphudSdk.hasPremiumAccess().then((hasPremiumAccess) =>
56-
// console.log(`Apphud: hasPremiumAccess: ${hasPremiumAccess}`)
57-
// );
52+
ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + active));
53+
5854

5955
// ApphudSdk.setUserProperty({key: 'some_string_key2', value: 'some_string_valueee', setOnce: true})
6056
// ApphudSdk.setUserProperty({key: 'some_float_key3', value: 1.45, setOnce: true})

example/src/screens/LoginScreen.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export default function LoginScreen({ navigation }: Props) {
2020

2121
const onStartHandler = () => {
2222
ApphudSdk.start({ apiKey, userId, deviceId, observerMode: false })
23+
24+
// ApphudSdk.hasActiveSubscription().then((active) => console.log('START Has Active Subscription: = ' + hasActive));
25+
2326
navigation.navigate('Actions')
2427
}
2528

example/src/screens/PaywallScreen.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export default function PaywallScreen({ route, navigation}: { route: any, naviga
5353
for (const paywall of paywalls) {
5454
if (paywall.identifier === route.params.paywallId) {
5555
setCurrentPaywall(paywall);
56+
await ApphudSdk.paywallShown(paywall.identifier);
5657
const productsPropsList: ProductProps[] = preparedProducts(paywall.products);
5758
setProductsProps(productsPropsList);
5859
return paywall;

ios/.xcode.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export NODE_BINARY=/opt/homebrew/opt/node@20/bin/node

ios/ApphudSdk.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ @interface RCT_EXTERN_MODULE(ApphudSdk, NSObject)
4646

4747
RCT_EXTERN_METHOD(collectDeviceIdentifiers)
4848
RCT_EXTERN_METHOD(setAdvertisingIdentifier:(NSString*)idfa)
49+
RCT_EXTERN_METHOD(paywallShown:(NSString*)identifier)
50+
RCT_EXTERN_METHOD(paywallClosed:(NSString*)identifier)
4951
RCT_EXTERN_METHOD(optOutOfTracking)
5052
RCT_EXTERN_METHOD(enableDebugLogs)
5153
RCT_EXTERN_METHOD(logout:(RCTPromiseResolveBlock)resolve)

0 commit comments

Comments
 (0)