From 430ab89592c65924c93dcdff2b5d42b75d9f4973 Mon Sep 17 00:00:00 2001 From: Tilak Gondi Date: Wed, 19 Jul 2023 17:55:16 +0900 Subject: [PATCH 1/6] [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Enable passing the Project ID and subscription key using deep link. For eg., miniappdemo://miniapp/settings?projectid=abc&subscription=def **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) --- Example/ContentView.swift | 6 +- .../Settings/MiniAppSettingsView.swift | 27 ++++++--- .../SwiftUI/MiniAppDashboardView.swift | 5 +- Example/Models/SettingsParams.swift | 9 +++ Example/SampleApp.swift | 55 ++++++++++++++++++- Example/SceneDelegate.swift | 32 +++++++++++ Sample.xcodeproj/project.pbxproj | 4 ++ 7 files changed, 124 insertions(+), 14 deletions(-) create mode 100644 Example/Models/SettingsParams.swift diff --git a/Example/ContentView.swift b/Example/ContentView.swift index cfc95efb..10702593 100644 --- a/Example/ContentView.swift +++ b/Example/ContentView.swift @@ -1,13 +1,15 @@ import SwiftUI struct ContentView: View { + @StateObject var sharedSettingsVM: MiniAppSettingsViewModel + var body: some View { - MiniAppDashboardView() + MiniAppDashboardView(sharedSettingsVM: sharedSettingsVM) } } struct ContentView_Previews: PreviewProvider { static var previews: some View { - ContentView() + ContentView(sharedSettingsVM: MiniAppSettingsViewModel()) } } diff --git a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift index 07a21918..992f7ec2 100644 --- a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift +++ b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift @@ -5,8 +5,9 @@ import MiniApp // swiftlint:disable line_length struct MiniAppSettingsView: View { + @Environment(\.presentationMode) var presentationMode - @StateObject var viewModel = MiniAppSettingsViewModel() + @StateObject var viewModel: MiniAppSettingsViewModel @Binding var showFullProgress: Bool @@ -194,20 +195,32 @@ struct MiniAppSettingsView: View { trackButtonTap(pageName: pageName, buttonTitle: "Save") dismissKeyboard() viewModel.save() + viewModel.listConfig.persist() + viewModel.listConfigI.persist() + viewModel.listConfigII.persist() + if presentationMode.wrappedValue.isPresented { + presentationMode.wrappedValue.dismiss() + } } .disabled((viewModel.listConfig.wrappedProjectId.isEmpty || viewModel.listConfig.wrappedSubscriptionKey.isEmpty)) } } + .onAppear { + UITextField.appearance().clearButtonMode = .whileEditing + self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") + self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") + } .alert(item: $alertMessage) { errorMessage in Alert( title: Text(errorMessage.title), message: Text(errorMessage.message), - dismissButton: .default(Text("Ok")) + dismissButton: .default(Text("Ok"), action: { + self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") + self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") + + }) ) } - .onAppear { - UITextField.appearance().clearButtonMode = .whileEditing - } .onReceive(viewModel.$state) { state in switch state { case .loading: @@ -246,11 +259,9 @@ struct MiniAppSettingsView: View { case .production: viewModel.listConfig.projectId = viewModel.listConfig.projectIdProd viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyProd - case .staging: viewModel.listConfig.projectId = viewModel.listConfig.projectIdStaging viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyStaging - } self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") @@ -300,7 +311,7 @@ extension MiniAppSettingsView: ViewTrackable { struct MiniAppFeatureConfigView_Previews: PreviewProvider { static var previews: some View { - MiniAppSettingsView(showFullProgress: .constant(false)) + MiniAppSettingsView(viewModel: MiniAppSettingsViewModel(), showFullProgress: .constant(false)) } } // swiftlint:enable line_length diff --git a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift index 017b1ef2..c1b401d2 100644 --- a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift +++ b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift @@ -9,6 +9,7 @@ class MiniAppDashboardViewModel: ObservableObject { struct MiniAppDashboardView: View { @StateObject var viewModel = MiniAppDashboardViewModel() + @StateObject var sharedSettingsVM: MiniAppSettingsViewModel @State var sampleMiniAppId: String = "" @State var sampleMiniAppVersion: String = "" @@ -51,7 +52,7 @@ struct MiniAppDashboardView: View { .tag(2) NavigationView { - MiniAppSettingsView(showFullProgress: $isPresentingFullProgress) + MiniAppSettingsView(viewModel:sharedSettingsVM, showFullProgress: $isPresentingFullProgress) } .navigationViewStyle(.stack) .tabItem { @@ -95,6 +96,6 @@ struct MiniAppDashboardView: View { struct MiniAppDashboardView_Previews: PreviewProvider { static var previews: some View { - MiniAppDashboardView() + MiniAppDashboardView(sharedSettingsVM: MiniAppSettingsViewModel()) } } diff --git a/Example/Models/SettingsParams.swift b/Example/Models/SettingsParams.swift new file mode 100644 index 00000000..ddbb0be0 --- /dev/null +++ b/Example/Models/SettingsParams.swift @@ -0,0 +1,9 @@ +import Foundation + +struct SettingsParams: Equatable { + var tab: Int = 1 + var projectId: String = "" + var subscriptionKey: String = "" + var isProduction: Bool = false + var isPreviewMode: Bool = false +} diff --git a/Example/SampleApp.swift b/Example/SampleApp.swift index 52a65a7b..fe7877d4 100644 --- a/Example/SampleApp.swift +++ b/Example/SampleApp.swift @@ -8,12 +8,14 @@ struct SampleApp: App { let store = MiniAppStore.shared let deepLinkManager = DeeplinkManager() - + + @StateObject var sharedSettingsViewModel = MiniAppSettingsViewModel() @State var deepLink: SampleAppDeeplink? + var body: some Scene { WindowGroup { - ContentView() + ContentView(sharedSettingsVM: sharedSettingsViewModel) .accentColor(.red) .onOpenURL { url in let receivedDeepLink = deepLinkManager.manage(url: url) @@ -40,6 +42,9 @@ struct SampleApp: App { print(error) } } + case let .settings(settinsInfo): + prepareSettingsViewModel(with: settinsInfo) + deepLink = .settings(viewModel: self.sharedSettingsViewModel) } } .sheet(item: $deepLink) { @@ -56,19 +61,65 @@ struct SampleApp: App { ) } .accentColor(.red) + case .settings(let viewModel): + NavigationView { + MiniAppSettingsView(viewModel: viewModel, showFullProgress: .constant(false)) + } + .accentColor(.red) } } } } + + func prepareSettingsViewModel(with params: SettingsParams) { + if params.tab == 1 { + let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI)) + sharedSettingsViewModel.listConfig = list1 + sharedSettingsViewModel.listConfigI = list1 + sharedSettingsViewModel.listConfigI.persist() + } else { + let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII)) + sharedSettingsViewModel.listConfig = list2 + sharedSettingsViewModel.listConfigII = list2 + sharedSettingsViewModel.listConfigII.persist() + } + sharedSettingsViewModel.listConfig.persist() + sharedSettingsViewModel.selectedListConfig = params.tab == 1 ? .listI : .listII + } + + func setConfigValues(with params: SettingsParams, for listConfig:ListConfiguration) -> ListConfiguration { + var listConfig = listConfig + if params.isProduction { + listConfig.environmentMode = .production + listConfig.projectIdProd = params.projectId + listConfig.subscriptionKey = params.subscriptionKey + } else { + listConfig.environmentMode = .staging + listConfig.projectIdStaging = params.projectId + listConfig.subscriptionKeyStaging = params.subscriptionKey + } + if params.isPreviewMode { + listConfig.previewMode = .previewable + } else { + listConfig.previewMode = .published + } + listConfig.projectId = params.projectId + listConfig.subscriptionKey = params.subscriptionKey + listConfig.persist() + return listConfig + } } enum SampleAppDeeplink: Identifiable { case miniapp(info: MiniAppInfo) + case settings(viewModel: MiniAppSettingsViewModel) var id: String { switch self { case .miniapp(let info): return info.id + "_" + info.version.versionId + case .settings(let queryParams): + return "SettingsConfig" } } } diff --git a/Example/SceneDelegate.swift b/Example/SceneDelegate.swift index 21e7324e..59db5796 100644 --- a/Example/SceneDelegate.swift +++ b/Example/SceneDelegate.swift @@ -44,12 +44,14 @@ class DeeplinkManager { enum Path: String { case qrcode = "preview" case deeplink = "dl" + case settings = "settings" } enum Target: Equatable, Identifiable { case unknown case qrcode(code: String) case deeplink(id: String) + case settings(settingsParams: SettingsParams) var id: String { switch self { @@ -59,6 +61,8 @@ class DeeplinkManager { return code case let .deeplink(id): return id + case let .settings(settingsParams): + return settingsParams.projectId } } } @@ -77,6 +81,34 @@ class DeeplinkManager { case .deeplink: guard url.pathComponents.count > 1 else { return .unknown } return .deeplink(id: url.pathComponents[2]) + case .settings: + guard url.pathComponents.count > 1 else { return .unknown } + let settingsParams = self.getQueryItems(url.absoluteString) + return .settings(settingsParams: settingsParams) + } + } + + func getQueryItems(_ urlString: String) -> SettingsParams { + var queryItems: [String : String] = [:] + let components: NSURLComponents? = getURLComonents(urlString) + for item in components?.queryItems ?? [] { + queryItems[item.name] = item.value?.removingPercentEncoding + } + var settingsParams = SettingsParams() + settingsParams.tab = Int(queryItems["tab"] ?? "") ?? 1 + settingsParams.projectId = queryItems["projectid"] ?? "" + settingsParams.subscriptionKey = queryItems["subscription"] ?? "" + settingsParams.isProduction = Bool(queryItems["isProduction"] ?? "") ?? false + settingsParams.isPreviewMode = Bool(queryItems["isPreviewMode"] ?? "") ?? false + return settingsParams + } + + func getURLComonents(_ urlString: String?) -> NSURLComponents? { + var components: NSURLComponents? = nil + let linkUrl = URL(string: urlString?.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? "") + if let linkUrl = linkUrl { + components = NSURLComponents(url: linkUrl, resolvingAgainstBaseURL: true) } + return components } } diff --git a/Sample.xcodeproj/project.pbxproj b/Sample.xcodeproj/project.pbxproj index 7e4d0e85..74f90f48 100644 --- a/Sample.xcodeproj/project.pbxproj +++ b/Sample.xcodeproj/project.pbxproj @@ -17,6 +17,7 @@ 1C0A785C29C3417500433A38 /* AppTrackingTransparency.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C0A785A29C3417500433A38 /* AppTrackingTransparency.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; 1C0C5C892A0C973300CB1F63 /* HostAppThemeColorsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C0C5C882A0C973300CB1F63 /* HostAppThemeColorsView.swift */; }; 1C2E06AE293A6A99003C6380 /* MiniAppSecureStorageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C2E06AD293A6A99003C6380 /* MiniAppSecureStorageView.swift */; }; + 1C3FCFEB2A666DB3003C7A05 /* SettingsParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C3FCFEA2A666DB3003C7A05 /* SettingsParams.swift */; }; 1C6BAB472A5519340012E800 /* MAAnalyticsInfoLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6BAB462A5519340012E800 /* MAAnalyticsInfoLogger.swift */; }; 1C6BAB4B2A5522F60012E800 /* MAAnalyticsInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C6BAB4A2A5522F60012E800 /* MAAnalyticsInfoView.swift */; }; 1CD1591829421FDF001E0E21 /* UniversalBridgeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */; }; @@ -155,6 +156,7 @@ 1C0A785A29C3417500433A38 /* AppTrackingTransparency.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppTrackingTransparency.framework; path = System/Library/Frameworks/AppTrackingTransparency.framework; sourceTree = SDKROOT; }; 1C0C5C882A0C973300CB1F63 /* HostAppThemeColorsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HostAppThemeColorsView.swift; sourceTree = ""; }; 1C2E06AD293A6A99003C6380 /* MiniAppSecureStorageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MiniAppSecureStorageView.swift; sourceTree = ""; }; + 1C3FCFEA2A666DB3003C7A05 /* SettingsParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsParams.swift; sourceTree = ""; }; 1C6BAB462A5519340012E800 /* MAAnalyticsInfoLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MAAnalyticsInfoLogger.swift; sourceTree = ""; }; 1C6BAB4A2A5522F60012E800 /* MAAnalyticsInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MAAnalyticsInfoView.swift; sourceTree = ""; }; 1CD1591729421FDF001E0E21 /* UniversalBridgeView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UniversalBridgeView.swift; sourceTree = ""; }; @@ -444,6 +446,7 @@ children = ( 38920AD5251D9C57004C5DDD /* UserProfileModel.swift */, A13C249726A15048003ADC6D /* UserPointsModel.swift */, + 1C3FCFEA2A666DB3003C7A05 /* SettingsParams.swift */, ); path = Models; sourceTree = ""; @@ -877,6 +880,7 @@ F70DD8EC28D417C4003EF1F1 /* MiniAppSettingsQAView.swift in Sources */, F70DD8EA28D417C4003EF1F1 /* MiniAppSettingsProfileView.swift in Sources */, F70DD8E828D417C4003EF1F1 /* MiniAppSettingsView+Config.swift in Sources */, + 1C3FCFEB2A666DB3003C7A05 /* SettingsParams.swift in Sources */, F70DD8F628D417C4003EF1F1 /* MiniAppWithTermsView.swift in Sources */, A13198012918A45C00B839E8 /* View+Events.swift in Sources */, F70DD8EE28D417C4003EF1F1 /* MiniAppSettingsAccessTokenView.swift in Sources */, From e3cf0d2398c50ff3ace0805a657b822ac92439bb Mon Sep 17 00:00:00 2001 From: Tilak Gondi Date: Thu, 20 Jul 2023 10:54:29 +0900 Subject: [PATCH 2/6] [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix issue of keys not changing when switching List1-List2 in settings screen. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) --- .../Settings/MiniAppSettingsView.swift | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift index 992f7ec2..3b3d0a42 100644 --- a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift +++ b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift @@ -253,18 +253,13 @@ struct MiniAppSettingsView: View { () } } + .onChange(of: viewModel.listConfig.listType, perform: { _ in + self.dismissKeyboard() + self.updateKeys() + }) .onChange(of: viewModel.listConfig.environmentMode, perform: { _ in self.dismissKeyboard() - switch viewModel.listConfig.environmentMode { - case .production: - viewModel.listConfig.projectId = viewModel.listConfig.projectIdProd - viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyProd - case .staging: - viewModel.listConfig.projectId = viewModel.listConfig.projectIdStaging - viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyStaging - } - self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") - self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") + self.updateKeys() }) .trackPage(pageName: pageName) } @@ -273,6 +268,19 @@ struct MiniAppSettingsView: View { UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil) } + func updateKeys() { + switch viewModel.listConfig.environmentMode { + case .production: + viewModel.listConfig.projectId = viewModel.listConfig.projectIdProd + viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyProd + case .staging: + viewModel.listConfig.projectId = viewModel.listConfig.projectIdStaging + viewModel.listConfig.subscriptionKey = viewModel.listConfig.subscriptionKeyStaging + } + self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") + self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") + } + var hasListIErrors: Bool { return viewModel.listConfigI.error != nil } From e54f71e39bbe51b06609caa0b44ad9b81dc348c8 Mon Sep 17 00:00:00 2001 From: Tilak Gondi Date: Thu, 27 Jul 2023 16:51:00 +0900 Subject: [PATCH 3/6] [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix swiftlint violations. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) --- Example/ContentView.swift | 2 +- .../SwiftUI/Features/Settings/MiniAppSettingsView.swift | 1 - Example/Controllers/SwiftUI/MiniAppDashboardView.swift | 2 +- Example/SampleApp.swift | 9 ++++----- Example/SceneDelegate.swift | 8 ++++---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Example/ContentView.swift b/Example/ContentView.swift index 10702593..4aa33453 100644 --- a/Example/ContentView.swift +++ b/Example/ContentView.swift @@ -2,7 +2,7 @@ import SwiftUI struct ContentView: View { @StateObject var sharedSettingsVM: MiniAppSettingsViewModel - + var body: some View { MiniAppDashboardView(sharedSettingsVM: sharedSettingsVM) } diff --git a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift index 3b3d0a42..19968313 100644 --- a/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift +++ b/Example/Controllers/SwiftUI/Features/Settings/MiniAppSettingsView.swift @@ -217,7 +217,6 @@ struct MiniAppSettingsView: View { dismissButton: .default(Text("Ok"), action: { self.tmpProjectKey = maskedString(of: viewModel.listConfig.projectId ?? "") self.tmpSubscriptionKey = maskedString(of: viewModel.listConfig.subscriptionKey ?? "") - }) ) } diff --git a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift index c1b401d2..768a2468 100644 --- a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift +++ b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift @@ -52,7 +52,7 @@ struct MiniAppDashboardView: View { .tag(2) NavigationView { - MiniAppSettingsView(viewModel:sharedSettingsVM, showFullProgress: $isPresentingFullProgress) + MiniAppSettingsView(viewModel: sharedSettingsVM, showFullProgress: $isPresentingFullProgress) } .navigationViewStyle(.stack) .tabItem { diff --git a/Example/SampleApp.swift b/Example/SampleApp.swift index fe7877d4..6249b9b2 100644 --- a/Example/SampleApp.swift +++ b/Example/SampleApp.swift @@ -8,10 +8,9 @@ struct SampleApp: App { let store = MiniAppStore.shared let deepLinkManager = DeeplinkManager() - + @StateObject var sharedSettingsViewModel = MiniAppSettingsViewModel() @State var deepLink: SampleAppDeeplink? - var body: some Scene { WindowGroup { @@ -70,7 +69,7 @@ struct SampleApp: App { } } } - + func prepareSettingsViewModel(with params: SettingsParams) { if params.tab == 1 { let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI)) @@ -86,8 +85,8 @@ struct SampleApp: App { sharedSettingsViewModel.listConfig.persist() sharedSettingsViewModel.selectedListConfig = params.tab == 1 ? .listI : .listII } - - func setConfigValues(with params: SettingsParams, for listConfig:ListConfiguration) -> ListConfiguration { + + func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration { var listConfig = listConfig if params.isProduction { listConfig.environmentMode = .production diff --git a/Example/SceneDelegate.swift b/Example/SceneDelegate.swift index 59db5796..b60b3932 100644 --- a/Example/SceneDelegate.swift +++ b/Example/SceneDelegate.swift @@ -87,9 +87,9 @@ class DeeplinkManager { return .settings(settingsParams: settingsParams) } } - + func getQueryItems(_ urlString: String) -> SettingsParams { - var queryItems: [String : String] = [:] + var queryItems: [String: String] = [:] let components: NSURLComponents? = getURLComonents(urlString) for item in components?.queryItems ?? [] { queryItems[item.name] = item.value?.removingPercentEncoding @@ -102,9 +102,9 @@ class DeeplinkManager { settingsParams.isPreviewMode = Bool(queryItems["isPreviewMode"] ?? "") ?? false return settingsParams } - + func getURLComonents(_ urlString: String?) -> NSURLComponents? { - var components: NSURLComponents? = nil + var components: NSURLComponents? let linkUrl = URL(string: urlString?.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlQueryAllowed) ?? "") if let linkUrl = linkUrl { components = NSURLComponents(url: linkUrl, resolvingAgainstBaseURL: true) From 815a9aba498b852ed010075017b8746ee062c2db Mon Sep 17 00:00:00 2001 From: Tilak Gondi Date: Thu, 31 Aug 2023 14:37:27 +0900 Subject: [PATCH 4/6] [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix issues identified by QA. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) --- .../SwiftUI/MiniAppDashboardView.swift | 45 ++++++++++++++++++ Example/SampleApp.swift | 47 ++----------------- 2 files changed, 48 insertions(+), 44 deletions(-) diff --git a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift index 768a2468..306b4ac0 100644 --- a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift +++ b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift @@ -8,6 +8,8 @@ class MiniAppDashboardViewModel: ObservableObject { struct MiniAppDashboardView: View { + let deepLinkManager = DeeplinkManager() + @StateObject var viewModel = MiniAppDashboardViewModel() @StateObject var sharedSettingsVM: MiniAppSettingsViewModel @@ -76,6 +78,20 @@ struct MiniAppDashboardView: View { selection = 3 } } + .onOpenURL{url in + let receivedDeepLink = deepLinkManager.manage(url: url) + switch receivedDeepLink { + case .unknown: + return + case .qrcode(_): + return + case .deeplink(_): + return + case let .settings(settinsInfo): + prepareSettingsViewModel(with: settinsInfo) + selection = 3 + } + } } var navigationTitle: String { @@ -92,6 +108,35 @@ struct MiniAppDashboardView: View { return "Unknown" } } + + func prepareSettingsViewModel(with params: SettingsParams) { + if params.tab == 1 { + let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI)) + sharedSettingsVM.listConfigI = list1 + } else { + let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII)) + sharedSettingsVM.listConfigII = list2 + } + sharedSettingsVM.selectedListConfig = params.tab == 1 ? .listI : .listII + } + + func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration { + var listConfig = listConfig + listConfig.listType = params.tab == 1 ? .listI : .listII + if params.isProduction { + listConfig.environmentMode = .production + } else { + listConfig.environmentMode = .staging + } + if params.isPreviewMode { + listConfig.previewMode = .previewable + } else { + listConfig.previewMode = .published + } + listConfig.projectId = params.projectId + listConfig.subscriptionKey = params.subscriptionKey + return listConfig + } } struct MiniAppDashboardView_Previews: PreviewProvider { diff --git a/Example/SampleApp.swift b/Example/SampleApp.swift index 6249b9b2..20bea3b1 100644 --- a/Example/SampleApp.swift +++ b/Example/SampleApp.swift @@ -41,9 +41,8 @@ struct SampleApp: App { print(error) } } - case let .settings(settinsInfo): - prepareSettingsViewModel(with: settinsInfo) - deepLink = .settings(viewModel: self.sharedSettingsViewModel) + case let .settings(_): + return } } .sheet(item: $deepLink) { @@ -61,52 +60,12 @@ struct SampleApp: App { } .accentColor(.red) case .settings(let viewModel): - NavigationView { - MiniAppSettingsView(viewModel: viewModel, showFullProgress: .constant(false)) - } + MiniAppDashboardView(sharedSettingsVM: viewModel, selection: 3) .accentColor(.red) } } } } - - func prepareSettingsViewModel(with params: SettingsParams) { - if params.tab == 1 { - let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI)) - sharedSettingsViewModel.listConfig = list1 - sharedSettingsViewModel.listConfigI = list1 - sharedSettingsViewModel.listConfigI.persist() - } else { - let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII)) - sharedSettingsViewModel.listConfig = list2 - sharedSettingsViewModel.listConfigII = list2 - sharedSettingsViewModel.listConfigII.persist() - } - sharedSettingsViewModel.listConfig.persist() - sharedSettingsViewModel.selectedListConfig = params.tab == 1 ? .listI : .listII - } - - func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration { - var listConfig = listConfig - if params.isProduction { - listConfig.environmentMode = .production - listConfig.projectIdProd = params.projectId - listConfig.subscriptionKey = params.subscriptionKey - } else { - listConfig.environmentMode = .staging - listConfig.projectIdStaging = params.projectId - listConfig.subscriptionKeyStaging = params.subscriptionKey - } - if params.isPreviewMode { - listConfig.previewMode = .previewable - } else { - listConfig.previewMode = .published - } - listConfig.projectId = params.projectId - listConfig.subscriptionKey = params.subscriptionKey - listConfig.persist() - return listConfig - } } enum SampleAppDeeplink: Identifiable { From cdac2b410a64c616e75b45eb8d113653651ae029 Mon Sep 17 00:00:00 2001 From: Tilak Gondi Date: Thu, 31 Aug 2023 16:37:34 +0900 Subject: [PATCH 5/6] [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix swiftlint violations. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) --- Example/Controllers/SwiftUI/MiniAppDashboardView.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift index 306b4ac0..fdd397c9 100644 --- a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift +++ b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift @@ -9,7 +9,7 @@ class MiniAppDashboardViewModel: ObservableObject { struct MiniAppDashboardView: View { let deepLinkManager = DeeplinkManager() - + @StateObject var viewModel = MiniAppDashboardViewModel() @StateObject var sharedSettingsVM: MiniAppSettingsViewModel @@ -78,14 +78,14 @@ struct MiniAppDashboardView: View { selection = 3 } } - .onOpenURL{url in + .onOpenURL { url in let receivedDeepLink = deepLinkManager.manage(url: url) switch receivedDeepLink { case .unknown: return - case .qrcode(_): + case .qrcode: return - case .deeplink(_): + case .deeplink: return case let .settings(settinsInfo): prepareSettingsViewModel(with: settinsInfo) @@ -108,7 +108,7 @@ struct MiniAppDashboardView: View { return "Unknown" } } - + func prepareSettingsViewModel(with params: SettingsParams) { if params.tab == 1 { let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI)) From 6384fd392236355cc356074fc1edd708a45ead20 Mon Sep 17 00:00:00 2001 From: "tilak.gondi" <115203844+GondiTilak@users.noreply.github.com> Date: Fri, 1 Sep 2023 14:05:57 +0900 Subject: [PATCH 6/6] Update Example/Controllers/SwiftUI/MiniAppDashboardView.swift Commit for suggested changes. Co-authored-by: leojoseph.r <58416454+rleojoseph@users.noreply.github.com> --- Example/Controllers/SwiftUI/MiniAppDashboardView.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift index fdd397c9..634cdb2a 100644 --- a/Example/Controllers/SwiftUI/MiniAppDashboardView.swift +++ b/Example/Controllers/SwiftUI/MiniAppDashboardView.swift @@ -81,11 +81,7 @@ struct MiniAppDashboardView: View { .onOpenURL { url in let receivedDeepLink = deepLinkManager.manage(url: url) switch receivedDeepLink { - case .unknown: - return - case .qrcode: - return - case .deeplink: + case .unknown, .qrcode, .deeplink: return case let .settings(settinsInfo): prepareSettingsViewModel(with: settinsInfo)