#import "MyidSdk.h" // Generated by the Swift compiler from MyidSdkImpl.swift. The bracketed form is // used when the pod is built as a framework; the quoted fallback covers static // linkage, where the header is copied next to the sources instead. #if __has_include() #import #else #import "RNMyidSdk-Swift.h" #endif /** * Codegen hands this layer C++ structs (JS::NativeMyidSdk::*Input), which Swift * cannot see. So the only job here is to flatten them into NSDictionary and * hand off to MyidSdkImpl, which owns all the actual SDK interaction. * * Optional fields are inserted only when they carry a value, so an omitted * option stays absent all the way down and the SDK keeps its own default. */ @implementation MyidSdk { MyidSdkImpl *_impl; } - (instancetype)init { if (self = [super init]) { _impl = [MyidSdkImpl new]; } return self; } /** Inserts the string under `key`, skipping nil (an absent JS key). */ static void MyidSdkPutString(NSMutableDictionary *target, NSString *key, NSString *value) { if (value != nil) { target[key] = value; } } static void MyidSdkPutNumber(NSMutableDictionary *target, NSString *key, std::optional value) { if (value.has_value()) { target[key] = @(value.value()); } } static void MyidSdkPutBool(NSMutableDictionary *target, NSString *key, std::optional value) { if (value.has_value()) { target[key] = @(value.value()); } } static NSDictionary *MyidSdkConfigToDictionary(JS::NativeMyidSdk::MyIdConfigInput &config) { NSMutableDictionary *result = [NSMutableDictionary new]; MyidSdkPutString(result, @"sessionId", config.sessionId()); MyidSdkPutString(result, @"clientHash", config.clientHash()); MyidSdkPutString(result, @"clientHashId", config.clientHashId()); MyidSdkPutNumber(result, @"minAge", config.minAge()); MyidSdkPutNumber(result, @"distance", config.distance()); MyidSdkPutString(result, @"residency", config.residency()); MyidSdkPutString(result, @"environment", config.environment()); MyidSdkPutString(result, @"entryType", config.entryType()); MyidSdkPutString(result, @"locale", config.locale()); MyidSdkPutString(result, @"cameraShape", config.cameraShape()); MyidSdkPutString(result, @"cameraSelector", config.cameraSelector()); MyidSdkPutString(result, @"presentationStyle", config.presentationStyle()); MyidSdkPutBool(result, @"showErrorScreen", config.showErrorScreen()); // cameraResolution, imageFormat, screenOrientation, withSoundGuides and // huaweiAppId are Android-only and have no counterpart in MyIdConfig here, // so they are intentionally not forwarded. auto organizationDetails = config.organizationDetails(); if (organizationDetails.has_value()) { NSMutableDictionary *details = [NSMutableDictionary new]; MyidSdkPutString(details, @"phone", organizationDetails.value().phone()); MyidSdkPutString(details, @"logo", organizationDetails.value().logo()); result[@"organizationDetails"] = details; } return result; } static NSDictionary *MyidSdkAppearanceToDictionary(JS::NativeMyidSdk::MyIdAppearanceInput &appearance) { NSMutableDictionary *result = [NSMutableDictionary new]; MyidSdkPutString(result, @"colorPrimary", appearance.colorPrimary()); MyidSdkPutString(result, @"colorOnPrimary", appearance.colorOnPrimary()); MyidSdkPutString(result, @"colorError", appearance.colorError()); MyidSdkPutString(result, @"colorOnError", appearance.colorOnError()); MyidSdkPutString(result, @"colorOutline", appearance.colorOutline()); MyidSdkPutString(result, @"colorDivider", appearance.colorDivider()); MyidSdkPutString(result, @"colorSuccess", appearance.colorSuccess()); MyidSdkPutString(result, @"colorButtonContainer", appearance.colorButtonContainer()); MyidSdkPutString(result, @"colorButtonContainerDisabled", appearance.colorButtonContainerDisabled()); MyidSdkPutString(result, @"colorButtonContent", appearance.colorButtonContent()); MyidSdkPutString(result, @"colorButtonContentDisabled", appearance.colorButtonContentDisabled()); MyidSdkPutString(result, @"colorScanButtonContainer", appearance.colorScanButtonContainer()); MyidSdkPutNumber(result, @"buttonCornerRadius", appearance.buttonCornerRadius()); return result; } - (void)start:(JS::NativeMyidSdk::MyIdConfigInput &)config appearance:(JS::NativeMyidSdk::MyIdAppearanceInput &)appearance resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject { [_impl startWithConfig:MyidSdkConfigToDictionary(config) appearance:MyidSdkAppearanceToDictionary(appearance) onSuccess:^(NSDictionary *payload) { resolve(payload); } onError:^(NSString *code, NSString *message) { reject(code, message, nil); }]; } /// Called when the module is torn down, e.g. a reload mid-flow. Mirrors the /// Android module: settle the in-flight promise instead of leaving it hanging. - (void)invalidate { [_impl cancelActive]; } - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { return std::make_shared(params); } + (NSString *)moduleName { return @"MyidSdk"; } @end