@momo-kits/native-kits 0.167.1-duo.2-debug → 0.167.1-duo.3-debug

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/.claude/scheduled_tasks.lock +1 -0
  2. package/.claude/settings.local.json +185 -0
  3. package/CLAUDE.md +8 -3
  4. package/compose/build.gradle.kts +15 -1
  5. package/compose/build.gradle.kts.backup +14 -0
  6. package/compose/compose.podspec +1 -1
  7. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +2 -0
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +52 -25
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +12 -2
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +45 -15
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +43 -4
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +8 -0
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +34 -8
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +81 -62
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +281 -0
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +31 -4
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +27 -2
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +17 -10
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -0
  20. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +4 -0
  21. package/gradle.properties +1 -1
  22. package/ios/Application/HeaderRight.swift +25 -12
  23. package/ios/Application/Layout/ScreenLayout.swift +196 -0
  24. package/ios/Application/Navigation/BottomTab/BottomTab.swift +30 -9
  25. package/ios/Application/Navigation/BottomTab/BottomTabBar.swift +5 -2
  26. package/ios/Application/Navigation/BottomTab/DuoTabBar.swift +275 -0
  27. package/ios/Application/Navigation/HeaderUser.swift +4 -1
  28. package/ios/Application/Navigation/NavigationContainer.swift +3 -0
  29. package/ios/Application/Navigation/Overplay/BottomSheet.swift +41 -4
  30. package/ios/Application/Navigation/Overplay/ModalScreen.swift +5 -1
  31. package/ios/Application/Navigation/component/DuoScrollGradient.swift +55 -0
  32. package/ios/Application/Navigation/component/Header.swift +9 -3
  33. package/ios/Application/Navigation/component/HeaderBackground.swift +3 -2
  34. package/ios/Application/Navigation/component/NavigationFooter.swift +1 -1
  35. package/ios/Application/Navigation/component/NavigationHeaderRight.swift +61 -9
  36. package/ios/Application/Navigation/component/SideBar.swift +155 -0
  37. package/ios/Application/StackScreen.swift +135 -18
  38. package/ios/Popup/PopupDisplay.swift +84 -68
  39. package/ios/Popup/PopupLayout.swift +45 -0
  40. package/ios/Popup/PopupNotify.swift +43 -32
  41. package/ios/Popup/PopupPromotion.swift +17 -5
  42. package/ios/native-kits.podspec +1 -1
  43. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  44. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/DuoTabDemo.swift +76 -0
  45. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/Home.swift +1 -0
  46. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/IPhoneDuoDemo.swift +170 -0
  47. package/local.properties +8 -0
  48. package/package.json +1 -1
@@ -0,0 +1,196 @@
1
+ //
2
+ // ScreenLayout.swift
3
+ // MoMoUIKits
4
+ //
5
+ // Port of momo-kits RN `useScreenLayout` (Layout/utils.ts) and `Application/device.ts`:
6
+ // window size, safe-area insets, content width, header geometry and the iPhone Duo side bar.
7
+ //
8
+
9
+ import SwiftUI
10
+ import UIKit
11
+
12
+ public enum SideBarEdge: Equatable {
13
+ case left, right
14
+ }
15
+
16
+ public struct SideBarLayout: Equatable {
17
+ public let edge: SideBarEdge
18
+ public let width: CGFloat
19
+ /// Preferred window y of the first control; StackScreen still keeps the column above the bottom bars.
20
+ public let top: CGFloat
21
+ }
22
+
23
+ public struct ScreenLayout: Equatable {
24
+ public let width: CGFloat
25
+ public let height: CGFloat
26
+ public let isIPhoneDuo: Bool
27
+ public let insets: EdgeInsets
28
+ public let insetLeft: CGFloat
29
+ public let insetRight: CGFloat
30
+ public let contentWidth: CGFloat
31
+ public let headerHeight: CGFloat
32
+ /// 0 when the status bar is off the top edge, so the bar row fills the header and keeps the title centered.
33
+ public let headerStatusBarHeight: CGFloat
34
+ /// iPhone Duo moves back and toolkit into a column in the side safe area; nil while they stay in the bar.
35
+ public let sideBar: SideBarLayout?
36
+
37
+ public var headerBarHeight: CGFloat { headerHeight - headerStatusBarHeight }
38
+ }
39
+
40
+ // Measured by momo-kits RN (Layout/utils.ts) on the iOS 27.1 iPhone Duo simulator; keep both in sync.
41
+ enum DuoMetrics {
42
+ // Inner display is ~1.42, outer ~1.45; every slab iPhone is 1.77 or taller.
43
+ static let maxAspectRatio: CGFloat = 1.6
44
+ // Outer display is 466pt tall in landscape, inner 669pt.
45
+ static let innerMinHeight: CGFloat = 600
46
+ static let controlSize: CGFloat = 48
47
+ static let itemPitch: CGFloat = 50
48
+ static let firstItemTop: CGFloat = 170
49
+ static let firstItemTopLandscape: CGFloat = 120
50
+ // Widest short side of any single-display iPhone.
51
+ static let iPhoneMaxShortSide: CGFloat = 440
52
+ }
53
+
54
+ enum HeaderMetrics {
55
+ static let barHeight: CGFloat = HEADER_HEIGHT
56
+ static let iPhoneMinHeight: CGFloat = 72
57
+ // A smaller top inset means the status bar is not on the top edge.
58
+ static let statusBarMinInset: CGFloat = 20
59
+ }
60
+
61
+ private var isPhoneIdiom: Bool { UIDevice.current.userInterfaceIdiom == .phone }
62
+
63
+ private var keyWindow: UIWindow? {
64
+ UIApplication.shared.connectedScenes
65
+ .compactMap { ($0 as? UIWindowScene)?.keyWindow }
66
+ .first
67
+ }
68
+
69
+ extension ScreenLayout {
70
+ /// Snapshot of the key window; not reactive, so views read `\.screenLayout` instead.
71
+ public static var current: ScreenLayout {
72
+ guard let window = keyWindow else {
73
+ return make(size: UIScreen.main.bounds.size, insets: EdgeInsets())
74
+ }
75
+ let inset = window.safeAreaInsets
76
+ return make(
77
+ size: window.bounds.size,
78
+ insets: EdgeInsets(top: inset.top, leading: inset.left, bottom: inset.bottom, trailing: inset.right)
79
+ )
80
+ }
81
+
82
+ static func make(size: CGSize, insets: EdgeInsets, isPhone: Bool = isPhoneIdiom) -> ScreenLayout {
83
+ let width = size.width
84
+ let height = size.height
85
+ let (headerHeight, headerStatusBarHeight) = headerGeometry(topInset: insets.top, isPhone: isPhone)
86
+ let isDuo = isPhone && isIPhoneDuoWindow(width: width, height: height, insets: insets)
87
+ guard isDuo else {
88
+ return ScreenLayout(
89
+ width: width, height: height, isIPhoneDuo: false, insets: insets,
90
+ insetLeft: 0, insetRight: 0, contentWidth: width,
91
+ headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: nil
92
+ )
93
+ }
94
+
95
+ var sideBar: SideBarLayout?
96
+ let sideInset = max(insets.leading, insets.trailing)
97
+ // narrower strips cannot host a control 12pt from the inner edge
98
+ if sideInset >= DuoMetrics.controlSize + Spacing.M {
99
+ var top = insets.top + HeaderMetrics.barHeight + Spacing.M
100
+ if insets.top < HeaderMetrics.statusBarMinInset {
101
+ // status bar lives in the strip: start under its cluster, as the native bar does
102
+ let isInnerLandscape = width > height && height >= DuoMetrics.innerMinHeight
103
+ top = isInnerLandscape ? DuoMetrics.firstItemTopLandscape : DuoMetrics.firstItemTop
104
+ }
105
+ sideBar = SideBarLayout(
106
+ edge: insets.trailing >= insets.leading ? .right : .left,
107
+ width: sideInset,
108
+ top: top
109
+ )
110
+ }
111
+
112
+ return ScreenLayout(
113
+ width: width, height: height, isIPhoneDuo: true, insets: insets,
114
+ insetLeft: insets.leading, insetRight: insets.trailing,
115
+ contentWidth: width - insets.leading - insets.trailing,
116
+ headerHeight: headerHeight, headerStatusBarHeight: headerStatusBarHeight, sideBar: sideBar
117
+ )
118
+ }
119
+
120
+ private static func headerGeometry(topInset: CGFloat, isPhone: Bool) -> (CGFloat, CGFloat) {
121
+ let height = topInset + HeaderMetrics.barHeight
122
+ guard isPhone else { return (height, topInset) }
123
+ return (
124
+ max(height, HeaderMetrics.iPhoneMinHeight),
125
+ topInset < HeaderMetrics.statusBarMinInset ? 0 : topInset
126
+ )
127
+ }
128
+
129
+ // Slab iPhones report equal side insets in landscape; iPhone Duo moves the status bar to one side.
130
+ private static func isIPhoneDuoWindow(width: CGFloat, height: CGFloat, insets: EdgeInsets) -> Bool {
131
+ let shortSide = min(width, height)
132
+ let isSquare = shortSide > 0 && max(width, height) / shortSide < DuoMetrics.maxAspectRatio
133
+ return isSquare || insets.leading != insets.trailing
134
+ }
135
+
136
+ /// Below the side status bar: in portrait it is about twice as tall as its inset is wide.
137
+ public var duoTopInset: CGFloat {
138
+ max(insets.top, height > width ? max(insets.leading, insets.trailing) * 2 : 0)
139
+ }
140
+ }
141
+
142
+ /// Port of RN `device.ts` `isIPhoneDuo()`: UIScreen stays on the outer display, so this
143
+ /// still matches when Split View narrows the window. Used by popups and overlays.
144
+ public func isIPhoneDuoDevice(windowSize: CGSize? = nil) -> Bool {
145
+ guard isPhoneIdiom else { return false }
146
+ let screen = UIScreen.main.bounds.size
147
+ let window = windowSize ?? keyWindow?.bounds.size ?? screen
148
+ return max(min(screen.width, screen.height), min(window.width, window.height)) > DuoMetrics.iPhoneMaxShortSide
149
+ }
150
+
151
+ // MARK: - Environment
152
+
153
+ private struct ScreenLayoutKey: EnvironmentKey {
154
+ // Computed so an un-injected subtree (bare UIHostingController) still reads the live window.
155
+ static var defaultValue: ScreenLayout { .current }
156
+ }
157
+
158
+ public extension EnvironmentValues {
159
+ var screenLayout: ScreenLayout {
160
+ get { self[ScreenLayoutKey.self] }
161
+ set { self[ScreenLayoutKey.self] = newValue }
162
+ }
163
+ }
164
+
165
+ /// Re-reads the window whenever this view's size changes (rotation, fold/unfold, Split View).
166
+ private struct ScreenLayoutReader: ViewModifier {
167
+ @State private var layout: ScreenLayout = .current
168
+
169
+ func body(content: Content) -> some View {
170
+ content
171
+ .environment(\.screenLayout, layout)
172
+ .background(
173
+ GeometryReader { proxy in
174
+ Color.clear
175
+ .onAppear { refresh() }
176
+ .onChange(of: proxy.size) { _ in refresh() }
177
+ .onChange(of: proxy.safeAreaInsets) { _ in refresh() }
178
+ }
179
+ )
180
+ .onReceive(NotificationCenter.default.publisher(for: UIDevice.orientationDidChangeNotification)) { _ in
181
+ refresh()
182
+ }
183
+ }
184
+
185
+ private func refresh() {
186
+ let next = ScreenLayout.current
187
+ if next != layout { layout = next }
188
+ }
189
+ }
190
+
191
+ public extension View {
192
+ /// Provides `\.screenLayout`; NavigationContainer applies it, a bare UIHostingController root should too.
193
+ func momoScreenLayout() -> some View {
194
+ modifier(ScreenLayoutReader())
195
+ }
196
+ }
@@ -16,6 +16,7 @@ public struct BottomTab: View {
16
16
  private let floatingButton: BottomTabFloatingButton?
17
17
 
18
18
  @EnvironmentObject private var navigator: Navigator
19
+ @Environment(\.screenLayout) private var layout
19
20
  @State private var selectedIndex: Int = 0
20
21
 
21
22
  public init(items: [BottomTabItem], floatingButton: BottomTabFloatingButton? = nil) {
@@ -24,7 +25,14 @@ public struct BottomTab: View {
24
25
  }
25
26
 
26
27
  private var bottomInset: CGFloat { safeAreaBottomInset() }
27
- private var reservedBottom: CGFloat { BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S }
28
+ // the Duo bars overlay the content or sit in the side strip, so only the home indicator is kept clear
29
+ private var reservedBottom: CGFloat {
30
+ layout.isIPhoneDuo ? layout.insets.bottom : BOTTOM_TAB_BAR_HEIGHT + bottomInset + Spacing.S
31
+ }
32
+
33
+ private var duoInsets: DuoTabBarInsets {
34
+ layout.duoTabBarInsets(itemCount: items.count, hasFloatingButton: floatingButton != nil)
35
+ }
28
36
 
29
37
  public var body: some View {
30
38
  ZStack(alignment: .bottom) {
@@ -38,20 +46,29 @@ public struct BottomTab: View {
38
46
  }
39
47
  }
40
48
  .padding(.bottom, reservedBottom)
49
+ .environment(\.duoTabBarInsets, duoInsets)
41
50
  .animation(.easeInOut(duration: 0.2), value: selectedIndex)
42
51
 
43
- // Tab bar + home-indicator filler.
44
- VStack(spacing: 0) {
45
- BottomTabBar(
52
+ if layout.isIPhoneDuo {
53
+ DuoTabBar(
46
54
  items: items,
47
55
  floatingButton: floatingButton,
48
56
  selectedIndex: selectedIndex,
49
- onTabSelected: { index in
50
- if index != selectedIndex { selectedIndex = index }
51
- }
57
+ onTabSelected: selectTab
52
58
  )
53
- Colors.black01
54
- .frame(height: bottomInset + Spacing.S)
59
+ } else {
60
+ // Tab bar + home-indicator filler.
61
+ VStack(spacing: 0) {
62
+ BottomTabBar(
63
+ items: items,
64
+ floatingButton: floatingButton,
65
+ selectedIndex: selectedIndex,
66
+ onTabSelected: selectTab
67
+ )
68
+ Colors.black01
69
+ .frame(height: bottomInset + Spacing.S)
70
+ .ignoresSafeArea(edges: .horizontal)
71
+ }
55
72
  }
56
73
  }
57
74
  .frame(maxWidth: .infinity, maxHeight: .infinity)
@@ -59,6 +76,10 @@ public struct BottomTab: View {
59
76
  .preference(key: IsBottomTabRootKey.self, value: true)
60
77
  }
61
78
 
79
+ private func selectTab(_ index: Int) {
80
+ if index != selectedIndex { selectedIndex = index }
81
+ }
82
+
62
83
  @ViewBuilder
63
84
  private func tabScreen(for index: Int) -> some View {
64
85
  let item = items[index]
@@ -65,7 +65,10 @@ struct BottomTabBar: View {
65
65
  let selectedIndex: Int
66
66
  let onTabSelected: (Int) -> Void
67
67
 
68
- private var screenWidth: CGFloat { UIScreen.main.bounds.width }
68
+ @Environment(\.screenLayout) private var layout
69
+
70
+ // the bar sits between the side safe areas
71
+ private var screenWidth: CGFloat { layout.width - layout.insets.leading - layout.insets.trailing }
69
72
  private var mid: Int { items.count / 2 }
70
73
 
71
74
  private var tabWidth: CGFloat {
@@ -95,7 +98,7 @@ struct BottomTabBar: View {
95
98
  }
96
99
  .frame(maxWidth: .infinity)
97
100
  .frame(height: BOTTOM_TAB_BAR_HEIGHT)
98
- .background(Colors.black01)
101
+ .background(Colors.black01.ignoresSafeArea(edges: .horizontal))
99
102
 
100
103
  // Animated selection indicator.
101
104
  RoundedRectangle(cornerRadius: 2)
@@ -0,0 +1,275 @@
1
+ //
2
+ // DuoTabBar.swift
3
+ // MoMoUIKits
4
+ //
5
+ // iPhone Duo tab bar, port of RN `BottomTab/DuoTabBar.tsx` (Figma Fold-Design-System MT1/MT2):
6
+ // a glass rail in the side bar, or a floating glass bar when unfolded portrait.
7
+ //
8
+
9
+ import SwiftUI
10
+
11
+ private let itemSize = DuoMetrics.controlSize
12
+ private let iconSize: CGFloat = 28
13
+ private let qrIconSize: CGFloat = 24
14
+ private let railPadding: CGFloat = 6
15
+ private let railGap = Spacing.XXS
16
+ // selection bubble overflows the 48 rail cell by 5 above and below (Figma MT2)
17
+ private let railBubbleWidth: CGFloat = 44
18
+ private let railBubbleHeight: CGFloat = 58
19
+ let duoFloatingTabBarHeight: CGFloat = 62
20
+ private let floatingPadding = Spacing.XS
21
+ private let floatingQrSize: CGFloat = 44
22
+ // floating bar spans 6 of the 8 portrait grid columns, like the content
23
+ private let gridColumns: CGFloat = 8
24
+ private let gridSpan: CGFloat = 6
25
+ private let tabSpring = Animation.interpolatingSpring(mass: 0.8, stiffness: 220, damping: 18)
26
+
27
+ /// Room tab screens leave for the Duo tab bar, provided by BottomTab to its tab StackScreens.
28
+ struct DuoTabBarInsets: Equatable {
29
+ /// Floating bar overlays the content: scroll content, footer and FAB keep clear of it.
30
+ var overlay: CGFloat = 0
31
+ /// Rail sits at the bottom of the side strip: the header side bar stays above it.
32
+ var sideBarReserve: CGFloat = 0
33
+ }
34
+
35
+ private struct DuoTabBarInsetsKey: EnvironmentKey {
36
+ static let defaultValue = DuoTabBarInsets()
37
+ }
38
+
39
+ extension EnvironmentValues {
40
+ var duoTabBarInsets: DuoTabBarInsets {
41
+ get { self[DuoTabBarInsetsKey.self] }
42
+ set { self[DuoTabBarInsetsKey.self] = newValue }
43
+ }
44
+ }
45
+
46
+ extension ScreenLayout {
47
+ func duoTabBarInsets(itemCount: Int, hasFloatingButton: Bool) -> DuoTabBarInsets {
48
+ guard isIPhoneDuo else { return DuoTabBarInsets() }
49
+ guard sideBar != nil else {
50
+ return DuoTabBarInsets(overlay: duoFloatingTabBarHeight + Spacing.M)
51
+ }
52
+ let count = CGFloat(itemCount)
53
+ let rail = railPadding * 2 + count * itemSize + max(count - 1, 0) * railGap
54
+ let qr = hasFloatingButton ? Spacing.M + itemSize : 0
55
+ return DuoTabBarInsets(sideBarReserve: rail + qr + Spacing.XL)
56
+ }
57
+ }
58
+
59
+ /// Glass on iOS 26, a system blur before it (RN GlassView's fallback).
60
+ struct DuoBarMaterial<S: Shape>: ViewModifier {
61
+ let shape: S
62
+ var visible: Bool = true
63
+
64
+ func body(content: Content) -> some View {
65
+ content.background(material.allowsHitTesting(false))
66
+ }
67
+
68
+ @ViewBuilder
69
+ private var material: some View {
70
+ #if compiler(>=6.2)
71
+ if #available(iOS 26.0, *) {
72
+ // glass materializes by toggling its effect, it does not fade with opacity
73
+ Color.clear
74
+ .glassEffect(visible ? .regular : .identity, in: shape)
75
+ .shadow(color: Color.black.opacity(visible ? 0.16 : 0), radius: 16, x: 0, y: 6)
76
+ .animation(.easeInOut(duration: 0.25), value: visible)
77
+ } else {
78
+ blur
79
+ }
80
+ #else
81
+ blur
82
+ #endif
83
+ }
84
+
85
+ private var blur: some View {
86
+ shape.fill(.regularMaterial)
87
+ .shadow(color: Color.black.opacity(0.16), radius: 16, x: 0, y: 6)
88
+ .opacity(visible ? 1 : 0)
89
+ .animation(.easeInOut(duration: 0.25), value: visible)
90
+ }
91
+ }
92
+
93
+ struct DuoTabBar: View {
94
+ let items: [BottomTabItem]
95
+ let floatingButton: BottomTabFloatingButton?
96
+ let selectedIndex: Int
97
+ let onTabSelected: (Int) -> Void
98
+
99
+ @Environment(\.screenLayout) private var layout
100
+
101
+ var body: some View {
102
+ if let sideBar = layout.sideBar {
103
+ DuoRailTabBar(sideBar: sideBar, items: items, floatingButton: floatingButton,
104
+ selectedIndex: selectedIndex, onTabSelected: onTabSelected)
105
+ } else {
106
+ DuoFloatingTabBar(items: items, floatingButton: floatingButton,
107
+ selectedIndex: selectedIndex, onTabSelected: onTabSelected)
108
+ }
109
+ }
110
+ }
111
+
112
+ /// Vertical bar anchored to the bottom of the side bar, QR button below it (Figma MT1-C/E).
113
+ private struct DuoRailTabBar: View {
114
+ let sideBar: SideBarLayout
115
+ let items: [BottomTabItem]
116
+ let floatingButton: BottomTabFloatingButton?
117
+ let selectedIndex: Int
118
+ let onTabSelected: (Int) -> Void
119
+
120
+ @Environment(\.appTheme) private var theme
121
+
122
+ private var isRight: Bool { sideBar.edge == .right }
123
+
124
+ var body: some View {
125
+ VStack(spacing: Spacing.M) {
126
+ ZStack(alignment: .top) {
127
+ Capsule()
128
+ .fill(theme.colors.background.selected)
129
+ .frame(width: railBubbleWidth, height: railBubbleHeight)
130
+ .offset(y: railPadding - (railBubbleHeight - itemSize) / 2
131
+ + CGFloat(selectedIndex) * (itemSize + railGap))
132
+ .animation(tabSpring, value: selectedIndex)
133
+
134
+ VStack(spacing: railGap) {
135
+ ForEach(items.indices, id: \.self) { index in
136
+ SwiftUI.Button { onTabSelected(index) } label: {
137
+ DuoTabIcon(item: items[index], selected: index == selectedIndex)
138
+ .frame(width: itemSize, height: itemSize)
139
+ .contentShape(Rectangle())
140
+ }
141
+ .buttonStyle(.plain)
142
+ .accessibilityLabel(items[index].label)
143
+ }
144
+ }
145
+ .padding(.vertical, railPadding)
146
+ }
147
+ .frame(width: itemSize)
148
+ .modifier(DuoBarMaterial(shape: RoundedRectangle(cornerRadius: Radius.XL)))
149
+ .accessibilityIdentifier("bottom_tab_bar")
150
+
151
+ if let floatingButton {
152
+ DuoQrButton(data: floatingButton, size: itemSize)
153
+ }
154
+ }
155
+ .padding(isRight ? .leading : .trailing, Spacing.M)
156
+ .frame(width: sideBar.width, alignment: isRight ? .leading : .trailing)
157
+ .padding(.bottom, Spacing.XL)
158
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: isRight ? .bottomTrailing : .bottomLeading)
159
+ .ignoresSafeArea()
160
+ }
161
+ }
162
+
163
+ /// Floating labelled bar for the unfolded portrait display, QR in the middle cell (Figma MT1-M).
164
+ private struct DuoFloatingTabBar: View {
165
+ let items: [BottomTabItem]
166
+ let floatingButton: BottomTabFloatingButton?
167
+ let selectedIndex: Int
168
+ let onTabSelected: (Int) -> Void
169
+
170
+ @Environment(\.screenLayout) private var layout
171
+ @Environment(\.appTheme) private var theme
172
+
173
+ private var barWidth: CGFloat {
174
+ let columnWidth = (layout.width - 2 * Spacing.M - (gridColumns - 1) * Spacing.M) / gridColumns
175
+ return columnWidth * gridSpan + (gridSpan - 1) * Spacing.M
176
+ }
177
+
178
+ private var useQr: Bool { floatingButton != nil && items.count % 2 == 0 }
179
+ private var middle: Int { items.count / 2 }
180
+ private var cellCount: Int { items.count + (useQr ? 1 : 0) }
181
+ private var cellWidth: CGFloat { (barWidth - floatingPadding * 2) / CGFloat(max(cellCount, 1)) }
182
+ private var visualIndex: Int { useQr && selectedIndex >= middle ? selectedIndex + 1 : selectedIndex }
183
+
184
+ var body: some View {
185
+ ZStack(alignment: .leading) {
186
+ Capsule()
187
+ .fill(theme.colors.background.selected)
188
+ .frame(width: cellWidth)
189
+ .offset(x: CGFloat(visualIndex) * cellWidth)
190
+ .animation(tabSpring, value: visualIndex)
191
+
192
+ HStack(spacing: 0) {
193
+ ForEach(0..<cellCount, id: \.self) { cell in
194
+ if useQr && cell == middle, let floatingButton {
195
+ DuoQrButton(data: floatingButton, size: floatingQrSize)
196
+ .frame(width: cellWidth)
197
+ } else {
198
+ let index = useQr && cell > middle ? cell - 1 : cell
199
+ tabCell(index)
200
+ }
201
+ }
202
+ }
203
+ }
204
+ .padding(floatingPadding)
205
+ .frame(width: barWidth, height: duoFloatingTabBarHeight)
206
+ .modifier(DuoBarMaterial(shape: Capsule()))
207
+ .accessibilityIdentifier("bottom_tab_bar")
208
+ .padding(.bottom, layout.insets.bottom + Spacing.M)
209
+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
210
+ .ignoresSafeArea()
211
+ }
212
+
213
+ private func tabCell(_ index: Int) -> some View {
214
+ let selected = index == selectedIndex
215
+ return SwiftUI.Button { onTabSelected(index) } label: {
216
+ VStack(spacing: Spacing.XXS) {
217
+ DuoTabIcon(item: items[index], selected: selected)
218
+ MomoText(
219
+ items[index].label,
220
+ typography: .labelXsMedium,
221
+ color: selected ? theme.colors.primary : theme.colors.text.default,
222
+ textAlign: .center,
223
+ maxLines: 1
224
+ )
225
+ }
226
+ .frame(width: cellWidth)
227
+ .frame(maxHeight: .infinity)
228
+ .contentShape(Rectangle())
229
+ }
230
+ .buttonStyle(.plain)
231
+ .accessibilityLabel(items[index].label)
232
+ }
233
+ }
234
+
235
+ private struct DuoTabIcon: View {
236
+ let item: BottomTabItem
237
+ let selected: Bool
238
+
239
+ @Environment(\.appTheme) private var theme
240
+
241
+ private var badgeLabel: String? {
242
+ guard let label = item.badgeLabel else { return nil }
243
+ if let n = Int(label), n == 0 { return nil }
244
+ return label
245
+ }
246
+
247
+ var body: some View {
248
+ Icon(source: item.icon, size: iconSize, color: selected ? theme.colors.primary : theme.colors.text.default)
249
+ .overlay(alignment: .topTrailing) {
250
+ if let badgeLabel, !badgeLabel.isEmpty {
251
+ Badge(label: badgeLabel).offset(x: Spacing.S, y: -Spacing.XS)
252
+ } else if badgeLabel != nil || item.showDot {
253
+ BadgeDot(size: .small)
254
+ }
255
+ }
256
+ }
257
+ }
258
+
259
+ private struct DuoQrButton: View {
260
+ let data: BottomTabFloatingButton
261
+ let size: CGFloat
262
+
263
+ @Environment(\.appTheme) private var theme
264
+
265
+ var body: some View {
266
+ SwiftUI.Button(action: data.onPress) {
267
+ Circle()
268
+ .fill(theme.colors.primary)
269
+ .frame(width: size, height: size)
270
+ .overlay(Icon(source: data.icon, size: qrIconSize, color: Colors.black01))
271
+ }
272
+ .buttonStyle(.plain)
273
+ .accessibilityLabel(data.label)
274
+ }
275
+ }
@@ -20,8 +20,11 @@ public struct HeaderUserView: View {
20
20
 
21
21
  private let avatarSize: CGFloat = Spacing.XXL // 32
22
22
 
23
+ @Environment(\.screenLayout) private var layout
24
+
25
+ // back button and toolkit share the bar unless the iPhone Duo side bar holds them
23
26
  private var maxWidth: CGFloat {
24
- UIScreen.main.bounds.width - 172
27
+ layout.sideBar != nil ? layout.contentWidth - Spacing.M * 2 : layout.width - 172
25
28
  }
26
29
 
27
30
  public var body: some View {
@@ -88,6 +88,7 @@ public struct NavigationContainer<Initial: View>: View {
88
88
  .momoLocalize(localize)
89
89
  .momoFontScale(context: applicationEnvironment.applicationContext)
90
90
  // AI-GENERATED END: route Localize + font-scale injection through the observing modifiers
91
+ .momoScreenLayout()
91
92
  }
92
93
  }
93
94
  .onAppear {
@@ -167,6 +168,8 @@ private struct ScreenHost: View {
167
168
  screenName: screen.name,
168
169
  content: { screen.content() }
169
170
  )
171
+ // Per screen, not around the NavigationStack: a state-driven reader there stops path pushes rendering.
172
+ .momoScreenLayout()
170
173
  }
171
174
  }
172
175
 
@@ -45,6 +45,7 @@ struct BottomSheetView<Content: View>: View {
45
45
  @EnvironmentObject private var navigator: Navigator
46
46
  @Environment(\.appTheme) private var theme
47
47
  @Environment(\.applicationEnvironment) private var appEnv
48
+ @Environment(\.screenLayout) private var layout
48
49
 
49
50
  /// Vertical translation of the sheet; starts off-screen and animates to 0.
50
51
  @State private var sheetOffset: CGFloat = UIScreen.main.bounds.height
@@ -66,7 +67,36 @@ struct BottomSheetView<Content: View>: View {
66
67
  /// steady-state (fully open) scrim peaks at 0.6, matching ModalScreen's peak.
67
68
  private let maxDynamicAlpha: CGFloat = 0.3
68
69
 
69
- private var screenHeight: CGFloat { UIScreen.main.bounds.height }
70
+ // UIScreen stays on the outer display on iPhone Duo, even when unfolded
71
+ private var screenHeight: CGFloat { isDuo ? layout.height : UIScreen.main.bounds.height }
72
+
73
+ private var isDuo: Bool { layout.isDuoDevice }
74
+ // iPhone Duo inner display: center the sheet instead of spanning the width
75
+ private var isDuoCentered: Bool { isDuo && layout.width >= 600 }
76
+
77
+ /// Keeps the portrait width in landscape, like system sheets.
78
+ private var duoCenteredWidth: CGFloat {
79
+ min(
80
+ min(layout.width, layout.height) - Spacing.L * 2,
81
+ layout.width - max(layout.insets.leading, layout.insets.trailing, Spacing.L) * 2
82
+ )
83
+ }
84
+
85
+ /// Landscape side buttons span the full height, so the content is inset; in portrait the
86
+ /// side status bar only covers the top corner.
87
+ private var sideInsetLeading: CGFloat {
88
+ isDuo && !isDuoCentered && layout.width > layout.height ? layout.insets.leading : 0
89
+ }
90
+
91
+ private var sideInsetTrailing: CGFloat {
92
+ isDuo && !isDuoCentered && layout.width > layout.height ? layout.insets.trailing : 0
93
+ }
94
+
95
+ /// The keyboard filler is part of the sheet, so capping the sheet shrinks the content by it.
96
+ private var duoMaxHeight: CGFloat? {
97
+ guard isDuo else { return nil }
98
+ return layout.height - max(layout.duoTopInset, Spacing.XL)
99
+ }
70
100
  private var bottomInset: CGFloat { safeAreaBottomInset() }
71
101
  /// While the keyboard is up, it already covers the home-indicator area, so it
72
102
  /// replaces (rather than adds to) the usual bottom-inset filler.
@@ -110,7 +140,7 @@ struct BottomSheetView<Content: View>: View {
110
140
  .onReceive(NotificationCenter.default.publisher(for: UIResponder.keyboardWillChangeFrameNotification)) { notification in
111
141
  guard let endFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect else { return }
112
142
  withAnimation(.easeOut(duration: 0.25)) {
113
- keyboardHeight = UIScreen.main.bounds.height - endFrame.origin.y
143
+ keyboardHeight = screenHeight - endFrame.origin.y
114
144
  }
115
145
  }
116
146
  .onAppear {
@@ -138,6 +168,8 @@ struct BottomSheetView<Content: View>: View {
138
168
  headerView
139
169
  .frame(height: 56)
140
170
  .padding(.horizontal, Spacing.M)
171
+ .padding(.leading, sideInsetLeading)
172
+ .padding(.trailing, sideInsetTrailing)
141
173
  }
142
174
  .frame(maxWidth: .infinity)
143
175
  .frame(height: 72)
@@ -149,12 +181,17 @@ struct BottomSheetView<Content: View>: View {
149
181
  .frame(height: 1)
150
182
 
151
183
  content()
184
+ .padding(.leading, sideInsetLeading)
185
+ .padding(.trailing, sideInsetTrailing)
186
+ // a tall sheet on iPhone Duo keeps its header and gives the content what is left
187
+ .layoutPriority(-1)
152
188
 
153
189
  backgroundColor
154
190
  .frame(height: effectiveBottomInset)
155
191
  }
156
- .frame(maxWidth: .infinity)
157
- .frame(alignment: .bottom)
192
+ .frame(maxWidth: isDuoCentered ? duoCenteredWidth : .infinity)
193
+ .frame(maxHeight: duoMaxHeight, alignment: .bottom)
194
+ .clipped()
158
195
  .background(
159
196
  GeometryReader { geo in
160
197
  Color.clear.onAppear { sheetHeight = geo.size.height }