@momo-kits/native-kits 0.169.8-beta.7-debug → 0.169.8-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 (32) hide show
  1. package/compose/build.gradle.kts +1 -1
  2. package/compose/compose.podspec +1 -1
  3. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -59
  4. package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +5 -20
  5. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +1 -1
  6. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +55 -0
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +2 -7
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +14 -33
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +1 -10
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +39 -29
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +29 -28
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +10 -3
  13. package/gradle.properties +1 -1
  14. package/ios/Input/InputSearch.swift +6 -23
  15. package/ios/Navigation/BottomTab/BottomTabBar.swift +0 -9
  16. package/ios/Navigation/Component/Header.swift +46 -31
  17. package/ios/Navigation/Component/HeaderJourney.swift +1 -2
  18. package/ios/Navigation/Component/HeaderLocation.swift +1 -2
  19. package/ios/Navigation/Component/HeaderRight.swift +15 -18
  20. package/ios/Navigation/Component/HeaderUser.swift +1 -2
  21. package/ios/Navigation/Component/SideBar.swift +13 -4
  22. package/ios/Navigation/Navigation.swift +1 -31
  23. package/ios/Navigation/StackScreen.swift +14 -43
  24. package/ios/native-kits.podspec +1 -1
  25. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  26. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +2 -11
  27. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +1 -13
  28. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +0 -11
  29. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +1 -1
  30. package/package.json +1 -1
  31. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -63
  32. package/ios/Layout/HeaderLayout.swift +0 -60
@@ -14,9 +14,6 @@ public final class Navigation: ObservableObject {
14
14
  private weak var registry: DynamicScreenRegistry?
15
15
  /// What the footer (or navigation bar) takes from the window bottom; lifts snack bars.
16
16
  var bottomObstruction: CGFloat = 0
17
- /// A tab that pads itself asks (via `floatingTabBarEdgeToEdge()`) to run edge to edge behind the floating
18
- /// bar and the home indicator; the kit then stops reserving that space. Compose's `bottomTabEdgeToEdge`.
19
- @Published var bottomTabEdgeToEdge = false
20
17
 
21
18
  init(
22
19
  id: Int = -1,
@@ -87,8 +84,6 @@ public struct NavigationOptions {
87
84
  public var inputSearchProps: InputSearchProps?
88
85
  public var fabProps: FabProps?
89
86
  public var onBackHandler: (() -> Void)?
90
- /// Wide windows: `.stretch` puts the header row in the centered 600pt content frame.
91
- public var contentLayout: ContentLayout
92
87
 
93
88
  public init(
94
89
  screenName: String? = nil,
@@ -117,8 +112,7 @@ public struct NavigationOptions {
117
112
  layoutOffset: CGFloat = 56,
118
113
  inputSearchProps: InputSearchProps? = nil,
119
114
  fabProps: FabProps? = nil,
120
- onBackHandler: (() -> Void)? = nil,
121
- contentLayout: ContentLayout = .grid
115
+ onBackHandler: (() -> Void)? = nil
122
116
  ) {
123
117
  self.screenName = screenName
124
118
  self.title = title
@@ -147,7 +141,6 @@ public struct NavigationOptions {
147
141
  self.inputSearchProps = inputSearchProps
148
142
  self.fabProps = fabProps
149
143
  self.onBackHandler = onBackHandler
150
- self.contentLayout = contentLayout
151
144
  }
152
145
  }
153
146
 
@@ -191,31 +184,8 @@ struct OptionsStackScreen: View {
191
184
  layoutOffset: options.layoutOffset,
192
185
  inputSearchProps: options.inputSearchProps,
193
186
  fabProps: options.fabProps,
194
- contentLayout: options.contentLayout,
195
187
  screenName: screenName,
196
188
  content: content
197
189
  )
198
190
  }
199
191
  }
200
-
201
- // MARK: - Edge-to-edge tab content
202
-
203
- public extension View {
204
- /// Compose's `floatingTabBarContentPadding()`: the content of a `BottomTab` tab runs edge to edge behind
205
- /// the floating tab bar and the home indicator, and pads its own bottom (e.g. a full-screen native view
206
- /// with its own safe area). No effect outside a tab.
207
- func floatingTabBarEdgeToEdge() -> some View {
208
- modifier(FloatingTabBarEdgeToEdge())
209
- }
210
- }
211
-
212
- private struct FloatingTabBarEdgeToEdge: ViewModifier {
213
- @OptionalEnvironmentObject private var navigation: Navigation?
214
-
215
- func body(content: Content) -> some View {
216
- content.onAppear {
217
- guard let navigation, navigation.bottomTabIndex != -1, !navigation.bottomTabEdgeToEdge else { return }
218
- navigation.bottomTabEdgeToEdge = true
219
- }
220
- }
221
- }
@@ -34,7 +34,6 @@ public struct StackScreen<Content: View>: View {
34
34
  var layoutOffset: CGFloat
35
35
  var inputSearchProps: InputSearchProps?
36
36
  var fabProps: FabProps?
37
- var contentLayout: ContentLayout = .grid
38
37
  var screenName: String = ""
39
38
  var content: () -> Content
40
39
 
@@ -66,7 +65,6 @@ public struct StackScreen<Content: View>: View {
66
65
  layoutOffset: CGFloat = 56,
67
66
  inputSearchProps: InputSearchProps? = nil,
68
67
  fabProps: FabProps? = nil,
69
- contentLayout: ContentLayout = .grid,
70
68
  screenName: String = "",
71
69
  @ViewBuilder content: @escaping () -> Content
72
70
  ) {
@@ -97,7 +95,6 @@ public struct StackScreen<Content: View>: View {
97
95
  self.layoutOffset = layoutOffset
98
96
  self.inputSearchProps = inputSearchProps
99
97
  self.fabProps = fabProps
100
- self.contentLayout = contentLayout
101
98
  self.screenName = screenName
102
99
  self.content = content
103
100
  }
@@ -164,16 +161,6 @@ public struct StackScreen<Content: View>: View {
164
161
  && inputSearchProps == nil && !headerTransparent && !fullScreenContent
165
162
  }
166
163
 
167
- /// Bottom room for the tab's content: clear of the floating bar, unless the tab runs edge to edge
168
- /// (`floatingTabBarEdgeToEdge()`), when it also covers the home indicator that BottomTab keeps clear of
169
- /// (a negative inset extends the content past the tab's frame).
170
- private var contentBottomInset: CGFloat {
171
- guard let navigation, navigation.bottomTabIndex != -1, navigation.bottomTabEdgeToEdge else {
172
- return duoTabBarInsets.overlay
173
- }
174
- return -layout.insets.bottom
175
- }
176
-
177
164
  /// iPhone Duo: the header leaves with the content and slides back in on a reverse scroll
178
165
  /// (RN DuoQuickReturnHeader). The side bar is drawn apart from the header, so it stays put.
179
166
  private var useQuickReturn: Bool {
@@ -310,7 +297,6 @@ public struct StackScreen<Content: View>: View {
310
297
  }
311
298
  }
312
299
  .ignoresSafeArea(.keyboard, edges: .bottom)
313
- .environment(\.contentLayout, contentLayout)
314
300
  .onChange(of: scrollOffset) { updateHeaderHide($0) }
315
301
  .onAppear { reportEmptySideBar() }
316
302
  .onChange(of: showsSideBar) { _ in reportEmptySideBar() }
@@ -393,7 +379,7 @@ public struct StackScreen<Content: View>: View {
393
379
  scrollOffset: $scrollOffset,
394
380
  scrollToTopCallback: scrollToTopCallback,
395
381
  animatedSearchInset: animatedSearchInset,
396
- bottomInset: contentBottomInset,
382
+ bottomInset: duoTabBarInsets.overlay,
397
383
  snapDistance: searchSnapDistance,
398
384
  onScrollIdle: settleHeader,
399
385
  content: { animatedHeroBody(animatedHeader) }
@@ -426,7 +412,7 @@ public struct StackScreen<Content: View>: View {
426
412
  scrollOffset: $scrollOffset,
427
413
  scrollToTopCallback: scrollToTopCallback,
428
414
  animatedSearchInset: animatedSearchInset,
429
- bottomInset: contentBottomInset,
415
+ bottomInset: duoTabBarInsets.overlay,
430
416
  snapDistance: searchSnapDistance,
431
417
  onScrollIdle: settleHeader,
432
418
  content: { duoInsetContent }
@@ -447,7 +433,7 @@ public struct StackScreen<Content: View>: View {
447
433
  scrollOffset: $scrollOffset,
448
434
  scrollToTopCallback: scrollToTopCallback,
449
435
  topInset: layout.headerHeight - layout.insets.top,
450
- bottomInset: contentBottomInset,
436
+ bottomInset: duoTabBarInsets.overlay,
451
437
  snapDistance: searchSnapDistance,
452
438
  onScrollIdle: settleHeader,
453
439
  content: content
@@ -493,7 +479,7 @@ public struct StackScreen<Content: View>: View {
493
479
  scrollOffset: $scrollOffset,
494
480
  scrollToTopCallback: scrollToTopCallback,
495
481
  animatedSearchInset: animatedSearchInset,
496
- bottomInset: contentBottomInset,
482
+ bottomInset: duoTabBarInsets.overlay,
497
483
  snapDistance: searchSnapDistance,
498
484
  onScrollIdle: settleHeader,
499
485
  content: content
@@ -510,28 +496,18 @@ public struct StackScreen<Content: View>: View {
510
496
  }
511
497
 
512
498
  private func heroGlassStart(_ animatedHeader: AnimatedHeader) -> CGFloat {
513
- max(bannerWidth / animatedHeader.aspectRatio.value - layout.headerHeight, 0)
514
- }
515
-
516
- /// Wide windows keep the phone banner size, centered; phones fill the width.
517
- private var bannerWidth: CGFloat {
518
- layout.headerLayout(contentLayout).isWide ? HeaderLayoutMetrics.bannerWidth : layout.width
499
+ max(layout.width / animatedHeader.aspectRatio.value - layout.headerHeight, 0)
519
500
  }
520
501
 
521
502
  /// The banner fills the width at its aspect ratio; the body starts `layoutOffset` below the
522
- /// header band so it overlaps the banner's lower part. On wide windows `bannerBackgroundColor`
523
- /// fills the sides, fading out downward.
503
+ /// header band so it overlaps the banner's lower part.
524
504
  @ViewBuilder
525
505
  private func animatedHeroBody(_ animatedHeader: AnimatedHeader) -> some View {
526
- let width = bannerWidth
506
+ let width = layout.width
527
507
  let imageHeight = width / animatedHeader.aspectRatio.value
528
508
  let contentTopInset = layout.headerHeight + layoutOffset
529
509
 
530
510
  ZStack(alignment: .top) {
531
- if width < layout.width, let fill = animatedHeader.bannerBackgroundColor {
532
- LinearGradient(colors: [fill, fill.opacity(0)], startPoint: .top, endPoint: .bottom)
533
- .frame(width: layout.width, height: imageHeight)
534
- }
535
511
  animatedHeader.composable(scrollOffset)
536
512
  .frame(width: width, height: imageHeight)
537
513
  .clipped()
@@ -585,8 +561,7 @@ private struct StackScreenContent<Content: View>: View {
585
561
  /// Room for a header the content scrolls under (iPhone Duo glass header).
586
562
  var topInset: CGFloat = 0
587
563
  /// Room for the floating tab bar that overlays the content: scrolling content runs under it and
588
- /// ends clear of it, static content stays above it. Negative for an edge-to-edge tab: the content
589
- /// reaches that far past its frame.
564
+ /// ends clear of it, static content stays above it.
590
565
  var bottomInset: CGFloat = 0
591
566
  /// Compose's animated-search snap: a scroll that comes to rest part way through this distance
592
567
  /// finishes the move, up or back down.
@@ -647,8 +622,6 @@ private struct StackScreenContent<Content: View>: View {
647
622
  }
648
623
  }
649
624
  .coordinateSpace(name: scrollSpace)
650
- // an edge-to-edge tab's scroll reaches past its frame, under the home indicator
651
- .padding(.bottom, min(bottomInset, 0))
652
625
  .modifier(ScrollRest(offset: scrollOffset, onRest: scrollDidRest))
653
626
  // Status-bar tap (MoMoStatusBarTap swizzle) scrolls to top and notifies the consumer.
654
627
  .onReceive(NotificationCenter.default.publisher(for: MoMoStatusBarTap.notificationName)) { _ in
@@ -749,7 +722,6 @@ private struct SearchAnimatedHeader: View {
749
722
  var hasToolkit: Bool = false
750
723
 
751
724
  @Environment(\.screenLayout) private var layout
752
- @Environment(\.contentLayout) private var contentLayout
753
725
  @Environment(\.appTheme) private var theme
754
726
  @OptionalEnvironmentObject private var navigator: Navigator?
755
727
 
@@ -760,14 +732,14 @@ private struct SearchAnimatedHeader: View {
760
732
  let rowTop = layout.headerStatusBarHeight - layout.insets.top
761
733
  let minTop = rowTop + (layout.headerBarHeight - HEADER_HEIGHT) / 2
762
734
  let maxTop = layout.headerHeight - layout.insets.top
763
- // stretch screens on wide windows keep the search in the header's centered frame
764
- let minSide = layout.headerLayout(contentLayout).frameInset
765
- // collapsed on the iPhone Duo status bar row, the search stays between its clusters
735
+ let minSide = Spacing.M
736
+ // collapsed on the iPhone Duo status bar row, the search stays between its clusters (48pt back there)
766
737
  let clearance = layout.statusBarClearance
767
- let maxStart = (clearance?.left ?? 0) + (hiddenBack || useSideBar ? minSide : HeaderLayoutMetrics.buttonSize + minSide + HeaderLayoutMetrics.titleGap)
738
+ let backWidth: CGFloat = clearance != nil && !useSideBar ? DuoMetrics.controlSize : 28
739
+ let maxStart = (clearance?.left ?? 0) + (hiddenBack || useSideBar ? Spacing.M : backWidth + Spacing.M + Spacing.S)
768
740
  let maxEnd = (clearance?.right ?? 0) + (useSideBar && hasToolkit
769
- ? minSide
770
- : headerRightWidth + (hasHeaderRight ? minSide + Spacing.M : minSide))
741
+ ? Spacing.M
742
+ : headerRightWidth + (hasHeaderRight ? Spacing.M * 2 : Spacing.M))
771
743
 
772
744
  // one progress for all three, so the field docks with its final insets and never covers the toolkit
773
745
  let progress = min(scroll / HEADER_HEIGHT, 1)
@@ -783,7 +755,6 @@ private struct SearchAnimatedHeader: View {
783
755
  theme: theme,
784
756
  pop: navigator.map { navigator in { navigator.pop() } }
785
757
  ))
786
- .headerSize()
787
758
  .frame(height: HEADER_HEIGHT)
788
759
  .padding(.leading, start)
789
760
  .padding(.trailing, end)
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKits'
3
- s.version = '0.169.8-beta.7'
3
+ s.version = '0.169.8'
4
4
  s.summary = 'MoMoUIKits for iOS'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |s|
2
2
  s.name = 'MoMoUIKitsDemo'
3
- s.version = '0.169.8-beta.7'
3
+ s.version = '0.169.8'
4
4
  s.summary = 'Demo browser for MoMoUIKits SwiftUI components'
5
5
  s.homepage = 'https://momo.vn'
6
6
  s.license = { :type => 'MIT' }
@@ -30,7 +30,6 @@ struct AnimatedHeaderDemoContent: View {
30
30
 
31
31
  @State private var ratio: AnimatedHeaderRatio = .ratio16_9
32
32
  @State private var isSurface = true
33
- @State private var isStretch = true
34
33
 
35
34
  private let imageUrl = "https://static.momocdn.net/app/img/booking/holiday/mid_atumn_dldl.jpeg"
36
35
 
@@ -48,11 +47,6 @@ struct AnimatedHeaderDemoContent: View {
48
47
  MomoText("Surface")
49
48
  }
50
49
 
51
- // wide windows (short side >= 600): phone-sized banner, sides filled with the banner color
52
- Toggle(isOn: $isStretch) {
53
- MomoText("Stretch content layout")
54
- }
55
-
56
50
  MoMoUIKits.Button(
57
51
  title: "Show Animated Header",
58
52
  action: show,
@@ -69,7 +63,6 @@ struct AnimatedHeaderDemoContent: View {
69
63
  private func show() {
70
64
  let ratio = ratio
71
65
  let isSurface = isSurface
72
- let contentLayout: ContentLayout = isStretch ? .stretch : .grid
73
66
  let url = imageUrl
74
67
  navigator.push(
75
68
  { AnimatedHeaderTargetScreen(ratio: ratio) },
@@ -84,10 +77,8 @@ struct AnimatedHeaderDemoContent: View {
84
77
  .frame(maxWidth: .infinity, maxHeight: .infinity)
85
78
  .clipped()
86
79
  )
87
- },
88
- bannerBackgroundColor: Colors.pink09
89
- ),
90
- contentLayout: contentLayout
80
+ }
81
+ )
91
82
  )
92
83
  )
93
84
  }
@@ -39,8 +39,6 @@ private struct DemoConfig: Hashable {
39
39
  var initialRouteName = "Momo"
40
40
  var compressionBehavior: DuoBarCompressionBehavior = .toolbar
41
41
  var backToInitialTab = true
42
- // a sticky footer in the tab's content body, to check it clears the floating bar
43
- var footer = false
44
42
 
45
43
  var visibleTabs: [TabConfig] { Array(tabs.prefix(tabCount)) }
46
44
  }
@@ -109,10 +107,7 @@ struct BottomTabDemoContent: View {
109
107
  icon: tab.icon,
110
108
  showDot: tab.showDot,
111
109
  badgeLabel: tab.badgeLabel,
112
- options: NavigationOptions(
113
- headerTitle: .default(tab.label),
114
- footer: config.footer ? { AnyView(demoFooter) } : nil
115
- ),
110
+ options: NavigationOptions(headerTitle: .default(tab.label)),
116
111
  screen: { TabContent(name: tab.name, config: $config, focused: $focused) }
117
112
  )
118
113
  },
@@ -129,10 +124,6 @@ struct BottomTabDemoContent: View {
129
124
  .onAppear { ctaLottieLoader.load() }
130
125
  }
131
126
 
132
- private var demoFooter: some View {
133
- MoMoUIKits.Button(title: "Footer trong content", action: {}, isFull: true)
134
- }
135
-
136
127
  private var floatingButton: BottomTabFloatingButton? {
137
128
  guard config.special else { return nil }
138
129
  guard config.ctaLottie else {
@@ -211,9 +202,6 @@ private struct TabContent: View {
211
202
  ])
212
203
  Options(title: "backToInitialTab", hint: "Back ở tab khác quay về tab đầu trước khi rời màn",
213
204
  options: yesNo(config.backToInitialTab) { config.backToInitialTab = $0 })
214
- Options(title: "footer",
215
- hint: "Footer dính trong content body, kiểm tra nó nằm trên thanh tab nổi",
216
- options: yesNo(config.footer) { config.footer = $0 })
217
205
  }
218
206
 
219
207
  Section(title: "Nút giữa (floatingButton)") {
@@ -273,9 +273,7 @@ private struct HeaderTypesScreen: View {
273
273
 
274
274
  @EnvironmentObject private var navigation: Navigation
275
275
  @Environment(\.applicationEnvironment) private var applicationEnvironment
276
- @Environment(\.screenLayout) private var layout
277
276
  @State private var kind: AnyHashable = Kind.default
278
- @State private var contentLayout: AnyHashable = ContentLayout.grid
279
277
  @State private var titlePosition: AnyHashable = TitlePosition.left
280
278
  @State private var showBack = true
281
279
  @State private var headerRight: AnyHashable = HeaderRightOption.toolkit
@@ -297,15 +295,6 @@ private struct HeaderTypesScreen: View {
297
295
  }, label: position == .left ? "LEFT" : "CENTER")
298
296
  }
299
297
  Divider()
300
- // stretch only differs on wide windows (short side >= 600, iPhone Duo excluded)
301
- let headerLayout = layout.headerLayout(contentLayout.base as? ContentLayout ?? .grid)
302
- MomoText("Content Layout · wide: \(headerLayout.isWide), frame inset: \(Int(headerLayout.frameInset))")
303
- ForEach([ContentLayout.grid, ContentLayout.stretch], id: \.self) { item in
304
- Radio(value: item, groupValue: $contentLayout, onChange: {
305
- navigation.setOptions { $0.contentLayout = item }
306
- }, label: item == .grid ? "Grid" : "Stretch")
307
- }
308
- Divider()
309
298
  Checkbox($showBack, onChange: { checked in
310
299
  navigation.setOptions { $0.hiddenBack = !checked }
311
300
  }, title: "Show Back")
@@ -14,7 +14,7 @@ struct PopupNotifyDemo: View {
14
14
  // MARK: - Preview
15
15
 
16
16
  // Figma Risk - eKYC (node 51445-177824)
17
- private let popupHighlightTitle = "Tạm khoá giao dịch để báo vệ bạn"
17
+ private let popupHighlightTitle = "Tạm khoá giao dịch để bảo vệ bạn"
18
18
  private let popupHighlightSentence =
19
19
  "Mỗi ngày có ít nhất 20 người bị lừa đảo hơn 100 triệu đồng trong các giao dịch có dấu hiệu tương tự"
20
20
  private let popupHighlightDescription =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.169.8-beta.7-debug",
3
+ "version": "0.169.8-debug",
4
4
  "private": false,
5
5
  "scripts": {
6
6
  "publish:local": "bash publish.sh local"
@@ -1,63 +0,0 @@
1
- package vn.momo.kits.layout
2
-
3
- import androidx.compose.runtime.Composable
4
- import androidx.compose.runtime.Immutable
5
- import androidx.compose.runtime.remember
6
- import androidx.compose.ui.unit.Dp
7
- import androidx.compose.ui.unit.dp
8
- import vn.momo.kits.const.DEFAULT_SCREEN_SIZE
9
- import vn.momo.kits.const.Spacing
10
-
11
- // Top navigation spec (Figma "Top Navigation · Màn hình gập"); mirrors RN and SwiftUI, keep in sync.
12
- val HEADER_BUTTON_SIZE = 32.dp
13
- val HEADER_ICON_SIZE = 20.dp
14
- val HEADER_PILL_WIDTH = 72.dp
15
- val HEADER_SEARCH_HEIGHT = 32.dp
16
- val HEADER_FRAME_MAX_WIDTH = 600.dp
17
- // Banner image width on every device: wide windows keep the phone size, centered.
18
- val HEADER_BANNER_WIDTH = DEFAULT_SCREEN_SIZE.dp
19
- internal val HEADER_TITLE_GAP = Spacing.S
20
- internal val HEADER_SIDE_PADDING = Spacing.M
21
- // shortcut + gap + help/home pill
22
- val HEADER_CLUSTER_WIDTH = HEADER_BUTTON_SIZE + HEADER_TITLE_GAP + HEADER_PILL_WIDTH
23
-
24
- /** How a screen lays out its content on wide windows; the header row follows it. */
25
- enum class ContentLayout {
26
- // 12 column grid: the header keeps the 12pt side padding.
27
- Grid,
28
- // One column of at most HEADER_FRAME_MAX_WIDTH, centered: the header row sits in the same frame.
29
- Stretch,
30
- }
31
-
32
- /** Header geometry for the current window; see [headerLayoutOf]. */
33
- @Immutable
34
- data class HeaderLayout(
35
- // short side >= FOLDABLE_MIN_WIDTH, iPhone Duo excluded (it has its own layout)
36
- val isWide: Boolean,
37
- // padding from each side of the safe area to the header row (back, title / search, right cluster)
38
- val frameInset: Dp,
39
- // width of the header row, so tabs and other header extensions can line up with it
40
- val frameWidth: Dp,
41
- )
42
-
43
- // Pass the screen's NavigationOptions.contentLayout so tabs and extensions line up with its header.
44
- @Composable
45
- fun rememberHeaderLayout(contentLayout: ContentLayout = ContentLayout.Grid): HeaderLayout {
46
- val layout = getScreenLayout()
47
- return remember(layout, contentLayout) { headerLayoutOf(layout, contentLayout) }
48
- }
49
-
50
- fun headerLayoutOf(layout: ScreenLayout, contentLayout: ContentLayout): HeaderLayout {
51
- val isDuo = layout.isIPhoneDuo || layout.isIPhoneDuoDevice
52
- val isWide = !isDuo && minOf(layout.width, layout.height) >= FOLDABLE_MIN_WIDTH
53
- val frameInset = if (isWide && contentLayout == ContentLayout.Stretch) {
54
- maxOf(HEADER_SIDE_PADDING, (layout.contentWidth - HEADER_FRAME_MAX_WIDTH) / 2)
55
- } else {
56
- HEADER_SIDE_PADDING
57
- }
58
- return HeaderLayout(
59
- isWide = isWide,
60
- frameInset = frameInset,
61
- frameWidth = layout.contentWidth - frameInset * 2,
62
- )
63
- }
@@ -1,60 +0,0 @@
1
- // Top navigation spec (Figma "Top Navigation · Màn hình gập"). Mirrors Compose `layout/HeaderLayout.kt`
2
- // and RN; keep the three in sync.
3
-
4
- import SwiftUI
5
-
6
- /// Header spec values, in points. Public so custom header rights and extensions can match them.
7
- public enum HeaderLayoutMetrics {
8
- public static let buttonSize: CGFloat = 32
9
- public static let iconSize: CGFloat = 20
10
- public static let pillWidth: CGFloat = 72
11
- public static let searchHeight: CGFloat = 32
12
- public static let titleGap: CGFloat = Spacing.S
13
- public static let sidePadding: CGFloat = Spacing.M
14
- /// shortcut + gap + help/home pill
15
- public static let clusterWidth: CGFloat = buttonSize + titleGap + pillWidth
16
- public static let frameMaxWidth: CGFloat = 600
17
- /// Banner image width on every device: wide windows keep the phone size, centered.
18
- public static let bannerWidth: CGFloat = 375
19
- }
20
-
21
- /// How a screen lays out its content on wide windows; the header row follows it.
22
- public enum ContentLayout: Equatable {
23
- /// 12 column grid: the header keeps the 12pt side padding.
24
- case grid
25
- /// One column of at most `HeaderLayoutMetrics.frameMaxWidth`, centered: the header row sits in the same frame.
26
- case stretch
27
- }
28
-
29
- /// Header geometry for a window; see `ScreenLayout.headerLayout(_:)`.
30
- public struct HeaderLayout: Equatable {
31
- /// Short side >= 600, iPhone Duo excluded (it has its own layout).
32
- public let isWide: Bool
33
- /// Padding from each side of the safe area to the header row (back, title / search, right cluster).
34
- public let frameInset: CGFloat
35
- /// Width of the header row, so tabs and other header extensions can line up with it.
36
- public let frameWidth: CGFloat
37
- }
38
-
39
- public extension ScreenLayout {
40
- func headerLayout(_ contentLayout: ContentLayout = .grid) -> HeaderLayout {
41
- let isWide = !isIPhoneDuo && !isDuoDevice && min(width, height) >= ModalMetrics.foldableMinWidth
42
- let safeWidth = width - insets.leading - insets.trailing
43
- let frameInset = isWide && contentLayout == .stretch
44
- ? max(HeaderLayoutMetrics.sidePadding, (safeWidth - HeaderLayoutMetrics.frameMaxWidth) / 2)
45
- : HeaderLayoutMetrics.sidePadding
46
- return HeaderLayout(isWide: isWide, frameInset: frameInset, frameWidth: safeWidth - frameInset * 2)
47
- }
48
- }
49
-
50
- private struct ContentLayoutKey: EnvironmentKey {
51
- static let defaultValue: ContentLayout = .grid
52
- }
53
-
54
- public extension EnvironmentValues {
55
- /// The enclosing screen's `NavigationOptions.contentLayout`, set by `StackScreen`.
56
- var contentLayout: ContentLayout {
57
- get { self[ContentLayoutKey.self] }
58
- set { self[ContentLayoutKey.self] = newValue }
59
- }
60
- }