Skip to content

Commit d9b50d9

Browse files
RN: Enable New Architecture & Enhance Custom Color Support for SmallPlug iOS (#122)
* fix: update method signatures to use BOOL instead of BOOL* for better clarity * making changes to enable new arch in react native sdk * making changes as per review * chore(fix): resolve issue of unable to use custom colors in header and back icon in smallPlug --------- Co-authored-by: Sourav Ganguly (isouravganguly) <sourav.ganguly@smallcase.com>
1 parent f6af300 commit d9b50d9

File tree

6 files changed

+1170
-521
lines changed

6 files changed

+1170
-521
lines changed

android/src/main/java/com/reactnativesmallcasegateway/SmallcaseGatewayModule.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,14 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
179179
}
180180

181181
@ReactMethod
182-
fun launchSmallplugWithBranding(targetEndpoint: String, params: String, readableMap: ReadableMap?, promise: Promise) {
182+
fun launchSmallplugWithBranding(targetEndpoint: String, params: String, headerColor: String?, headerOpacity: Double?, backIconColor: String?, backIconOpacity: Double?, promise: Promise
183+
) {
184+
val readableMap = Arguments.createMap().apply {
185+
headerColor?.let { putString("headerColor", it) }
186+
headerOpacity?.let { putDouble("headerOpacity", it) }
187+
backIconColor?.let { putString("backIconColor", it) }
188+
backIconOpacity?.let { putDouble("backIconOpacity", it) }
189+
}
183190

184191
fun getColorValue(value: Any?, defaultValue: String): String {
185192
return when (value) {
@@ -196,7 +203,7 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
196203
var partnerProps: SmallplugPartnerProps? = SmallplugPartnerProps(headerColor = "#2F363F", backIconColor = "ffffff")
197204

198205
try {
199-
partnerProps = readableMap?.toHashMap()?.let { map ->
206+
partnerProps = readableMap.toHashMap().let { map ->
200207
val hc = getColorValue(map["headerColor"], "#2F363F")
201208
val ho = map["headerOpacity"]?.let { if (it is Double) it else 1.0 } ?: 1.0
202209
val bc = getColorValue(map["backIconColor"], "#ffffff")
@@ -206,19 +213,16 @@ class SmallcaseGatewayModule(reactContext: ReactApplicationContext) : ReactConte
206213
} catch (e: Throwable) {
207214
}
208215

209-
210216
SmallcaseGatewaySdk.launchSmallPlug(currentActivity!!, SmallplugData(targetEndpoint, params), object : SmallPlugResponseListener {
211217
override fun onFailure(errorCode: Int, errorMessage: String) {
212218
val err = createErrorJSON(errorCode, errorMessage, null)
213-
214219
promise.reject("error", err)
215220
}
216221

217222
override fun onSuccess(smallPlugResult: SmallPlugResult) {
218223
val res = resultToWritableMap(smallPlugResult)
219224
promise.resolve(res)
220225
}
221-
222226
}, partnerProps)
223227
}
224228

ios/SmallcaseGateway.m

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
3030
RCT_REMAP_METHOD(setConfigEnvironment,
3131
envName:(NSString *)envName
3232
gateway:(NSString *)gateway
33-
isLeprechaunActive: (BOOL *)isLeprechaunActive
34-
isAmoEnabled: (BOOL *)isAmoEnabled
33+
isLeprechaunActive: (BOOL)isLeprechaunActive
34+
isAmoEnabled: (BOOL)isAmoEnabled
3535
preProvidedBrokers: (NSArray *)preProvidedBrokers
3636
setConfigEnvironmentWithResolver:(RCTPromiseResolveBlock)resolve
3737
rejecter:(RCTPromiseRejectBlock)reject) {
@@ -383,9 +383,25 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
383383
rejecter:(RCTPromiseRejectBlock)reject)
384384
{
385385
dispatch_async(dispatch_get_main_queue(), ^(void) {
386+
387+
NSString* (^processColorValue)(NSString*, NSString*) = ^NSString*(NSString *color, NSString *defaultColor) {
388+
if (color == nil || color.length < 6) {
389+
return defaultColor;
390+
}
391+
if ([color hasPrefix:@"#"]) {
392+
return [color substringFromIndex:1];
393+
}
394+
return color;
395+
};
396+
397+
NSString *processedHeaderColor = processColorValue(headerColor, @"2F363F");
398+
NSString *processedBackIconColor = processColorValue(backIconColor, @"ffffff");
399+
400+
double finalHeaderOpacity = headerOpacity != nil ? [headerOpacity doubleValue] : 1.0;
401+
double finalBackIconOpacity = backIconOpacity != nil ? [backIconOpacity doubleValue] : 1.0;
386402

387403
SmallplugData *smallplugData = [[SmallplugData alloc] init:targetEndpoint :params];
388-
SmallplugUiConfig *smallplugUiConfig = [[SmallplugUiConfig alloc] initWithSmallplugHeaderColor:headerColor headerColorOpacity:headerOpacity backIconColor:backIconColor backIconColorOpacity:backIconOpacity];
404+
SmallplugUiConfig *smallplugUiConfig = [[SmallplugUiConfig alloc] initWithSmallplugHeaderColor:processedHeaderColor headerColorOpacity:@(finalHeaderOpacity) backIconColor:processedBackIconColor backIconColorOpacity:@(finalBackIconOpacity)];
389405

390406
[SCGateway.shared launchSmallPlugWithPresentingController:[[[UIApplication sharedApplication] keyWindow] rootViewController] smallplugData:smallplugData smallplugUiConfig:smallplugUiConfig completion:^(id smallplugResponse, NSError * error) {
391407

@@ -480,7 +496,7 @@ @interface RCT_EXTERN_MODULE(SmallcaseGateway, NSObject)
480496
RCT_REMAP_METHOD(triggerLeadGenWithLoginCta,
481497
userParams: (NSDictionary *)userParams
482498
utmParams:(NSDictionary *)utmParams
483-
showLoginCta:(BOOL *)showLoginCta
499+
showLoginCta:(BOOL)showLoginCta
484500
leadGenGenWithResolver: (RCTPromiseResolveBlock)resolve
485501
rejecter:(RCTPromiseRejectBlock)reject
486502
) {

smart_investing_react_native/android/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64
3232
# your application. You should enable this flag either if you want
3333
# to write custom TurboModules/Fabric components OR use libraries that
3434
# are providing them.
35-
newArchEnabled=false
35+
newArchEnabled=true
3636

3737
# Use this property to enable or disable the Hermes JS engine.
3838
# If set to false, you will be using JSC instead.

smart_investing_react_native/ios/Podfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ target 'smart_investing_react_native' do
2222

2323
use_react_native!(
2424
:path => config[:reactNativePath],
25-
# An absolute path to your application root.
26-
:app_path => "#{Pod::Config.instance.installation_root}/.."
25+
:app_path => "#{Pod::Config.instance.installation_root}/..",
26+
:fabric_enabled => true,
27+
:hermes_enabled => true
2728
)
2829

2930
post_install do |installer|

0 commit comments

Comments
 (0)