diff --git a/Nativebrik.podspec b/Nativebrik.podspec index 9fd8a1b..e033977 100644 --- a/Nativebrik.podspec +++ b/Nativebrik.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'Nativebrik' - s.version = '0.4.2' + s.version = '0.5.0' s.summary = 'Nativebrik SDK' s.description = <<-DESC Nativebrik SDK for iOS. diff --git a/ios/Nativebrik/Nativebrik/data/cotnainer.swift b/ios/Nativebrik/Nativebrik/data/cotnainer.swift index 96bbfd1..b4db455 100644 --- a/ios/Nativebrik/Nativebrik/data/cotnainer.swift +++ b/ios/Nativebrik/Nativebrik/data/cotnainer.swift @@ -78,6 +78,8 @@ class ContainerImpl: Container { private let databaseRepository: DatabaseRepository private let httpRequestRepository: HttpRequestRepository + private let arguments: Any? + init(config: Config, user: NativebrikUser, persistentContainer: NSPersistentContainer, intercepter: NativebrikHttpRequestInterceptor? = nil) { self.config = config self.user = user @@ -88,13 +90,15 @@ class ContainerImpl: Container { self.formRepository = nil self.databaseRepository = DatabaseRepositoryImpl(persistentContainer: persistentContainer) self.httpRequestRepository = HttpRequestRepositoryImpl(intercepter: intercepter) + + self.arguments = nil } // should be refactored. // this is because, i wanted to initialize form instance for each component, not to share the same instance from every components. // this is called when component is instantiated. // bad code. - init(_ container: ContainerImpl) { + init(_ container: ContainerImpl, arguments: Any?) { self.config = container.config self.user = container.user self.persistentContainer = container.persistentContainer @@ -104,6 +108,7 @@ class ContainerImpl: Container { self.formRepository = FormRepositoryImpl() self.databaseRepository = container.databaseRepository self.httpRequestRepository = container.httpRequestRepository + self.arguments = arguments } func handleEvent(_ it: UIBlockEventDispatcher) { @@ -116,6 +121,7 @@ class ContainerImpl: Container { data: data, properties: properties, form: self.formRepository?.getFormData(), + arguments: self.arguments, projectId: self.config.projectId ) } diff --git a/ios/Nativebrik/Nativebrik/data/variable.swift b/ios/Nativebrik/Nativebrik/data/variable.swift index 20af1f8..3a5b68c 100644 --- a/ios/Nativebrik/Nativebrik/data/variable.swift +++ b/ios/Nativebrik/Nativebrik/data/variable.swift @@ -12,6 +12,7 @@ func _createVariableForTemplate( data: Any? = nil, properties: [Property]? = nil, form: [String: Any]? = nil, + arguments: Any? = nil, projectId: String? = nil ) -> Any { let userData: [String:Any] = (user != nil) ? [ @@ -34,6 +35,7 @@ func _createVariableForTemplate( "user": (userData.isEmpty ? nil : userData) as Any, "props": (propertiesData.isEmpty ? nil : propertiesData) as Any, "form": (formData?.isEmpty == true ? nil : formData) as Any, + "args": arguments as Any, "data": data as Any, "project": projectData as Any, ] @@ -48,6 +50,7 @@ func _mergeVariable(base: Any?, _ overlay: Any?) -> Any? { "user": overlay?["user"] ?? base["user"] as Any, "props": overlay?["props"] ?? base["props"] as Any, "form": overlay?["form"] ?? base["form"] as Any, + "args": overlay?["args"] ?? base["args"] as Any, "data": overlay?["data"] ?? base["data"] as Any, "project": overlay?["project"] ?? base["project"] as Any, ] diff --git a/ios/Nativebrik/Nativebrik/remote-config.swift b/ios/Nativebrik/Nativebrik/remote-config.swift index 9cb3200..2c188d9 100644 --- a/ios/Nativebrik/Nativebrik/remote-config.swift +++ b/ios/Nativebrik/Nativebrik/remote-config.swift @@ -77,14 +77,14 @@ public class RemoteConfigVariant { public func getAsView( _ key: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil ) -> some View { let componentId = self.get(key) return EmbeddingSwiftView( experimentId: self.experimentId, componentId: componentId, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.modalViewController, onEvent: onEvent ) @@ -92,7 +92,7 @@ public class RemoteConfigVariant { public func getAsView( _ key: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil, @ViewBuilder content: (@escaping (_ phase: AsyncEmbeddingPhase) -> V) ) -> some View { @@ -100,7 +100,7 @@ public class RemoteConfigVariant { return EmbeddingSwiftView.init( experimentId: self.experimentId, componentId: componentId, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.modalViewController, onEvent: onEvent, content: content @@ -109,7 +109,7 @@ public class RemoteConfigVariant { public func getAsUIView( _ key: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil ) -> UIView? { guard let componentId = self.get(key) else { @@ -118,7 +118,7 @@ public class RemoteConfigVariant { let uiview = EmbeddingUIView( experimentId: self.experimentId, componentId: componentId, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.modalViewController, onEvent: onEvent, fallback: nil @@ -128,7 +128,7 @@ public class RemoteConfigVariant { public func getAsUIView( _ key: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil, content: @escaping (_ phase: EmbeddingPhase) -> UIView ) -> UIView? { @@ -138,7 +138,7 @@ public class RemoteConfigVariant { let uiview = EmbeddingUIView( experimentId: self.experimentId, componentId: componentId, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.modalViewController, onEvent: onEvent, fallback: content diff --git a/ios/Nativebrik/Nativebrik/sdk.swift b/ios/Nativebrik/Nativebrik/sdk.swift index e544f25..d6d5396 100644 --- a/ios/Nativebrik/Nativebrik/sdk.swift +++ b/ios/Nativebrik/Nativebrik/sdk.swift @@ -9,7 +9,7 @@ import Foundation import SwiftUI import Combine -public let nativebrikSdkVersion = "0.4.2" +public let nativebrikSdkVersion = "0.5.0" public let isNativebrikAvailable: Bool = { if #available(iOS 15.0, *) { return true @@ -152,7 +152,7 @@ public class NativebrikExperiment { public func embedding( _ id: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil ) -> some View { if !isNativebrikAvailable { @@ -160,7 +160,7 @@ public class NativebrikExperiment { } return AnyView(EmbeddingSwiftView( experimentId: id, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.overlayVC.modalViewController, onEvent: onEvent )) @@ -168,7 +168,7 @@ public class NativebrikExperiment { public func embedding( _ id: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil, @ViewBuilder content: (@escaping (_ phase: AsyncEmbeddingPhase) -> V) ) -> some View { @@ -178,7 +178,7 @@ public class NativebrikExperiment { return AnyView(EmbeddingSwiftView.init( experimentId: id, componentId: nil, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.overlayVC.modalViewController, onEvent: onEvent, content: content @@ -187,7 +187,7 @@ public class NativebrikExperiment { public func embeddingUIView( _ id: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil ) -> UIView { if !isNativebrikAvailable { @@ -195,7 +195,7 @@ public class NativebrikExperiment { } return EmbeddingUIView( experimentId: id, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.overlayVC.modalViewController, onEvent: onEvent, fallback: nil @@ -204,7 +204,7 @@ public class NativebrikExperiment { public func embeddingUIView( _ id: String, - arguments: [String:Any?]? = nil, + arguments: Any? = nil, onEvent: ((_ event: ComponentEvent) -> Void)? = nil, content: @escaping (_ phase: EmbeddingPhase) -> UIView ) -> UIView { @@ -213,7 +213,7 @@ public class NativebrikExperiment { } return EmbeddingUIView( experimentId: id, - container: ContainerImpl(self.container as! ContainerImpl), + container: ContainerImpl(self.container as! ContainerImpl, arguments: arguments), modalViewController: self.overlayVC.modalViewController, onEvent: onEvent, fallback: content @@ -230,7 +230,7 @@ public class NativebrikExperiment { } let _ = RemoteConfig( experimentId: id, - container: ContainerImpl(self.container as! ContainerImpl), + container: self.container, modalViewController: self.overlayVC.modalViewController, phase: phase )