Skip to content

Commit

Permalink
Merge pull request #25 from superwall/develop
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
yusuftor authored Nov 15, 2024
2 parents b7c2951 + b594abe commit e073178
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

The changelog for `Superwall`. Also see the [releases](https://github.com/superwall/react-native-superwall/releases) on GitHub.

## 1.4.0

### Enhancements

- Adds `setInterfaceStyle(style:)` to Superwall, which you can use to set the interface style as `LIGHT` or `DARK`.

## 1.3.5

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.superwallreactnative.models.PaywallSkippedReason
import com.superwallreactnative.models.PurchaseResult
import com.superwallreactnative.models.RestorationResult
import com.superwallreactnative.models.SubscriptionStatus
import com.superwallreactnative.models.InterfaceStyle
import com.superwallreactnative.models.SuperwallOptions
import com.superwallreactnative.models.convertMapToReadableMap
import com.superwallreactnative.models.convertReadableMapToMap
Expand Down Expand Up @@ -220,6 +221,14 @@ class SuperwallReactNativeModule(private val reactContext: ReactApplicationConte
promise.resolve(Superwall.instance.handleDeepLink(url))
}

@ReactMethod
fun setInterfaceStyle(
interfaceStyle: String
) {
val interfaceStyle = InterfaceStyle.fromString(interfaceStyle)
Superwall.instance.setInterfaceStyle(interfaceStyle)
}

@ReactMethod
fun didPurchase(result: ReadableMap) {
val purchaseResult = PurchaseResult.fromJson(result)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.superwallreactnative.models

import com.superwall.sdk.network.device.InterfaceStyle

class InterfaceStyle {
companion object {
fun fromString(interfaceStyle: String): InterfaceStyle {
return when (interfaceStyle) {
"LIGHT" -> InterfaceStyle.LIGHT
"DARK" -> InterfaceStyle.DARK
else -> InterfaceStyle.LIGHT // Default case to handle unexpected values
}
}
}
}
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ PODS:
- React-Core
- SocketRocket (0.6.1)
- Superscript (0.1.12)
- superwall-react-native (1.3.5):
- superwall-react-native (1.4.0):
- glog
- RCT-Folly (= 2022.05.16.00)
- React-Core
Expand Down Expand Up @@ -1393,7 +1393,7 @@ SPEC CHECKSUMS:
RNPurchases: 06957eb2f35bd7bb336d32fccf3534d45a3fda8a
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
Superscript: 1ed1b4364f93bd16be05d085bba7357dbab95c83
superwall-react-native: 515aa62b5dc9452e3148a91fb645e08c4b0e1deb
superwall-react-native: 43ee3985e7bf123b5ad71e361e32d50e93d5da4d
SuperwallKit: ff739c94ebc351ae210c8b0f0b3931e930d74053
Yoga: 1b901a6d6eeba4e8a2e8f308f708691cdb5db312

Expand Down
1 change: 1 addition & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { StyleSheet, View, Platform, Button, Linking } from 'react-native';
import Superwall from '@superwall/react-native-superwall';
import { RCPurchaseController } from './RCPurchaseController';
import { MySuperwallDelegate } from './MySuperwallDelegate';
import { InterfaceStyle } from '@superwall/react-native-superwall';

Check failure on line 7 in example/src/App.tsx

View workflow job for this annotation

GitHub Actions / lint

'InterfaceStyle' is defined but never used

export default function App() {
const delegate = new MySuperwallDelegate();
Expand Down
21 changes: 21 additions & 0 deletions ios/Json/InterfaceStyle+Json.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// InterfaceStyle+Json.swift
// Superwall
//
// Created by Yusuf Tör on 21/02/2024.
//

import SuperwallKit

extension InterfaceStyle {
static func fromString(style: String) -> InterfaceStyle {
switch style {
case "LIGHT":
return .light
case "DARK":
return .dark
default:
return .light
}
}
}
2 changes: 2 additions & 0 deletions ios/SuperwallReactNative.mm
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ @interface RCT_EXTERN_MODULE(SuperwallReactNative, NSObject)

RCT_EXTERN_METHOD(setSubscriptionStatus:(NSString *)status)

RCT_EXTERN_METHOD(setInterfaceStyle:(NSString *)style)

RCT_EXTERN_METHOD(
getUserAttributes:(RCTPromiseResolveBlock)resolve
withRejecter:(RCTPromiseRejectBlock)reject
Expand Down
9 changes: 9 additions & 0 deletions ios/SuperwallReactNative.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ class SuperwallReactNative: RCTEventEmitter {
Superwall.shared.subscriptionStatus = subscriptionStatus
}

@objc(setInterfaceStyle:)
func setInterfaceStyle(style: String?) {
var interfaceStyle: InterfaceStyle?
if let style = style {
interfaceStyle = InterfaceStyle.fromString(style: style)
}
Superwall.shared.setInterfaceStyle(to: interfaceStyle)
}

@objc(getUserAttributes:withRejecter:)
func getUserAttributes(
resolve: @escaping RCTPromiseResolveBlock,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superwall/react-native-superwall",
"version": "1.3.5",
"version": "1.4.0",
"description": "The React Native package for Superwall",
"main": "lib/commonjs/index",
"module": "lib/module/index",
Expand Down
6 changes: 6 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PaywallPresentationHandler } from './public/PaywallPresentationHandler'
import { PaywallInfo } from './public/PaywallInfo';
import { PaywallSkippedReason } from './public/PaywallSkippedReason';
import { SubscriptionStatus } from './public/SubscriptionStatus';
import { InterfaceStyle } from './public/InterfaceStyle';
import { SuperwallDelegate } from './public/SuperwallDelegate';
import { SuperwallEventInfo } from './public/SuperwallEventInfo';
import { NativeEventEmitter } from 'react-native';
Expand Down Expand Up @@ -52,6 +53,7 @@ export {
} from './public/PurchaseResult';
export { RestorationResult } from './public/RestorationResult';
export { SubscriptionStatus } from './public/SubscriptionStatus';
export { InterfaceStyle } from './public/InterfaceStyle';
export { ConfigurationStatus } from './public/ConfigurationStatus';
//export { Superwall } from './Superwall';
export { SuperwallDelegate } from './public/SuperwallDelegate';
Expand Down Expand Up @@ -346,6 +348,10 @@ export default class Superwall {
await SuperwallReactNative.setSubscriptionStatus(status.toString());
}

async setInterfaceStyle(style: InterfaceStyle) {
await SuperwallReactNative.setInterfaceStyle(style.toString());
}

async setDelegate(delegate: SuperwallDelegate | undefined) {
await this.awaitConfig();
Superwall.delegate = delegate;
Expand Down
17 changes: 17 additions & 0 deletions src/public/InterfaceStyle.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export enum InterfaceStyle {
LIGHT = 'LIGHT',
DARK = 'DARK',
}

export namespace InterfaceStyle {
export function fromString(value: string): InterfaceStyle {
switch (value) {
case 'LIGHT':
return InterfaceStyle.LIGHT;
case 'DARK':
return InterfaceStyle.DARK;
default:
return InterfaceStyle.LIGHT;
}
}
}

0 comments on commit e073178

Please sign in to comment.