Skip to content

Commit

Permalink
fix: theme settings not respected & simplify theming
Browse files Browse the repository at this point in the history
  • Loading branch information
ntnhon committed May 27, 2024
1 parent 81ed02e commit d1d8f92
Show file tree
Hide file tree
Showing 38 changed files with 35 additions and 168 deletions.
8 changes: 4 additions & 4 deletions AutoFill/CredentialProviderCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 53,6 @@ final class CredentialProviderCoordinator: DeinitPrintable {
private let router = resolve(\SharedRouterContainer.mainUIKitSwiftUIRouter)
private let corruptedSessionEventStream = resolve(\SharedDataStreamContainer.corruptedSessionEventStream)

private let theme = resolve(\SharedToolingContainer.theme)
private weak var rootViewController: UIViewController?
private weak var context: ASCredentialProviderExtensionContext?
private var cancellables = Set<AnyCancellable>()
Expand Down Expand Up @@ -124,7 123,8 @@ final class CredentialProviderCoordinator: DeinitPrintable {
guard let self else { return }
do {
try await preferencesManager.setUp()
rootViewController?.view.overrideUserInterfaceStyle = theme.userInterfaceStyle
let theme = preferencesManager.sharedPreferences.unwrapped().theme
rootViewController?.overrideUserInterfaceStyle = theme.userInterfaceStyle
start(mode: mode)
} catch {
handle(error: error)
Expand Down Expand Up @@ -381,7 381,6 @@ private extension CredentialProviderCoordinator {
guard let self else { return }
cancelAutoFill(reason: .userCanceled, context: context)
}
.theme(theme)
showView(view)
}

Expand Down Expand Up @@ -435,7 434,8 @@ private extension CredentialProviderCoordinator {

func present(_ viewController: UIViewController, animated: Bool = true, dismissible: Bool = false) {
viewController.isModalInPresentation = !dismissible
viewController.overrideUserInterfaceStyle = theme.userInterfaceStyle
viewController.overrideUserInterfaceStyle = rootViewController?
.overrideUserInterfaceStyle ?? .unspecified
topMostViewController?.present(viewController, animated: animated)
}

Expand Down
3 changes: 0 additions & 3 deletions AutoFill/Scenes/CredentialsView/CredentialsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 31,6 @@ import SwiftUI
struct CredentialsView: View {
@StateObject private var viewModel: CredentialsViewModel
@FocusState private var isFocusedOnSearchBar
private let theme = resolve(\SharedToolingContainer.theme)

init(viewModel: CredentialsViewModel) {
_viewModel = .init(wrappedValue: viewModel)
Expand All @@ -46,7 45,6 @@ struct CredentialsView: View {
.task {
await viewModel.sync()
}
.theme(theme)
.localAuthentication(delayed: false,
onAuth: {},
onSuccess: viewModel.handleAuthenticationSuccess,
Expand Down Expand Up @@ -82,7 80,6 @@ struct CredentialsView: View {
if let info = viewModel.selectPasskeySheetInformation,
let context = viewModel.context {
SelectPasskeyView(info: info, context: context)
.theme(theme)
.presentationDetents([.height(CGFloat(info.passkeys.count * 60) 80)])
}
}
Expand Down
2 changes: 0 additions & 2 deletions AutoFill/Scenes/ExtensionSettings/ExtensionSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,6 @@ import SwiftUI

struct ExtensionSettingsView: View {
@StateObject private var viewModel = ExtensionSettingsViewModel()
private let theme = resolve(\SharedToolingContainer.theme)

private let onDismiss: () -> Void
private let onLogOut: () -> Void
Expand Down Expand Up @@ -83,7 82,6 @@ struct ExtensionSettingsView: View {
}
}
}
.theme(theme)
.localAuthentication(delayed: false,
onAuth: {},
onSuccess: {},
Expand Down
2 changes: 0 additions & 2 deletions AutoFill/Scenes/LockedCredential/LockedCredentialView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,6 @@ import SwiftUI

/// When autofilling from QuickType bar but local authentication is turned on
struct LockedCredentialView: View {
private let theme = resolve(\SharedToolingContainer.theme)
let viewModel: LockedCredentialViewModel

init(viewModel: LockedCredentialViewModel) {
Expand All @@ -41,7 40,6 @@ struct LockedCredentialView: View {
onFailure: { viewModel.handleAuthenticationFailure() })
.toolbar { toolbarContent }
}
.theme(theme)
}

@ToolbarContentBuilder
Expand Down
2 changes: 0 additions & 2 deletions AutoFill/Scenes/Passkey/PasskeyCredentialsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 28,6 @@ import SwiftUI

struct PasskeyCredentialsView: View {
@StateObject private var viewModel: PasskeyCredentialsViewModel
private let theme = resolve(\SharedToolingContainer.theme)
private let onCreate: () -> Void
private let onCancel: () -> Void

Expand Down Expand Up @@ -63,7 62,6 @@ struct PasskeyCredentialsView: View {
onRetry: { Task { await viewModel.loadCredentials() } })
}
}
.theme(theme)
.showSpinner(viewModel.isCreatingPasskey)
.alert("Create passkey",
isPresented: $viewModel.isShowingAssociationConfirmation,
Expand Down
3 changes: 0 additions & 3 deletions LocalPackages/Core/Sources/Core/Coordinator/Coordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 37,6 @@ public protocol CoordinatorProtocol: AnyObject {
// animated: Bool,
// dismissible: Bool)
func present(_ viewController: UIViewController,
userInterfaceStyle: UIUserInterfaceStyle,
animated: Bool,
dismissible: Bool,
uniquenessTag: (any RawRepresentable<Int>)?)
Expand Down Expand Up @@ -76,13 75,11 @@ public extension CoordinatorProtocol {
/// When `uniquenessTag` is set and there is a sheet that holds the same tag,
/// we dismiss the top most sheet and do nothing. Otherwise we present the sheet as normal
func present(_ viewController: UIViewController,
userInterfaceStyle: UIUserInterfaceStyle,
animated: Bool = true,
dismissible: Bool = true,
uniquenessTag: (any RawRepresentable<Int>)? = nil) {
viewController.sheetPresentationController?.preferredCornerRadius = 16
viewController.isModalInPresentation = !dismissible
viewController.overrideUserInterfaceStyle = userInterfaceStyle
if let uniquenessTag {
viewController.view.tag = uniquenessTag.rawValue
if rootViewController.containsUniqueSheet(uniquenessTag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 48,7 @@ public extension ExtensionCoordinator {

let viewController = UIHostingController(rootView: view)
viewController.view.translatesAutoresizingMaskIntoConstraints = false
viewController.overrideUserInterfaceStyle = rootViewController.overrideUserInterfaceStyle
rootViewController.view.addSubview(viewController.view)
NSLayoutConstraint.activate([
viewController.view.topAnchor.constraint(equalTo: rootViewController.view.topAnchor),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 68,6 @@ public extension UIViewController {
}
return false
}

/// Override `userInterfaceStyle` of the current view controller as well as its presented view controllers
func setUserInterfaceStyle(_ userInterfaceStyle: UIUserInterfaceStyle) {
overrideUserInterfaceStyle = userInterfaceStyle
guard let presentationController = presentedViewController else {
return
}
presentationController.overrideUserInterfaceStyle = userInterfaceStyle
}
}

private extension UIViewController {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,11 20,23 @@
//

import Foundation
import UIKit

public enum Theme: Int, Codable, CaseIterable, Sendable {
case light = 0
case dark = 1
case matchSystem = 2

public static var `default`: Self { .dark }

public var userInterfaceStyle: UIUserInterfaceStyle {
switch self {
case .light:
.light
case .dark:
.dark
case .matchSystem:
.unspecified
}
}
}
2 changes: 0 additions & 2 deletions Share/ShareCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 74,6 @@ final class ShareCoordinator {
private let credentialProvider = resolve(\SharedDataContainer.credentialProvider)
private let setUpSentry = resolve(\SharedUseCasesContainer.setUpSentry)
private let setCoreLoggerEnvironment = resolve(\SharedUseCasesContainer.setCoreLoggerEnvironment)
private let theme = resolve(\SharedToolingContainer.theme)
private let router = resolve(\SharedRouterContainer.mainUIKitSwiftUIRouter)
private let sendErrorToSentry = resolve(\SharedUseCasesContainer.sendErrorToSentry)
private let wipeAllData = resolve(\SharedUseCasesContainer.wipeAllData)
Expand Down Expand Up @@ -195,7 194,6 @@ private extension ShareCoordinator {
guard let self else { return }
dismissExtension()
}
.theme(theme)
showView(view)
}

Expand Down
2 changes: 0 additions & 2 deletions Share/SharedContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,6 @@ import ProtonCoreUIFoundations
import SwiftUI

struct SharedContentView: View {
private let theme = resolve(\SharedToolingContainer.theme)
let content: SharedContent
let onCreate: (SharedItemType) -> Void
let onDismiss: () -> Void
Expand Down Expand Up @@ -58,7 57,6 @@ struct SharedContentView: View {
.toolbar { toolbarContent }
.navigationTitle("Create")
.navigationStackEmbeded()
.theme(theme)
}
}

Expand Down
2 changes: 0 additions & 2 deletions iOS/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 68,6 @@ final class SceneDelegate: UIResponder, UIWindowSceneDelegate {

private extension SceneDelegate {
struct AppCoverView: View {
private let theme = resolve(\SharedToolingContainer.theme)
let windowSize: CGSize

var body: some View {
Expand All @@ -83,7 82,6 @@ private extension SceneDelegate {
.frame(width: min(windowSize.width, windowSize.height) * 2 / 3)
.frame(maxWidth: 245)
}
.theme(theme)
}
}

Expand Down
8 changes: 6 additions & 2 deletions iOS/Scenes/App/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 67,10 @@ final class AppCoordinator {

private let sendErrorToSentry = resolve(\SharedUseCasesContainer.sendErrorToSentry)

private var theme: Theme {
preferencesManager.sharedPreferences.unwrapped().theme
}

init(window: UIWindow) {
self.window = window
appStateObserver = .init()
Expand Down Expand Up @@ -152,6 156,7 @@ final class AppCoordinator {
guard let self else { return }
do {
try await preferencesManager.setUp()
window.overrideUserInterfaceStyle = theme.userInterfaceStyle
start()
} catch {
appStateObserver.updateAppState(.loggedOut(.failedToInitializePreferences(error)))
Expand All @@ -173,7 178,7 @@ private extension AppCoordinator {

func showWelcomeScene(reason: LogOutReason) {
let welcomeCoordinator = WelcomeCoordinator(apiService: apiManager.apiService,
preferences: preferences)
theme: theme)
welcomeCoordinator.delegate = self
self.welcomeCoordinator = welcomeCoordinator
homepageCoordinator = nil
Expand Down Expand Up @@ -203,7 208,6 @@ private extension AppCoordinator {
func animateUpdateRootViewController(_ newRootViewController: UIViewController,
completion: (() -> Void)? = nil) {
window.rootViewController = newRootViewController
window.overrideUserInterfaceStyle = preferences.theme.userInterfaceStyle
UIView.transition(with: window,
duration: 0.35,
options: .transitionCrossDissolve,
Expand Down
3 changes: 0 additions & 3 deletions iOS/Scenes/DeepLinks/TotpLogins/TotpLoginsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 32,6 @@ struct TotpLoginsView: View {
@FocusState private var isFocusedOnSearchBar
@Environment(\.dismiss) private var dismiss

private let theme = resolve(\SharedToolingContainer.theme)

var body: some View {
ZStack {
PassColor.backgroundNorm.toColor
Expand All @@ -45,7 43,6 @@ struct TotpLoginsView: View {
.task {
await viewModel.loadLogins()
}
.theme(theme)
.navigationBarTitleDisplayMode(.inline)
.navigationTitle("Set up 2FA")
.toolbarBackground(PassColor.backgroundNorm.toColor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 26,6 @@ import ProtonCoreUIFoundations
import SwiftUI

struct CreateAliasLiteView: View {
private let theme = resolve(\SharedToolingContainer.theme)
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: CreateAliasLiteViewModel
@FocusState private var focusedField: Field?
Expand Down Expand Up @@ -101,7 100,6 @@ struct CreateAliasLiteView: View {
}
}
}
.theme(theme)
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 30,6 @@ import SwiftUI
import TipKit

struct CreateEditLoginView: View {
private let theme = resolve(\SharedToolingContainer.theme)
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: CreateEditLoginViewModel
@FocusState private var focusedField: Field?
Expand Down Expand Up @@ -162,7 161,6 @@ struct CreateEditLoginView: View {
.toolbar { keyboardToolbar }
}
.tint(viewModel.itemContentType().normMajor2Color.toColor)
.theme(theme)
.obsoleteItemAlert(isPresented: $viewModel.isObsolete, onAction: dismiss.callAsFunction)
.discardChangesAlert(isPresented: $isShowingDiscardAlert, onDiscard: dismiss.callAsFunction)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 25,6 @@ import ProtonCoreUIFoundations
import SwiftUI

struct CreateEditNoteView: View {
private let theme = resolve(\SharedToolingContainer.theme)
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: CreateEditNoteViewModel
@FocusState private var focusedField: Field?
Expand Down Expand Up @@ -92,7 91,6 @@ struct CreateEditNoteView: View {
onSave: { viewModel.save() })
}
}
.theme(theme)
.tint(viewModel.itemContentType().normMajor1Color.toColor)
.obsoleteItemAlert(isPresented: $viewModel.isObsolete, onAction: dismiss.callAsFunction)
.discardChangesAlert(isPresented: $isShowingDiscardAlert, onDiscard: dismiss.callAsFunction)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 34,6 @@ protocol CustomFieldAdditionDelegate: AnyObject {
final class CustomFieldAdditionCoordinator: DeinitPrintable, CustomCoordinator {
deinit { print(deinitMessage) }

private let theme = resolve(\SharedToolingContainer.theme)
weak var rootViewController: UIViewController?
weak var delegate: (any CustomFieldAdditionDelegate)?

Expand All @@ -61,7 60,6 @@ final class CustomFieldAdditionCoordinator: DeinitPrintable, CustomCoordinator {
}

viewController.sheetPresentationController?.prefersGrabberVisible = true
viewController.overrideUserInterfaceStyle = theme.userInterfaceStyle
rootViewController?.topMostViewController.present(viewController, animated: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 26,6 @@ import ProtonCoreUIFoundations
import SwiftUI

struct GeneratePasswordView: View {
private var theme = resolve(\SharedToolingContainer.theme)
@Environment(\.dismiss) private var dismiss
@StateObject private var viewModel: GeneratePasswordViewModel

Expand Down Expand Up @@ -123,7 122,6 @@ struct GeneratePasswordView: View {
}
}
}
.theme(theme)
}

private var passwordTypeRow: some View {
Expand Down
Loading

0 comments on commit d1d8f92

Please sign in to comment.