diff --git a/Mail/Utils/AdaptivePanelViewModifier.swift b/Mail/Utils/AdaptivePanelViewModifier.swift index 170e50e0a..27b528394 100644 --- a/Mail/Utils/AdaptivePanelViewModifier.swift +++ b/Mail/Utils/AdaptivePanelViewModifier.swift @@ -31,17 +31,34 @@ struct AdaptivePanelViewModifier: ViewMo @Binding var item: Item? @ViewBuilder var panelContent: (Item) -> PanelContent + enum AdaptiveSizeType { + case compact + case regular + } + func body(content: Content) -> some View { - if isCompactWindow { - content.floatingPanel(item: $item) { item in + content + .floatingPanel(item: getBindingForSize(.compact)) { item in panelContent(item) } - } else { - content.popover(item: $item) { item in + .popover(item: getBindingForSize(.regular)) { item in panelContent(item) .padding() .frame(idealWidth: 400) } - } + } + + func getBindingForSize(_ size: AdaptiveSizeType) -> Binding { + // We can't use if statement in this modifier because this creates performance issues in the List: + // => SwiftUI needs to create each element of the list before rendering if an if statement is present) + Binding(get: { + if isCompactWindow && size == .compact || !isCompactWindow && size == .regular { + return item + } else { + return nil + } + }, set: { newItem in + item = newItem + }) } } diff --git a/Mail/Views/Thread List/ThreadListSwipeAction.swift b/Mail/Views/Thread List/ThreadListSwipeAction.swift index cdab919a1..a35205804 100644 --- a/Mail/Views/Thread List/ThreadListSwipeAction.swift +++ b/Mail/Views/Thread List/ThreadListSwipeAction.swift @@ -110,25 +110,24 @@ struct ThreadListSwipeActions: ViewModifier { let multipleSelectionViewModel: ThreadListMultipleSelectionViewModel func body(content: Content) -> some View { - if viewModel.folder.role == .draft { - content - .swipeActions(edge: .trailing) { - edgeActions([.delete]) - } - } else { - content - .swipeActions(edge: .leading) { + content + .swipeActions(edge: .leading) { + if viewModel.folder.role != .draft { edgeActions([swipeFullLeading, swipeLeading]) } - .swipeActions(edge: .trailing) { + } + .swipeActions(edge: .trailing) { + if viewModel.folder.role == .draft { + edgeActions([.delete]) + } else { edgeActions([swipeFullTrailing, swipeTrailing]) } - .actionsPanel(actionsTarget: $actionsTarget) - .sheet(item: $moveAction) { moveAction in - MoveEmailView(moveAction: moveAction) - .sheetViewStyle() - } - } + } + .actionsPanel(actionsTarget: $actionsTarget) + .sheet(item: $moveAction) { moveAction in + MoveEmailView(moveAction: moveAction) + .sheetViewStyle() + } } @MainActor @ViewBuilder diff --git a/Mail/Views/Thread List/ThreadListView.swift b/Mail/Views/Thread List/ThreadListView.swift index 98c48f0b1..9f98590a6 100644 --- a/Mail/Views/Thread List/ThreadListView.swift +++ b/Mail/Views/Thread List/ThreadListView.swift @@ -57,7 +57,7 @@ struct ThreadListView: View { @Binding private var editedMessageDraft: Draft? @Binding private var messageReply: MessageReply? - + private var shouldDisplayEmptyView: Bool { viewModel.folder.lastUpdate != nil && viewModel.sections.isEmpty && !viewModel.isLoadingPage } @@ -129,7 +129,6 @@ struct ThreadListView: View { isSelected: viewModel.selectedThread?.uid == thread.uid, isMultiSelected: multipleSelectionViewModel.selectedItems .contains { $0.id == thread.id }) - .id(thread.id) } } header: { if threadDensity != .compact {