Skip to content

Commit 1382a79

Browse files
author
Cello Dev
committed
build: add support for theme mode
1 parent c35d9ef commit 1382a79

File tree

4 files changed

+45
-7
lines changed

4 files changed

+45
-7
lines changed

android/src/main/java/com/celloreactnative/CelloReactNativeModule.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CelloReactNativeModule(reactContext: ReactApplicationContext) :
1818
return NAME
1919
}
2020
@ReactMethod
21-
fun initialize(productId: String, token: String, environment: String?, productUserDetailsMap: ReadableMap?, language: String?, promise: Promise) {
21+
fun initialize(productId: String, token: String, environment: String?, productUserDetailsMap: ReadableMap?, language: String?, themeMode: String?, promise: Promise) {
2222
val activity = reactApplicationContext.currentActivity ?: run {
2323
promise.reject("ActivityError", "Activity is null")
2424
return
@@ -40,7 +40,7 @@ class CelloReactNativeModule(reactContext: ReactApplicationContext) :
4040
null
4141
}
4242

43-
Cello.initialize(activity, productId, token, environment, productUserDetails, language)
43+
Cello.initialize(activity, productId, token, environment, productUserDetails, language, themeMode)
4444
withContext(Dispatchers.Main) {
4545
val client = Cello.client()
4646
if (client != null) {
@@ -73,6 +73,15 @@ class CelloReactNativeModule(reactContext: ReactApplicationContext) :
7373
}
7474
}
7575

76+
@ReactMethod
77+
fun setThemeMode(themeMode: String) {
78+
try {
79+
Cello.client()?.setThemeMode(themeMode)
80+
} catch (e: Exception) {
81+
82+
}
83+
}
84+
7685
@ReactMethod
7786
fun showFab() {
7887
try {

ios/CelloReactNative.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ @interface RCT_EXTERN_MODULE(CelloReactNative, NSObject)
77
withEnvironment:(nullable NSString *)environment
88
withProductUserDetails:(nullable NSDictionary *)productUserDetails
99
withLanguage:(nullable NSString *)language
10+
withThemeMode:(nullable NSString *)themeMode
1011
withResolver:(RCTPromiseResolveBlock)resolve
1112
withRejecter:(RCTPromiseRejectBlock)reject)
1213

@@ -18,6 +19,10 @@ @interface RCT_EXTERN_MODULE(CelloReactNative, NSObject)
1819
withResolver:(RCTPromiseResolveBlock)resolve
1920
withRejecter:(RCTPromiseRejectBlock)reject)
2021

22+
RCT_EXTERN_METHOD(setThemeMode:(NSString *)themeMode
23+
withResolver:(RCTPromiseResolveBlock)resolve
24+
withRejecter:(RCTPromiseRejectBlock)reject)
25+
2126
RCT_EXTERN_METHOD(showFab)
2227

2328
RCT_EXTERN_METHOD(hideFab)

ios/CelloReactNative.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import CelloSDK
33
@objc(CelloReactNative)
44
class CelloReactNative: NSObject {
55

6-
@objc(initialize:withToken:withEnvironment:withProductUserDetails:withLanguage:withResolver:withRejecter:)
7-
func initialize(productId: String, token: String, environment: String?, productUserDetailsDict: NSDictionary?, language: String?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
6+
@objc(initialize:withToken:withEnvironment:withProductUserDetails:withLanguage:withThemeMode:withResolver:withRejecter:)
7+
func initialize(productId: String, token: String, environment: String?, productUserDetailsDict: NSDictionary?, language: String?, themeMode: String?, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) -> Void {
88
let resolver = resolve
99
let rejecter = reject
1010

@@ -20,7 +20,7 @@ class CelloReactNative: NSObject {
2020
productUserDetails = nil
2121
}
2222

23-
Cello.initialize(for: productId, with: token, environment: environment, productUserDetails: productUserDetails, language: language) { result in
23+
Cello.initialize(for: productId, with: token, environment: environment, productUserDetails: productUserDetails, language: language, themeMode: themeMode) { result in
2424
switch result {
2525
case .success(let configuration):
2626
resolver(configuration)
@@ -62,6 +62,22 @@ class CelloReactNative: NSObject {
6262
}
6363
}
6464

65+
@objc(setThemeMode:withResolver:withRejecter:)
66+
func setThemeMode(themeMode: String, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) {
67+
if #available(iOS 14.0, *) {
68+
Cello.setThemeMode(to: themeMode) { result in
69+
switch result {
70+
case .success(let res):
71+
resolve(res)
72+
case .failure(let error):
73+
reject("ThemeModeChangeError", "Failed to set theme mode: \(error.localizedDescription)", error)
74+
}
75+
}
76+
} else {
77+
reject("UnavailableError", "Theme mode change feature is not available in your iOS version.", nil)
78+
}
79+
}
80+
6581
@objc(showFab)
6682
func showFab() -> Void {
6783
Cello.showFab()

src/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface InitializeOptions {
1313
environment?: string;
1414
productUserDetails?: ProductUserDetails;
1515
language?: string;
16+
themeMode?: string;
1617
}
1718

1819
const LINKING_ERROR =
@@ -62,16 +63,18 @@ function initialize(
6263
options.token,
6364
options.environment,
6465
options.productUserDetails,
65-
options.language
66+
options.language,
67+
options.themeMode
6668
);
6769
}
6870

69-
// Old API doesn't support productUserDetails or language, pass undefined explicitly for RN bridge
71+
// Old API doesn't support productUserDetails, language, or themeMode, pass undefined explicitly for RN bridge
7072
return CelloReactNative.initialize(
7173
productIdOrOptions,
7274
token!,
7375
environment,
7476
undefined,
77+
undefined,
7578
undefined
7679
);
7780
}
@@ -84,6 +87,10 @@ function changeLanguage(language: string): Promise<any> {
8487
return CelloReactNative.changeLanguage(language);
8588
}
8689

90+
function setThemeMode(themeMode: string): Promise<any> {
91+
return CelloReactNative.setThemeMode(themeMode);
92+
}
93+
8794
function showFab() {
8895
return CelloReactNative.showFab();
8996
}
@@ -121,6 +128,7 @@ const Cello = {
121128
initialize,
122129
updateToken,
123130
changeLanguage,
131+
setThemeMode,
124132
showFab,
125133
hideFab,
126134
openWidget,

0 commit comments

Comments
 (0)