Fix #2652 - Room list looping and fighting scrolling after filtering

- also fixes filtering empty state vertical centering
This commit is contained in:
Stefan Ceriu
2024-04-23 12:16:10 +03:00
parent 23d5089287
commit 89927f1357
3 changed files with 46 additions and 23 deletions
@@ -121,6 +121,18 @@ struct HomeScreenViewState: BindableState {
var shouldShowEmptyFilterState: Bool { var shouldShowEmptyFilterState: Bool {
!bindings.isSearchFieldFocused && bindings.filtersState.isFiltering && visibleRooms.isEmpty !bindings.isSearchFieldFocused && bindings.filtersState.isFiltering && visibleRooms.isEmpty
} }
var shouldShowFilters: Bool {
!bindings.isSearchFieldFocused
}
var shouldShowRecoveryKeyConfirmationBanner: Bool {
securityBannerMode == .recoveryKeyConfirmation
}
var shouldShowInvitesButton: Bool {
!ServiceLocator.shared.settings.roomListInvitesEnabled && hasPendingInvitations && !bindings.isSearchFieldFocused
}
} }
struct HomeScreenViewStateBindings { struct HomeScreenViewStateBindings {
@@ -14,6 +14,7 @@
// limitations under the License. // limitations under the License.
// //
import Compound
import SwiftUI import SwiftUI
struct HomeScreenContent: View { struct HomeScreenContent: View {
@@ -54,10 +55,7 @@ struct HomeScreenContent: View {
case .rooms: case .rooms:
LazyVStack(spacing: 0) { LazyVStack(spacing: 0) {
Section { Section {
if context.viewState.shouldShowEmptyFilterState { if !context.viewState.shouldShowEmptyFilterState {
RoomListFiltersEmptyStateView(state: context.filtersState)
.frame(height: geometry.size.height)
} else {
HomeScreenRoomList(context: context) HomeScreenRoomList(context: context)
} }
} header: { } header: {
@@ -88,12 +86,19 @@ struct HomeScreenContent: View {
.onChange(of: context.viewState.visibleRooms) { _ in .onChange(of: context.viewState.visibleRooms) { _ in
updateVisibleRange() updateVisibleRange()
} }
.background( .background {
Button("", action: { Button("") {
context.send(viewAction: .globalSearch) context.send(viewAction: .globalSearch)
}) }
.keyboardShortcut(KeyEquivalent("k"), modifiers: [.command]) .keyboardShortcut(KeyEquivalent("k"), modifiers: [.command])
) }
.overlay {
if context.viewState.shouldShowEmptyFilterState {
RoomListFiltersEmptyStateView(state: context.filtersState)
.background(.compound.bgCanvasDefault)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}
.scrollDismissesKeyboard(.immediately) .scrollDismissesKeyboard(.immediately)
.scrollDisabled(context.viewState.roomListMode == .skeletons) .scrollDisabled(context.viewState.roomListMode == .skeletons)
.scrollBounceBehavior(context.viewState.roomListMode == .empty ? .basedOnSize : .automatic) .scrollBounceBehavior(context.viewState.roomListMode == .empty ? .basedOnSize : .automatic)
@@ -104,16 +109,20 @@ struct HomeScreenContent: View {
@ViewBuilder @ViewBuilder
private var topSection: some View { private var topSection: some View {
// An empty VStack causes glitches within the room list
if context.viewState.shouldShowFilters ||
context.viewState.shouldShowRecoveryKeyConfirmationBanner ||
context.viewState.shouldShowInvitesButton {
VStack(spacing: 0) { VStack(spacing: 0) {
if !context.isSearchFieldFocused { if context.viewState.shouldShowFilters {
RoomListFiltersView(state: $context.filtersState) RoomListFiltersView(state: $context.filtersState)
} }
if context.viewState.securityBannerMode == .recoveryKeyConfirmation { if context.viewState.shouldShowRecoveryKeyConfirmationBanner {
HomeScreenRecoveryKeyConfirmationBanner(context: context) HomeScreenRecoveryKeyConfirmationBanner(context: context)
} }
if context.viewState.hasPendingInvitations, !context.isSearchFieldFocused, !ServiceLocator.shared.settings.roomListInvitesEnabled { if context.viewState.shouldShowInvitesButton {
HomeScreenInvitesButton(title: L10n.actionInvitesList, hasBadge: context.viewState.hasUnreadPendingInvitations) { HomeScreenInvitesButton(title: L10n.actionInvitesList, hasBadge: context.viewState.hasUnreadPendingInvitations) {
context.send(viewAction: .selectInvites) context.send(viewAction: .selectInvites)
} }
@@ -123,6 +132,7 @@ struct HomeScreenContent: View {
} }
.background(Color.compound.bgCanvasDefault) .background(Color.compound.bgCanvasDefault)
} }
}
@ViewBuilder @ViewBuilder
private var migrationView: some View { private var migrationView: some View {
+1
View File
@@ -0,0 +1 @@
Fix room list looping and fighting scrolling after filtering