Skip to content
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
3 changes: 2 additions & 1 deletion MC1/Views/Chats/ChatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct ChatsView: View {
columnVisibility: columnVisibility,
tabBarPlacement: tabBarPlacement,
preferredColumn: preferredCompactColumn,
hasSelection: appState.navigation.chatsSelectedRoute != nil
hasSelection: appState.navigation.chatsSelectedRoute != nil,
sectionIsSelected: appState.navigation.selectedTab == AppTab.chats.rawValue
)
}

Expand Down
10 changes: 3 additions & 7 deletions MC1/Views/Chats/Mentions/ChatConversationMentionOverlay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import SwiftUI

/// Floating mention suggestions overlay for the chat input.
struct ChatConversationMentionOverlay: View {
/// Clearance above the compose bar when the keyboard is down (bar ~height).
private static let composeBarClearance: CGFloat = 60
/// Space under the card. The timeline safe area ends at the composer, so this is only the gap.
private static let gapAboveComposer: CGFloat = 0

let suggestions: [ContactDTO]
let onSelectMention: (ContactDTO) -> Void
Expand All @@ -17,9 +17,7 @@ struct ChatConversationMentionOverlay: View {
onSelectMention(contact)
}
.padding(.horizontal)
// Clearance above the compose bar, then `chatKeyboardLift` for the keyboard.
.padding(.bottom, Self.composeBarClearance)
.chatKeyboardLiftPadding()
.padding(.bottom, Self.gapAboveComposer)
.transition(
.asymmetric(
insertion: .move(edge: .bottom)
Expand All @@ -28,8 +26,6 @@ struct ChatConversationMentionOverlay: View {
removal: .move(edge: .bottom).combined(with: .opacity)
)
)
// `ChatWindowBottomInset` keeps suggestions above the bar once the container inset is ignored.
ChatWindowBottomInset()
}
.animation(.spring(response: 0.3, dampingFraction: 0.8), value: suggestions.isEmpty)
}
Expand Down
6 changes: 5 additions & 1 deletion MC1/Views/Chats/Navigation/SectionSplitPresentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ enum SectionSplitPresentation {
columnVisibility: NavigationSplitViewVisibility,
tabBarPlacement: TabBarPlacement?,
preferredColumn: NavigationSplitViewColumn,
hasSelection: Bool
hasSelection: Bool,
sectionIsSelected: Bool
) -> Visibility {
// An unselected section returns automatic. The tab stays mounted, so a hidden
// preference would hide the bar on the selected tab.
guard sectionIsSelected else { return .automatic }
let collapsedDetail = sizeClass == .compact
&& preferredColumn == .detail
&& hasSelection
Expand Down
131 changes: 122 additions & 9 deletions MC1/Views/Components/MapToolboxPlacement.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
import SwiftUI

enum MapToolboxColumn {
/// The vertical tab bar capsule keeps this margin from the screen edge.
/// The home-indicator inset is taller, so the safe-area bottom sits above it.
static let verticalTabBarScreenMargin: CGFloat = 24

/// Matches the pad `MapControlsToolbar` puts around the glass.
static let toolbarGlassPadding: CGFloat = 16

static var sharedTabBarBottomPadding: CGFloat {
verticalTabBarScreenMargin - toolbarGlassPadding
}

/// The system's own inset stays between the capsules. Other sides keep their pad.
static func barFacingInset(sharesTabBarBottom: Bool, edge: HorizontalEdge?) -> EdgeInsets {
guard sharesTabBarBottom else { return EdgeInsets() }
let pull = -toolbarGlassPadding
switch edge {
case .leading:
return EdgeInsets(top: 0, leading: pull, bottom: 0, trailing: 0)
case .trailing:
return EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: pull)
case nil:
return EdgeInsets()
}
}

static func alignsLeading(_ verticalBarEdge: HorizontalEdge?) -> Bool {
verticalBarEdge == .leading
}
Expand All @@ -20,10 +45,50 @@ enum MapToolboxColumn {
static func hidesTabBar(_ verticalBarEdge: HorizontalEdge?) -> Bool {
verticalBarEdge != nil
}

static func inset(on edge: HorizontalEdge?, of insets: EdgeInsets) -> CGFloat {
switch edge {
case .leading:
insets.leading
case .trailing:
insets.trailing
case nil:
0
}
}

/// Share the tab bar bottom only while the toolbox stays beside a visible bar.
/// A preferred edge with no inset has no column.
static func sharesTabBarBottom(
followsVerticalBar: Bool,
pinsToBottom: Bool,
verticalBarEdge: HorizontalEdge?,
edgeInset: CGFloat
) -> Bool {
!followsVerticalBar
&& pinsToBottom
&& verticalBarEdge != nil
&& edgeInset > 0
}

/// Following the bar uses that column. Sharing keeps the safe area and sits on the bar's side.
static func alignmentEdge(
columnEdge: HorizontalEdge?,
sharesTabBarBottom: Bool,
verticalBarEdge: HorizontalEdge?
) -> HorizontalEdge? {
if columnEdge != nil {
return columnEdge
}
if sharesTabBarBottom {
return verticalBarEdge
}
return nil
}
}

/// Bottom-corner toolbox, unless `pinsToBottom` is false. `followsVerticalBar`
/// moves it into a vertical-bar column and hides the tab bar; false leaves both visible.
/// moves it into a vertical-bar column and hides the tab bar. Beside a visible bar, both stay visible and share its bottom without the facing pad.
struct MapToolboxPlacement<Content: View>: View {
var bottomPadding: CGFloat = 0
var pinsToBottom: Bool = true
Expand All @@ -40,7 +105,9 @@ struct MapToolboxPlacement<Content: View>: View {
)
} else {
ToolboxStack(
verticalBarEdge: nil,
columnEdge: nil,
alignmentEdge: nil,
sharesTabBarBottom: false,
bottomPadding: bottomPadding,
pinsToBottom: pinsToBottom,
content: content
Expand All @@ -51,25 +118,45 @@ struct MapToolboxPlacement<Content: View>: View {
@available(iOS 27.1, *)
private struct VerticalBarToolbox<Toolbox: View>: View {
@Environment(\.toolbarVerticalEdge) private var toolbarVerticalEdge
@State private var edgeInset: CGFloat = 0

var bottomPadding: CGFloat
var pinsToBottom: Bool
var followsVerticalBar: Bool
@ViewBuilder var content: () -> Toolbox

var body: some View {
let barEdge = toolbarVerticalEdge
let columnEdge: HorizontalEdge? = followsVerticalBar ? barEdge : nil
let sharesTabBarBottom = MapToolboxColumn.sharesTabBarBottom(
followsVerticalBar: followsVerticalBar,
pinsToBottom: pinsToBottom,
verticalBarEdge: barEdge,
edgeInset: edgeInset
)
ToolboxStack(
verticalBarEdge: followsVerticalBar ? toolbarVerticalEdge : nil,
columnEdge: columnEdge,
alignmentEdge: MapToolboxColumn.alignmentEdge(
columnEdge: columnEdge,
sharesTabBarBottom: sharesTabBarBottom,
verticalBarEdge: barEdge
),
sharesTabBarBottom: sharesTabBarBottom,
bottomPadding: bottomPadding,
pinsToBottom: pinsToBottom,
content: content
)
.onGeometryChange(for: CGFloat.self) { proxy in
MapToolboxColumn.inset(on: barEdge, of: proxy.safeAreaInsets)
} action: { edgeInset = $0 }
}
}
}

private struct ToolboxStack<Content: View>: View {
var verticalBarEdge: HorizontalEdge?
var columnEdge: HorizontalEdge?
var alignmentEdge: HorizontalEdge?
var sharesTabBarBottom: Bool
var bottomPadding: CGFloat
var pinsToBottom: Bool
@ViewBuilder var content: () -> Content
Expand All @@ -85,18 +172,29 @@ private struct ToolboxStack<Content: View>: View {
row
}
}
.modifier(ToolboxColumnSafeArea(edge: verticalBarEdge))
.padding(.bottom, pinsToBottom ? bottomPadding : 0)
.modifier(VerticalBarTabBarHider(edge: verticalBarEdge))
.modifier(ToolboxColumnSafeArea(edge: columnEdge))
.modifier(
ToolboxBottomAlignment(
sharesTabBarBottom: sharesTabBarBottom,
extraPadding: pinsToBottom ? bottomPadding : 0
)
)
.modifier(VerticalBarTabBarHider(edge: columnEdge))
}

private var row: some View {
HStack {
if !MapToolboxColumn.alignsLeading(verticalBarEdge) {
if !MapToolboxColumn.alignsLeading(alignmentEdge) {
Spacer()
}
content()
if MapToolboxColumn.alignsLeading(verticalBarEdge) {
.padding(
MapToolboxColumn.barFacingInset(
sharesTabBarBottom: sharesTabBarBottom,
edge: alignmentEdge
)
)
if MapToolboxColumn.alignsLeading(alignmentEdge) {
Spacer()
}
}
Expand All @@ -115,6 +213,21 @@ private struct ToolboxColumnSafeArea: ViewModifier {
}
}

private struct ToolboxBottomAlignment: ViewModifier {
var sharesTabBarBottom: Bool
var extraPadding: CGFloat

func body(content: Content) -> some View {
if sharesTabBarBottom {
content
.padding(.bottom, MapToolboxColumn.sharedTabBarBottomPadding + extraPadding)
.ignoresSafeArea(.container, edges: .bottom)
} else {
content.padding(.bottom, extraPadding)
}
}
}

private struct VerticalBarTabBarHider: ViewModifier {
var edge: HorizontalEdge?

Expand Down
17 changes: 11 additions & 6 deletions MC1Tests/Views/AdaptiveNavigationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@ struct AdaptiveNavigationTests {

// MARK: - Presentation recipe

@Test
func `collapsed compact detail hides tabs`() {
@Test(arguments: [true, false])
func `collapsed compact detail hides tabs only for the selected section`(
sectionIsSelected: Bool
) {
let visibility = SectionSplitPresentation.tabBarVisibility(
sizeClass: .compact,
columnVisibility: .all,
tabBarPlacement: .bottomBar,
preferredColumn: .detail,
hasSelection: true
hasSelection: true,
sectionIsSelected: sectionIsSelected
)
#expect(visibility == .hidden)
#expect(visibility == (sectionIsSelected ? .hidden : .automatic))
}

@Test
Expand All @@ -43,7 +46,8 @@ struct AdaptiveNavigationTests {
columnVisibility: .all,
tabBarPlacement: .bottomBar,
preferredColumn: .sidebar,
hasSelection: false
hasSelection: false,
sectionIsSelected: true
)
#expect(visibility == .automatic)
}
Expand All @@ -59,7 +63,8 @@ struct AdaptiveNavigationTests {
columnVisibility: columnVisibility,
tabBarPlacement: placement,
preferredColumn: .sidebar,
hasSelection: hasSelection
hasSelection: hasSelection,
sectionIsSelected: true
)
let hidesBottomTabs = placement == .bottomBar && columnVisibility == .detailOnly && hasSelection
#expect(visibility == (hidesBottomTabs ? .hidden : .automatic))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,8 @@ private final class ChatNativeSplitHarnessModel {
columnVisibility: columnVisibility,
tabBarPlacement: placement,
preferredColumn: preferredCompactColumn,
hasSelection: selectedRoute != nil
hasSelection: selectedRoute != nil,
sectionIsSelected: true
)
}

Expand Down
Loading
Loading