Skip to content

Commit

Permalink
Merge pull request #372 from Infomaniak/onboarding
Browse files Browse the repository at this point in the history
Onboarding
  • Loading branch information
PhilippeWeidmann authored Oct 28, 2022
2 parents 94afd36 + 70ceee7 commit d8ba1a0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
6 changes: 6 additions & 0 deletions Mail/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import UIKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
private var accountManager: AccountManager!
static var orientationLock = UIInterfaceOrientationMask.all

func application(
_ application: UIApplication,
Expand Down Expand Up @@ -68,6 +69,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}

func application(_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
return AppDelegate.orientationLock
}

func refreshCacheData() {
guard let currentAccount = AccountManager.instance.currentAccount else {
return
Expand Down
26 changes: 26 additions & 0 deletions Mail/Views/Onboarding/OnboardingView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct OnboardingView: View {
private var isScrollEnabled: Bool

@Environment(\.window) var window
@Environment(\.dismiss) private var dismiss

private var isPresentedModally: Bool

Expand Down Expand Up @@ -65,6 +66,20 @@ struct OnboardingView: View {
.scaledToFit()
.frame(height: Constants.onboardingLogoHeight)
.padding(.top, isPresentedModally ? 15 : 0)

if !isScrollEnabled {
HStack {
Button {
dismiss()
} label: {
Image(systemName: "xmark")
.resizable()
}
.frame(width: 20, height: 20, alignment: .leading)
.padding(16)
Spacer()
}
}
}

// Buttons
Expand Down Expand Up @@ -101,6 +116,17 @@ struct OnboardingView: View {
} message: {
Text(MailResourcesStrings.Localizable.errorLoginDescription)
}
.onAppear {
if UIDevice.current.userInterfaceIdiom == .phone {
if #available(iOS 16.0, *) {
window?.windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
} else {
UIDevice.current
.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")
}
AppDelegate.orientationLock = .portrait
}
}
}

// MARK: - Private methods
Expand Down
18 changes: 7 additions & 11 deletions Mail/Views/Onboarding/SlideView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,13 @@ struct SlideView: View {
var body: some View {
GeometryReader { proxy in
ZStack(alignment: .top) {
slide.backgroundImage
.resizable()
.scaledToFit()
.ignoresSafeArea()
.foregroundColor(colorScheme == .light ? accentColor.secondary : MailResourcesAsset.backgroundColor)
// Hide image if it cannot fit
.background(GeometryReader { geometry -> Color in
imageSize = geometry.size
return .clear
})
.opacity(proxy.size.width == imageSize.width ? 1 : 0)
if (proxy.size.height > proxy.size.width) || (UIDevice.current.userInterfaceIdiom == .pad) {
slide.backgroundImage
.resizable(resizingMode: .stretch)
.ignoresSafeArea()
.fixedSize(horizontal: false, vertical: true)
.foregroundColor(colorScheme == .light ? accentColor.secondary : MailResourcesAsset.backgroundColor)
}

VStack(spacing: 0) {
Spacer(minLength: Constants.onboardingLogoHeight + Constants.onboardingVerticalPadding)
Expand Down
1 change: 1 addition & 0 deletions Mail/Views/SplitView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ struct SplitView: View {
.defaultAppStorage(.shared)
.onAppear {
navigationDrawerController.window = window
AppDelegate.orientationLock = .all
}
.task {
await fetchSignatures()
Expand Down
11 changes: 7 additions & 4 deletions Mail/Views/Switch User/AccountListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension Account: Hashable {

class AccountListViewModel: ObservableObject {
@Published var expandedUserId: Int? = AccountManager.instance.currentUserId
@Published var isShowingNewAccountView = false

@Published var accounts = [Account: [Mailbox]]()

private var mailboxObservationToken: NotificationToken?
Expand Down Expand Up @@ -62,6 +62,7 @@ class AccountListViewModel: ObservableObject {

struct AccountListView: View {
@StateObject private var viewModel = AccountListViewModel()
@State var isShowingNewAccountView = false

var body: some View {
ScrollView {
Expand All @@ -79,11 +80,13 @@ struct AccountListView: View {
.background(MailResourcesAsset.backgroundColor.swiftUiColor)
.navigationBarTitle(MailResourcesStrings.Localizable.titleMyAccounts, displayMode: .inline)
.floatingActionButton(icon: Image(systemName: "plus"), title: MailResourcesStrings.Localizable.buttonAddAccount) {
viewModel.isShowingNewAccountView = true
isShowingNewAccountView = true
}
.sheet(isPresented: $viewModel.isShowingNewAccountView) {
.sheet(isPresented: $isShowingNewAccountView, onDismiss: {
AppDelegate.orientationLock = .all
}, content: {
OnboardingView(isPresentedModally: true, page: 4, isScrollEnabled: false)
}
})
.task {
try? await updateUsers()
}
Expand Down

0 comments on commit d8ba1a0

Please sign in to comment.