Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: TODOs and tests in WireUI - WPB-11346 #2011

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public final class AccountImageView: UIView {
guard let accountImageViewWrapper = accountImageView.superview else { return }

accountImageViewWrapper.layer.cornerRadius = if isTeamAccount {
teamAccountImageCornerRadius
teamAccountImageCornerRadius // TODO: [WPB-11449] is this even needed? We always show the user's image
} else {
accountImageViewWrapper.frame.height / 2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public struct SidebarViewDesign {
public let accountInfoViewUsernameColor = ColorTheme.Base.secondaryText
public let menuItemTitleForegroundColor = ColorTheme.Backgrounds.onBackground
public let menuItemLinkIconForegroundColor = ColorTheme.Base.secondaryText
public let menuItemIsPressedTitleForegroundColor = ColorTheme.Base.onPrimary
public let menuItemIsSelectedTitleForegroundColor = ColorTheme.Base.onPrimary

public init() {}
}
18 changes: 10 additions & 8 deletions WireUI/Sources/WireMainNavigation/MainCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import UIKit

public typealias MainCoordinator = GenericMainCoordinator

// swiftlint:disable opening_brace

/// Manages the main navigation and the layout changes of the application after a successful login.
Expand All @@ -31,7 +33,7 @@ import UIKit
/// instances and then put or remove the content view controllers into/from `viewControllers` array.

@MainActor
public final class MainCoordinator<
public final class GenericMainCoordinator<

SplitViewController: MainSplitViewControllerProtocol,
ConversationBuilder: MainConversationBuilderProtocol,
Expand Down Expand Up @@ -192,7 +194,7 @@ public final class MainCoordinator<

dismissArchiveIfNeeded()
dismissSettingsIfNeeded()
await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()

// Move the conversation list from the tab bar controller to the split view controller if needed.
if let conversationList = tabBarController.conversationList {
Expand Down Expand Up @@ -222,7 +224,7 @@ public final class MainCoordinator<

dismissConversationListIfNeeded()
dismissSettingsIfNeeded()
await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()

// move the archive from the tab bar controller to the split view controller
if let archive = tabBarController.archive {
Expand All @@ -243,7 +245,7 @@ public final class MainCoordinator<

dismissConversationListIfNeeded()
dismissArchiveIfNeeded()
await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()

// move the settings from the tab bar controller to the split view controller
if let settings = tabBarController.settings {
Expand All @@ -262,7 +264,7 @@ public final class MainCoordinator<
splitViewController.hideSidebar()
}

await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()

let conversation = conversationBuilder.build(
conversation: conversation,
Expand Down Expand Up @@ -320,7 +322,7 @@ public final class MainCoordinator<
selfProfile.modalPresentationStyle = .formSheet
self.selfProfile = selfProfile

await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()
await withCheckedContinuation { continuation in
splitViewController.present(selfProfile, animated: true, completion: continuation.resume)
}
Expand Down Expand Up @@ -369,7 +371,7 @@ public final class MainCoordinator<
splitViewController.hideSidebar()
}

await dismissPresentedViewControllerIfNeeded()
await dismissPresentedViewController()
await withCheckedContinuation { continuation in
splitViewController.present(viewController, animated: true, completion: continuation.resume)
}
Expand Down Expand Up @@ -399,7 +401,7 @@ public final class MainCoordinator<
}
}

private func dismissPresentedViewControllerIfNeeded() async {
public func dismissPresentedViewController() async {
await withCheckedContinuation { continuation in
splitViewController.dismiss(animated: true, completion: continuation.resume)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ final class PreviewConversationListViewController: UIHostingController<LabelView
// MARK: - MainConversationListProtocol

var conversationFilter: ConversationFilter?
var selectedConversation: ConversationModel?
var mainSplitViewState: MainSplitViewState = .expanded

enum ConversationFilter: MainConversationFilterRepresentable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class PreviewConversationViewController: UIHostingController<LabelView>, M
struct ConversationModel {}
struct ConversationMessageModel {}

var conversationModel: ConversationModel! { .init() }

// MARK: - Life Cycle

convenience init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public protocol MainConversationBuilderProtocol {
message: Conversation.ConversationMessageModel?,
mainCoordinator: MainCoordinator
) -> Conversation where
MainCoordinator.ConversationList == ConversationList,
MainCoordinator.SettingsContentBuilder == SettingsBuilder,
MainCoordinator.ConversationModel == Conversation.ConversationModel,
MainCoordinator.ConversationMessageModel == Conversation.ConversationMessageModel,
MainCoordinator.User == User
MainCoordinator.ConversationList == ConversationList,
MainCoordinator.SettingsContentBuilder == SettingsBuilder,
MainCoordinator.ConversationModel == Conversation.ConversationModel,
MainCoordinator.ConversationMessageModel == Conversation.ConversationMessageModel,
MainCoordinator.User == User
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

import UIKit

@MainActor
public protocol MainConversationProtocol: UIViewController {
associatedtype ConversationModel
associatedtype ConversationMessageModel

var conversationModel: ConversationModel! { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ import UIKit
public protocol MainConversationListProtocol: UIViewController {

associatedtype ConversationFilter: MainConversationFilterRepresentable
associatedtype ConversationModel

/// Assigning a non-nil value to this property filters the presented conversations by the provided criteria.
var conversationFilter: ConversationFilter? { get set }

/// The conversation which is represented by the list selection.
var selectedConversation: ConversationModel? { get }

/// Allows the ``MainCoordinator`` to inform this instance about the current split view state.
var mainSplitViewState: MainSplitViewState { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public protocol MainCoordinatorInjectingViewControllerBuilder {
func build<MainCoordinator: MainCoordinatorProtocol>(
mainCoordinator: MainCoordinator
) -> ViewController where
MainCoordinator.ConversationList == ConversationList,
MainCoordinator.SettingsContentBuilder == SettingsBuilder,
MainCoordinator.ConversationModel == ConversationModel,
MainCoordinator.ConversationMessageModel == ConversationMessageModel,
MainCoordinator.User == User
MainCoordinator.ConversationList == ConversationList,
MainCoordinator.SettingsContentBuilder == SettingsBuilder,
MainCoordinator.ConversationModel == ConversationModel,
MainCoordinator.ConversationMessageModel == ConversationMessageModel,
MainCoordinator.User == User
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ public protocol MainCoordinatorProtocol: AnyObject {

@MainActor
func presentViewController(_ viewController: UIViewController) async
@MainActor
func dismissPresentedViewController() async
}
13 changes: 9 additions & 4 deletions WireUI/Sources/WireSidebar/Models/SidebarModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ final class SidebarModel: ObservableObject {
@Published var wireAccentColorMapping: WireAccentColorMapping?
@Published var wireTextStyleMapping: WireTextStyleMapping?
@Published var sidebarBackgroundColor: UIColor = .systemGray5
@Published var sidebarAccountInfoViewDisplayNameColor: UIColor = .darkText
@Published var sidebarAccountInfoViewUsernameColor: UIColor = .systemGray
@Published var sidebarMenuItemTitleForegroundColor: UIColor = .darkText
@Published var sidebarAccountInfoViewDisplayNameColor: UIColor = defaultTextColor
@Published var sidebarAccountInfoViewUsernameColor: UIColor = .gray
@Published var sidebarMenuHeaderForegroundColor: UIColor = defaultTextColor
@Published var sidebarMenuItemTitleForegroundColor: UIColor = defaultTextColor
@Published var sidebarMenuItemLinkIconForegroundColor: UIColor = .systemGray
@Published var sidebarMenuItemIsPressedTitleForegroundColor: UIColor = .systemBlue
@Published var sidebarMenuItemIsSelectedTitleForegroundColor: UIColor = .systemBackground

@Published var accountInfo = SidebarAccountInfo()
@Published var selectedMenuItem: SidebarSelectableMenuItem = .all {
Expand All @@ -55,3 +56,7 @@ final class SidebarModel: ObservableObject {
self.supportAction = supportAction
}
}

private let defaultTextColor = UIColor {
$0.userInterfaceStyle == .dark ? .white : .darkText
}
26 changes: 13 additions & 13 deletions WireUI/Sources/WireSidebar/Views/SidebarMenuItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct SidebarMenuItemView: View {

@Environment(\.sidebarMenuItemTitleForegroundColor) private var titleForegroundColor
@Environment(\.sidebarMenuItemLinkIconForegroundColor) private var linkIconForegroundColor
@Environment(\.sidebarMenuItemIsPressedTitleForegroundColor) private var isPressedTitleForegroundColor
@Environment(\.sidebarMenuItemIsSelectedTitleForegroundColor) private var isSelectedTitleForegroundColor

/// The `systemName` which is passed into `SwiftUI.Image`.
private(set) var icon: String
Expand All @@ -55,11 +55,11 @@ struct SidebarMenuItemView: View {
HStack {
Label {
title()
.foregroundStyle(isHighlighted ? isPressedTitleForegroundColor : titleForegroundColor)
.foregroundStyle(isHighlighted ? isSelectedTitleForegroundColor : titleForegroundColor)
} icon: {
let iconSystemNameSuffix = isHighlighted ? ".fill" : ""
let icon = Image(systemName: icon + iconSystemNameSuffix)
.foregroundStyle(isHighlighted ? isPressedTitleForegroundColor : Color(accentColor))
.foregroundStyle(isHighlighted ? isSelectedTitleForegroundColor : Color(accentColor))
.background(GeometryReader { geometryProxy in
Color.clear.preference(key: SidebarMenuItemMinIconSizeKey.self, value: geometryProxy.size)
})
Expand All @@ -74,7 +74,7 @@ struct SidebarMenuItemView: View {

if isLink {
Image(systemName: "arrow.up.forward.square")
.foregroundStyle(isHighlighted ? isPressedTitleForegroundColor : linkIconForegroundColor)
.foregroundStyle(isHighlighted ? isSelectedTitleForegroundColor : linkIconForegroundColor)
}
}
.contentShape(RoundedRectangle(cornerRadius: backgroundCornerRadius))
Expand Down Expand Up @@ -108,8 +108,8 @@ extension View {
modifier(SidebarMenuItemLinkIconForegroundColorViewModifier(linkIconForegroundColor: linkIconForegroundColor))
}

func sidebarMenuItemIsPressedTitleForegroundColor(_ isPressedTitleForegroundColor: Color) -> some View {
modifier(SidebarMenuItemIsPressedTitleForegroundColorViewModifier(isPressedTitleForegroundColor: isPressedTitleForegroundColor))
func sidebarMenuItemIsSelectedTitleForegroundColor(_ isSelectedTitleForegroundColor: Color) -> some View {
modifier(SidebarMenuItemIsSelectedTitleForegroundColorViewModifier(isSelectedTitleForegroundColor: isSelectedTitleForegroundColor))
}
}

Expand All @@ -124,9 +124,9 @@ private extension EnvironmentValues {
set { self[SidebarMenuItemLinkIconForegroundColorKey.self] = newValue }
}

var sidebarMenuItemIsPressedTitleForegroundColor: Color {
get { self[SidebarMenuItemIsPressedTitleForegroundColorKey.self] }
set { self[SidebarMenuItemIsPressedTitleForegroundColorKey.self] = newValue }
var sidebarMenuItemIsSelectedTitleForegroundColor: Color {
get { self[SidebarMenuItemIsSelectedTitleForegroundColorKey.self] }
set { self[SidebarMenuItemIsSelectedTitleForegroundColorKey.self] = newValue }
}
}

Expand Down Expand Up @@ -154,15 +154,15 @@ private struct SidebarMenuItemLinkIconForegroundColorKey: EnvironmentKey {
static let defaultValue = Color.primary.opacity(0.6)
}

struct SidebarMenuItemIsPressedTitleForegroundColorViewModifier: ViewModifier {
var isPressedTitleForegroundColor: Color
struct SidebarMenuItemIsSelectedTitleForegroundColorViewModifier: ViewModifier {
var isSelectedTitleForegroundColor: Color
func body(content: Content) -> some View {
content
.environment(\.sidebarMenuItemIsPressedTitleForegroundColor, isPressedTitleForegroundColor)
.environment(\.sidebarMenuItemIsSelectedTitleForegroundColor, isSelectedTitleForegroundColor)
}
}

private struct SidebarMenuItemIsPressedTitleForegroundColorKey: EnvironmentKey {
private struct SidebarMenuItemIsSelectedTitleForegroundColorKey: EnvironmentKey {
static let defaultValue = Color.white
}

Expand Down
27 changes: 25 additions & 2 deletions WireUI/Sources/WireSidebar/Views/SidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import WireFoundation

public struct SidebarView<AccountImageView>: View where AccountImageView: View {

@Environment(\.sidebarBackgroundColor) private var sidebarBackgroundColor
@Environment(\.sidebarMenuHeaderForegroundColor) private var menuHeaderForegroundColor
@Environment(\.sidebarBackgroundColor) private var backgroundViewColor

public var accountInfo: SidebarAccountInfo?
@Binding public var selectedMenuItem: SidebarSelectableMenuItem
Expand Down Expand Up @@ -57,7 +58,7 @@ public struct SidebarView<AccountImageView>: View where AccountImageView: View {
ZStack {
// background color
Rectangle()
.foregroundStyle(sidebarBackgroundColor)
.foregroundStyle(backgroundViewColor)
.ignoresSafeArea()

// content
Expand Down Expand Up @@ -123,6 +124,7 @@ public struct SidebarView<AccountImageView>: View where AccountImageView: View {
@ViewBuilder
private func menuItemHeader(_ key: LocalizedStringKey, addTopPadding: Bool = true) -> some View {
let text = Text(key, bundle: .module)
.foregroundStyle(menuHeaderForegroundColor)
.wireTextStyle(.h2)
.padding(.horizontal, 8)
.padding(.vertical, 12)
Expand Down Expand Up @@ -205,18 +207,39 @@ public struct SidebarView<AccountImageView>: View where AccountImageView: View {
// MARK: - View Modifiers + Environment

extension View {
func sidebarMenuHeaderForegroundColor(_ headerForegroundColor: Color) -> some View {
modifier(SidebarMenuHeaderForegroundColorViewModifier(headerForegroundColor: headerForegroundColor))
}

func sidebarBackgroundColor(_ sidebarBackgroundColor: Color) -> some View {
modifier(SidebarBackgroundColorViewModifier(sidebarBackgroundColor: sidebarBackgroundColor))
}
}

private extension EnvironmentValues {
var sidebarMenuHeaderForegroundColor: Color {
get { self[SidebarMenuHeaderForegroundColorKey.self] }
set { self[SidebarMenuHeaderForegroundColorKey.self] = newValue }
}

var sidebarBackgroundColor: Color {
get { self[SidebarBackgroundColorKey.self] }
set { self[SidebarBackgroundColorKey.self] = newValue }
}
}

struct SidebarMenuHeaderForegroundColorViewModifier: ViewModifier {
var headerForegroundColor: Color
func body(content: Content) -> some View {
content
.environment(\.sidebarMenuHeaderForegroundColor, headerForegroundColor)
}
}

private struct SidebarMenuHeaderForegroundColorKey: EnvironmentKey {
static let defaultValue = Color.primary
}

struct SidebarBackgroundColorViewModifier: ViewModifier {
var sidebarBackgroundColor: Color
func body(content: Content) -> some View {
Expand Down
14 changes: 10 additions & 4 deletions WireUI/Sources/WireSidebar/Views/SidebarViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public final class SidebarViewController: UIViewController {
set { model.sidebarAccountInfoViewUsernameColor = newValue }
}

public var sidebarMenuHeaderForegroundColor: UIColor {
get { model.sidebarMenuHeaderForegroundColor }
set { model.sidebarMenuHeaderForegroundColor = newValue }
}

public var sidebarMenuItemTitleForegroundColor: UIColor {
get { model.sidebarMenuItemTitleForegroundColor }
set { model.sidebarMenuItemTitleForegroundColor = newValue }
Expand All @@ -79,9 +84,9 @@ public final class SidebarViewController: UIViewController {
set { model.sidebarMenuItemLinkIconForegroundColor = newValue }
}

public var sidebarMenuItemIsPressedTitleForegroundColor: UIColor {
get { model.sidebarMenuItemIsPressedTitleForegroundColor }
set { model.sidebarMenuItemIsPressedTitleForegroundColor = newValue }
public var sidebarMenuItemIsSelectedTitleForegroundColor: UIColor {
get { model.sidebarMenuItemIsSelectedTitleForegroundColor }
set { model.sidebarMenuItemIsSelectedTitleForegroundColor = newValue }
}

// MARK: - Private Properties
Expand Down Expand Up @@ -168,9 +173,10 @@ private struct SidebarAdapter<AccountImageView>: View where AccountImageView: Vi
.sidebarBackgroundColor(.init(uiColor: model.sidebarBackgroundColor))
.sidebarAccountInfoViewDisplayNameColor(.init(uiColor: model.sidebarAccountInfoViewDisplayNameColor))
.sidebarAccountInfoViewUsernameColor(.init(uiColor: model.sidebarAccountInfoViewUsernameColor))
.sidebarMenuHeaderForegroundColor(.init(uiColor: model.sidebarMenuHeaderForegroundColor))
.sidebarMenuItemTitleForegroundColor(.init(uiColor: model.sidebarMenuItemTitleForegroundColor))
.sidebarMenuItemLinkIconForegroundColor(.init(uiColor: model.sidebarMenuItemLinkIconForegroundColor))
.sidebarMenuItemIsPressedTitleForegroundColor(.init(uiColor: model.sidebarMenuItemIsPressedTitleForegroundColor))
.sidebarMenuItemIsSelectedTitleForegroundColor(.init(uiColor: model.sidebarMenuItemIsSelectedTitleForegroundColor))
.environment(\.wireAccentColor, model.wireAccentColor)
.environment(\.wireAccentColorMapping, model.wireAccentColorMapping)
.environment(\.wireTextStyleMapping, model.wireTextStyleMapping)
Expand Down
Loading
Loading