From 1421992e979ba6918f7323a317b0999feb5e276d Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Thu, 17 Aug 2023 16:36:09 +1000 Subject: [PATCH] WIP: PN mode selection screen --- Session.xcodeproj/project.pbxproj | 4 + Session/Onboarding/DisplayNameView.swift | 3 + Session/Onboarding/PNModeView.swift | 203 +++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 Session/Onboarding/PNModeView.swift diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 21da39d50..9dcd1f4fe 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -123,6 +123,7 @@ 7B81682C28B72F480069F315 /* PendingChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B81682B28B72F480069F315 /* PendingChange.swift */; }; 7B87EF422A8D9840002A0E8F /* DisplayNameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B87EF412A8D9840002A0E8F /* DisplayNameView.swift */; }; 7B87EF442A8DA720002A0E8F /* SessionTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B87EF432A8DA720002A0E8F /* SessionTextField.swift */; }; + 7B87EF462A8DDA8E002A0E8F /* PNModeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B87EF452A8DDA8E002A0E8F /* PNModeView.swift */; }; 7B8914772A7CAAE200A4C627 /* SessionHostingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8914762A7CAAE200A4C627 /* SessionHostingViewController.swift */; }; 7B8C44C528B49DDA00FBE25F /* NewConversationVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8C44C428B49DDA00FBE25F /* NewConversationVC.swift */; }; 7B8D5FC428332600008324D9 /* VisibleMessage+Reaction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B8D5FC328332600008324D9 /* VisibleMessage+Reaction.swift */; }; @@ -1239,6 +1240,7 @@ 7B81682B28B72F480069F315 /* PendingChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PendingChange.swift; sourceTree = ""; }; 7B87EF412A8D9840002A0E8F /* DisplayNameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayNameView.swift; sourceTree = ""; }; 7B87EF432A8DA720002A0E8F /* SessionTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionTextField.swift; sourceTree = ""; }; + 7B87EF452A8DDA8E002A0E8F /* PNModeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PNModeView.swift; sourceTree = ""; }; 7B8914762A7CAAE200A4C627 /* SessionHostingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionHostingViewController.swift; sourceTree = ""; }; 7B8C44C428B49DDA00FBE25F /* NewConversationVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewConversationVC.swift; sourceTree = ""; }; 7B8D5FC328332600008324D9 /* VisibleMessage+Reaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "VisibleMessage+Reaction.swift"; sourceTree = ""; }; @@ -3005,6 +3007,7 @@ B8D0A26825E4A2C200C1835E /* Onboarding.swift */, 7BDE2A972A8B122900AE4393 /* LandingView.swift */, 7B87EF412A8D9840002A0E8F /* DisplayNameView.swift */, + 7B87EF452A8DDA8E002A0E8F /* PNModeView.swift */, ); path = Onboarding; sourceTree = ""; @@ -6149,6 +6152,7 @@ B82B4090239DD75000A248E7 /* RestoreVC.swift in Sources */, 3488F9362191CC4000E524CC /* MediaView.swift in Sources */, B8569AC325CB5D2900DBA3DB /* ConversationVC+Interaction.swift in Sources */, + 7B87EF462A8DDA8E002A0E8F /* PNModeView.swift in Sources */, 3496955C219B605E00DCFE74 /* ImagePickerController.swift in Sources */, C31D1DE32521718E005D4DA8 /* UserSelectionVC.swift in Sources */, 34A6C28021E503E700B5B12E /* OWSImagePickerController.swift in Sources */, diff --git a/Session/Onboarding/DisplayNameView.swift b/Session/Onboarding/DisplayNameView.swift index 57c60129b..88e373822 100644 --- a/Session/Onboarding/DisplayNameView.swift +++ b/Session/Onboarding/DisplayNameView.swift @@ -118,6 +118,9 @@ struct DisplayNameView: View { } // Need to get the PN mode if registering + let viewController: SessionHostingViewController = SessionHostingViewController(rootView: PNModeView(flow: flow)) + viewController.setUpNavBarSessionIcon() + self.host.controller?.navigationController?.pushViewController(viewController, animated: true) } } diff --git a/Session/Onboarding/PNModeView.swift b/Session/Onboarding/PNModeView.swift new file mode 100644 index 000000000..8ec3b2105 --- /dev/null +++ b/Session/Onboarding/PNModeView.swift @@ -0,0 +1,203 @@ +// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved. + +import SwiftUI +import Combine +import SessionUIKit +import SessionMessagingKit +import SessionSnodeKit +import SignalUtilitiesKit +import SessionUtilitiesKit + +enum PNMode { + case fast + case slow +} + +struct PNModeView: View { + @EnvironmentObject var host: HostWrapper + + @State private var currentSelection: PNMode = .fast + + private let flow: Onboarding.Flow + + public init(flow: Onboarding.Flow) { + self.flow = flow + } + + let options: [PNOptionView.Info] = [ + PNOptionView.Info( + mode: .fast, + title: "fast_mode".localized(), + explanation: "fast_mode_explanation".localized(), + isRecommended: true + ), + PNOptionView.Info( + mode: .slow, + title: "slow_mode".localized(), + explanation: "slow_mode_explanation".localized(), + isRecommended: false + ) + ] + + var body: some View { + NavigationView { + ZStack(alignment: .center) { + if #available(iOS 14.0, *) { + ThemeManager.currentTheme.colorSwiftUI(for: .backgroundPrimary).ignoresSafeArea() + } else { + ThemeManager.currentTheme.colorSwiftUI(for: .backgroundPrimary) + } + + VStack( + alignment: .leading, + spacing: Values.mediumSpacing + ) { + Spacer() + + Text("vc_pn_mode_title".localized()) + .bold() + .font(.system(size: Values.veryLargeFontSize)) + .foregroundColor(themeColor: .textPrimary) + .padding(.vertical, Values.mediumSpacing) + + VStack( + alignment: .leading, + spacing: Values.mediumSpacing) + { + ForEach( + 0...(options.count - 1), + id: \.self + ) { index in + PNOptionView( + currentSelection: $currentSelection, + info: options[index] + ) + } + } + + Spacer() + } + .padding(.horizontal, Values.veryLargeSpacing) + .padding(.bottom, Values.massiveSpacing + Values.largeButtonHeight) + + VStack() { + Spacer() + + Button { + register() + } label: { + Text("continue_2".localized()) + .bold() + .font(.system(size: Values.smallFontSize)) + .foregroundColor(themeColor: .sessionButton_text) + .frame( + maxWidth: .infinity, + maxHeight: Values.largeButtonHeight, + alignment: .center + ) + .overlay( + Capsule() + .stroke(themeColor: .sessionButton_border) + ) + } + .padding(.horizontal, Values.massiveSpacing) + } + .padding(.vertical, Values.mediumSpacing) + } + } + } + + private func register() { + + } +} + +struct PNOptionView: View { + + struct Info { + let mode: PNMode + let title: String + let explanation: String + let isRecommended: Bool + } + + @Binding var currentSelection: PNMode + + let info: Info + + static let cornerRadius: CGFloat = 8 + static let radioBorderSize: CGFloat = 22 + static let radioSelectionSize: CGFloat = 17 + + var body: some View { + HStack( + spacing: Values.largeSpacing + ) { + VStack( + alignment: .leading, + spacing: Values.smallSpacing + ) { + Text(info.title) + .bold() + .font(.system(size: Values.mediumFontSize)) + .foregroundColor(themeColor: .textPrimary) + + Text(info.explanation) + .font(.system(size: Values.verySmallFontSize)) + .foregroundColor(themeColor: .textPrimary) + .frame( + maxWidth: .infinity, + alignment: .leading + ) + + if info.isRecommended { + Text("vc_pn_mode_recommended_option_tag".localized()) + .bold() + .font(.system(size: Values.smallFontSize)) + .foregroundColor(themeColor: .primary) + } + } + .frame(maxWidth: .infinity) + .padding(.all, Values.mediumSpacing) + .overlay( + RoundedRectangle( + cornerSize: CGSize( + width: Self.cornerRadius, + height: Self.cornerRadius + ) + ) + .stroke(themeColor: .borderSeparator) + ) + + ZStack(alignment: .center) { + Circle() + .stroke(themeColor: .textPrimary) + .frame( + width: Self.radioBorderSize, + height: Self.radioBorderSize + ) + + if currentSelection == info.mode { + Circle() + .fill(themeColor: .primary) + .frame( + width: Self.radioSelectionSize, + height: Self.radioSelectionSize + ) + } + } + } + .frame( + maxWidth: .infinity + ) + .onTapGesture { + currentSelection = info.mode + } + } +} + +struct PNModeView_Previews: PreviewProvider { + static var previews: some View { + PNModeView(flow: .register) + } +}