Skip to content

Commit

Permalink
[PM-11490] iOS 18 fix broken account switcher (#926)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedemkr authored Sep 16, 2024
1 parent 3aaef4c commit 6f6ee54
Show file tree
Hide file tree
Showing 27 changed files with 9 additions and 85 deletions.
20 changes: 0 additions & 20 deletions BitwardenShared/UI/Auth/Landing/LandingProcessorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -862,26 +862,6 @@ class LandingProcessorTests: BitwardenTestCase { // swiftlint:disable:this type_
XCTAssertEqual(coordinator.routes, [])
}

/// `receive(_:)` with `.profileSwitcher(.scrollOffset)` updates the state to reflect the changes.
@MainActor
func test_receive_scrollOffset() {
let active = ProfileSwitcherItem.fixture()
subject.state.profileSwitcherState = ProfileSwitcherState(
accounts: [active],
activeAccountId: active.userId,
allowLockAndLogout: true,
isVisible: true,
scrollOffset: .zero
)

let newPoint = CGPoint(x: 0, y: 100)
subject.receive(.profileSwitcher(.scrollOffsetChanged(newPoint)))

XCTAssertNotNil(subject.state.profileSwitcherState)
XCTAssertTrue(subject.state.profileSwitcherState.isVisible)
XCTAssertEqual(subject.state.profileSwitcherState.scrollOffset, newPoint)
}

/// `receive(_:)` with `.toastShown` updates the state's toast value.
@MainActor
func test_receive_toastShown() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,4 @@ enum ProfileSwitcherAction: Equatable {

/// The user tapped the background area of the view
case backgroundPressed

/// The offset of the scrollView Changed
case scrollOffsetChanged(CGPoint)
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ extension ProfileSwitcherHandler {
}
case .backgroundPressed:
profileSwitcherState.isVisible = false
case let .scrollOffsetChanged(newOffset):
profileSwitcherState.scrollOffset = newOffset
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ struct ProfileSwitcherState: Equatable {
/// A flag for view visibility.
var isVisible: Bool

/// The observed offset of the scrollView.
var scrollOffset: CGPoint

/// A flag to indicate if an add account row should be visible.
private let shouldAlwaysHideAddAccount: Bool

Expand All @@ -60,7 +57,6 @@ struct ProfileSwitcherState: Equatable {
/// - allowLockAndLogout: Should the view be allowed to lock and logout accounts?
/// - currentAccountProfile: The current `ProfileSwitcherItem` profile.
/// - isVisible: The visibility of the view.
/// - scrollOffset: The offset of the scroll view.
/// - shouldAlwaysHideAddAccount: Overrides visibility of the add account row.
/// - showPlaceholderToolbarIcon: Should the handler replace the toolbar icon with two dots?
///
Expand All @@ -69,15 +65,13 @@ struct ProfileSwitcherState: Equatable {
activeAccountId: String?,
allowLockAndLogout: Bool,
isVisible: Bool,
scrollOffset: CGPoint = .zero,
shouldAlwaysHideAddAccount: Bool = false,
showPlaceholderToolbarIcon: Bool = false
) {
self.accounts = accounts
self.activeAccountId = activeAccountId
self.allowLockAndLogout = allowLockAndLogout
self.isVisible = isVisible
self.scrollOffset = scrollOffset
self.shouldAlwaysHideAddAccount = shouldAlwaysHideAddAccount
self.showPlaceholderToolbarIcon = showPlaceholderToolbarIcon
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ struct ProfileSwitcherView: View {
/// The `Store` for this view.
@ObservedObject var store: Store<ProfileSwitcherState, ProfileSwitcherAction, ProfileSwitcherEffect>

@SwiftUI.State var scrollOffset = CGPoint.zero

var body: some View {
OffsetObservingScrollView(
axes: store.state.isVisible ? .vertical : [],
offset: .init(
get: { store.state.scrollOffset },
set: { store.send(.scrollOffsetChanged($0)) }
)
axes: .vertical,
offset: $scrollOffset
) {
VStack(spacing: 0.0) {
accounts
Expand Down Expand Up @@ -65,12 +64,12 @@ struct ProfileSwitcherView: View {

/// A background view with accessibility enabled
private var backgroundView: some View {
VStack {
Asset.Colors.backgroundPrimary.swiftUIColor
.frame(height: abs(min(store.state.scrollOffset.y, 0)))
.fixedSize(horizontal: false, vertical: true)
ZStack(alignment: .top) {
Color.black.opacity(0.4)
.ignoresSafeArea()
Asset.Colors.backgroundPrimary.swiftUIColor
.frame(height: abs(min(scrollOffset.y, 0)))
.fixedSize(horizontal: false, vertical: true)
}
.hidden(!store.state.isVisible)
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1167,26 +1167,6 @@ class VaultUnlockProcessorTests: BitwardenTestCase { // swiftlint:disable:this t
XCTAssertTrue(appExtensionDelegate.didCancelCalled)
}

/// `receive(_:)` with `.profileSwitcher(.scrollOffset)` updates the state to reflect the changes.
@MainActor
func test_receive_scrollOffset() {
let active = ProfileSwitcherItem.fixture()
subject.state.profileSwitcherState = ProfileSwitcherState(
accounts: [active],
activeAccountId: active.userId,
allowLockAndLogout: true,
isVisible: true,
scrollOffset: .zero
)

let newPoint = CGPoint(x: 0, y: 100)
subject.receive(.profileSwitcher(.scrollOffsetChanged(newPoint)))

XCTAssertNotNil(subject.state.profileSwitcherState)
XCTAssertTrue(subject.state.profileSwitcherState.isVisible)
XCTAssertEqual(subject.state.profileSwitcherState.scrollOffset, newPoint)
}

/// `receive(_:)` with `.toastShown` updates the state's toast value.
@MainActor
func test_receive_toastShown() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,6 @@ class VaultAutofillListProcessorTests: BitwardenTestCase { // swiftlint:disable:
XCTAssertTrue(subject.state.profileSwitcherState.isVisible)
}

/// `receive(_:)` with `.profileSwitcher(.scrollOffsetChanged)` updates the scroll offset.
@MainActor
func test_receive_profileSwitcher_scrollOffset() {
subject.state.profileSwitcherState.scrollOffset = .zero
subject.receive(.profileSwitcher(.scrollOffsetChanged(CGPoint(x: 10, y: 10))))
XCTAssertEqual(subject.state.profileSwitcherState.scrollOffset, CGPoint(x: 10, y: 10))
}

/// `receive(_:)` with `.searchStateChanged` updates the state when the search state changes.
@MainActor
func test_receive_searchStateChanged() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -436,14 +436,6 @@ class VaultItemSelectionProcessorTests: BitwardenTestCase { // swiftlint:disable
XCTAssertTrue(subject.state.profileSwitcherState.isVisible)
}

/// `receive(_:)` with `.profileSwitcher(.scrollOffsetChanged)` updates the scroll offset.
@MainActor
func test_receive_profileSwitcher_scrollOffset() {
subject.state.profileSwitcherState.scrollOffset = .zero
subject.receive(.profileSwitcher(.scrollOffsetChanged(CGPoint(x: 10, y: 10))))
XCTAssertEqual(subject.state.profileSwitcherState.scrollOffset, CGPoint(x: 10, y: 10))
}

/// `receive(_:)` with `.searchStateChanged` updates the state when the search state changes.
@MainActor
func test_receive_searchStateChanged() {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -993,14 +993,6 @@ class VaultListProcessorTests: BitwardenTestCase { // swiftlint:disable:this typ
XCTAssertFalse(subject.state.profileSwitcherState.isVisible)
}

/// `receive(_:)` with `ProfileSwitcherAction.scrollOffsetChanged` updates the scroll offset.
@MainActor
func test_receive_profileSwitcherScrollOffset() {
subject.state.profileSwitcherState.scrollOffset = .zero
subject.receive(.profileSwitcher(.scrollOffsetChanged(CGPoint(x: 10, y: 10))))
XCTAssertEqual(subject.state.profileSwitcherState.scrollOffset, CGPoint(x: 10, y: 10))
}

/// `receive(_:)` with `.searchStateChanged(isSearching: false)` hides the profile switcher
@MainActor
func test_receive_searchTextChanged_false_noProfilesChange() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private struct SearchableVaultListView: View {
@ViewBuilder
private func vaultContents(with sections: [VaultListSection]) -> some View {
ScrollView {
VStack(spacing: 20) {
LazyVStack(spacing: 20) {
vaultFilterRow

ForEach(sections) { section in
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6f6ee54

Please sign in to comment.