@momo-kits/native-kits 0.168.1-beta.34-debug → 0.168.1-beta.35-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.
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.168.1-beta.34-debug"
43
+ version = "0.168.1-beta.35-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -20,20 +20,21 @@ import vn.momo.kits.modifier.noFeedbackClickable
20
20
  import vn.momo.kits.modifier.setAutomationId
21
21
 
22
22
  // Foldable spec for Popup and BottomSheet (Figma "Modal - Foldable Guideline"); mirrors RN and SwiftUI, keep in sync.
23
- internal val POPUP_MAX_WIDTH = 450.dp
24
- internal val POPUP_MIN_WIDTH = 280.dp
25
- internal val POPUP_MAX_HEIGHT = 600.dp
26
- internal val SHEET_MAX_WIDTH = 653.dp
27
- internal val SHEET_MIN_WIDTH = 296.dp
28
- internal val SHEET_MIN_HEIGHT = 230.dp
29
- internal val FOLDABLE_MIN_WIDTH = 600.dp
23
+ // Public so host apps can size their own (non-kits) popups and sheets the same way.
24
+ val POPUP_MAX_WIDTH = 450.dp
25
+ val POPUP_MIN_WIDTH = 280.dp
26
+ val POPUP_MAX_HEIGHT = 600.dp
27
+ val SHEET_MAX_WIDTH = 653.dp
28
+ val SHEET_MIN_WIDTH = 296.dp
29
+ val SHEET_MIN_HEIGHT = 230.dp
30
+ val FOLDABLE_MIN_WIDTH = 600.dp
30
31
  internal val MODAL_ICON_BUTTON_SIZE = 32.dp
31
32
  private val CLOSE_ICON_SIZE = 20.dp
32
33
  private const val PHONE_SCRIM_OPACITY = 0.6f
33
34
  private const val FOLDABLE_SCRIM_OPACITY = 0.2f
34
35
 
35
36
  @Immutable
36
- internal data class PopupGeometry(
37
+ data class PopupGeometry(
37
38
  val minWidth: Dp,
38
39
  val maxWidth: Dp,
39
40
  // null: as tall as the content, phones keep their own caps
@@ -43,7 +44,7 @@ internal data class PopupGeometry(
43
44
  )
44
45
 
45
46
  @Immutable
46
- internal data class SheetGeometry(
47
+ data class SheetGeometry(
47
48
  // null: spans the window
48
49
  val width: Dp?,
49
50
  // null: phones keep their own cap
@@ -53,8 +54,9 @@ internal data class SheetGeometry(
53
54
  val radius: Dp,
54
55
  )
55
56
 
57
+ /** Popup / bottom sheet geometry for the current window; see [modalLayoutOf]. */
56
58
  @Immutable
57
- internal data class ModalLayout(
59
+ data class ModalLayout(
58
60
  val isFoldable: Boolean,
59
61
  // window coordinates of the area popups center in and sheets rest on the bottom of
60
62
  val placement: DpRect,
@@ -71,10 +73,37 @@ internal fun rememberModalLayout(): ModalLayout {
71
73
  return remember(layout) { modalLayoutOf(layout) }
72
74
  }
73
75
 
74
- internal fun modalLayoutOf(layout: ScreenLayout): ModalLayout {
75
- val isFoldable = layout.isIPhoneDuoDevice || minOf(layout.width, layout.height) >= FOLDABLE_MIN_WIDTH
76
+ internal fun modalLayoutOf(layout: ScreenLayout): ModalLayout = modalLayoutOf(
77
+ width = layout.width,
78
+ height = layout.height,
79
+ insetLeft = layout.insetLeft,
80
+ insetTop = layout.insetTop,
81
+ insetRight = layout.insetRight,
82
+ insetBottom = layout.insetBottom,
83
+ isIPhoneDuoDevice = layout.isIPhoneDuoDevice,
84
+ hinge = layout.hinge,
85
+ )
86
+
87
+ /**
88
+ * Resolves popup / bottom sheet geometry from plain window metrics, for hosts without a kits screen.
89
+ *
90
+ * All values are in dp and window coordinates. The insets are the raw safe area (system bars and
91
+ * display cutout); on iPhone Duo they also carry the control column. [hinge] is the vertical hinge of
92
+ * a half-folded iPhone Duo, null while flat. Pure: no composition needed.
93
+ */
94
+ fun modalLayoutOf(
95
+ width: Dp,
96
+ height: Dp,
97
+ insetLeft: Dp = 0.dp,
98
+ insetTop: Dp = 0.dp,
99
+ insetRight: Dp = 0.dp,
100
+ insetBottom: Dp = 0.dp,
101
+ isIPhoneDuoDevice: Boolean = false,
102
+ hinge: DpRect? = null,
103
+ ): ModalLayout {
104
+ val isFoldable = isIPhoneDuoDevice || minOf(width, height) >= FOLDABLE_MIN_WIDTH
76
105
  if (!isFoldable) {
77
- val placement = DpRect(0.dp, 0.dp, layout.width, layout.height)
106
+ val placement = DpRect(0.dp, 0.dp, width, height)
78
107
  return ModalLayout(
79
108
  isFoldable = false,
80
109
  placement = placement,
@@ -85,18 +114,18 @@ internal fun modalLayoutOf(layout: ScreenLayout): ModalLayout {
85
114
  }
86
115
 
87
116
  // the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
88
- val hinge = layout.hinge?.takeIf { layout.isIPhoneDuoDevice && it.left > 0.dp && it.right < layout.width }
117
+ val hinge = hinge?.takeIf { isIPhoneDuoDevice && it.left > 0.dp && it.right < width }
89
118
  val placement = DpRect(
90
- left = maxOf(layout.insetLeft, hinge?.right ?: 0.dp),
91
- top = layout.insetTop,
92
- right = layout.width - layout.insetRight,
93
- bottom = layout.height - layout.insetBottom,
119
+ left = maxOf(insetLeft, hinge?.right ?: 0.dp),
120
+ top = insetTop,
121
+ right = width - insetRight,
122
+ bottom = height - insetBottom,
94
123
  )
95
124
  // outer display and half fold leave little room, so the margins tighten
96
- val isCompact = layout.isIPhoneDuoDevice && (hinge != null || minOf(layout.width, layout.height) < FOLDABLE_MIN_WIDTH)
125
+ val isCompact = isIPhoneDuoDevice && (hinge != null || minOf(width, height) < FOLDABLE_MIN_WIDTH)
97
126
  val popupMargin = if (isCompact) Spacing.M else Spacing.XL
98
127
  val sheetMargin = Spacing.M
99
- val sheetMaxHeight = layout.height - layout.insetTop - sheetMargin
128
+ val sheetMaxHeight = height - insetTop - sheetMargin
100
129
  val sheetMinWidth = minOf(SHEET_MIN_WIDTH, placement.width)
101
130
  return ModalLayout(
102
131
  isFoldable = true,
@@ -132,7 +161,7 @@ private fun popupGeometry(placementWidth: Dp, maxHeight: Dp?, margin: Dp, radius
132
161
 
133
162
  // Popup / sheet close and back on foldables: 32 icon button, 20 icon.
134
163
  @Composable
135
- internal fun ModalIconButton(
164
+ fun ModalIconButton(
136
165
  icon: String,
137
166
  automationId: String,
138
167
  onClick: () -> Unit,
@@ -8,66 +8,85 @@
8
8
 
9
9
  import SwiftUI
10
10
 
11
- enum ModalMetrics {
12
- static let popupMaxWidth: CGFloat = 450
13
- static let popupMinWidth: CGFloat = 280
14
- static let popupMaxHeight: CGFloat = 600
15
- static let sheetMaxWidth: CGFloat = 653
16
- static let sheetMinWidth: CGFloat = 296
17
- static let sheetMinHeight: CGFloat = 230
18
- static let foldableMinWidth: CGFloat = 600
19
- static let iconButtonSize: CGFloat = 32
20
- static let iconSize: CGFloat = 20
21
- static let phoneScrimOpacity: CGFloat = 0.6
22
- static let foldableScrimOpacity: CGFloat = 0.2
11
+ /// Foldable modal spec values, in points. Public so host apps can size their own popups and sheets the same way.
12
+ public enum ModalMetrics {
13
+ public static let popupMaxWidth: CGFloat = 450
14
+ public static let popupMinWidth: CGFloat = 280
15
+ public static let popupMaxHeight: CGFloat = 600
16
+ public static let sheetMaxWidth: CGFloat = 653
17
+ public static let sheetMinWidth: CGFloat = 296
18
+ public static let sheetMinHeight: CGFloat = 230
19
+ public static let foldableMinWidth: CGFloat = 600
20
+ public static let iconButtonSize: CGFloat = 32
21
+ public static let iconSize: CGFloat = 20
22
+ public static let phoneScrimOpacity: CGFloat = 0.6
23
+ public static let foldableScrimOpacity: CGFloat = 0.2
23
24
  }
24
25
 
25
- struct PopupGeometry: Equatable {
26
- let minWidth: CGFloat
27
- let maxWidth: CGFloat
26
+ public struct PopupGeometry: Equatable {
27
+ public let minWidth: CGFloat
28
+ public let maxWidth: CGFloat
28
29
  /// nil: as tall as the content, phones keep their own caps
29
- let maxHeight: CGFloat?
30
- let margin: CGFloat
31
- let radius: CGFloat
30
+ public let maxHeight: CGFloat?
31
+ public let margin: CGFloat
32
+ public let radius: CGFloat
32
33
  }
33
34
 
34
- struct SheetGeometry: Equatable {
35
+ public struct SheetGeometry: Equatable {
35
36
  /// nil: spans the window
36
- let width: CGFloat?
37
+ public let width: CGFloat?
37
38
  /// nil: phones keep their own cap
38
- let maxHeight: CGFloat?
39
- let minHeight: CGFloat
40
- let margin: CGFloat
41
- let radius: CGFloat
39
+ public let maxHeight: CGFloat?
40
+ public let minHeight: CGFloat
41
+ public let margin: CGFloat
42
+ public let radius: CGFloat
42
43
  }
43
44
 
44
- struct ModalLayout: Equatable {
45
- let isFoldable: Bool
45
+ /// Popup / bottom sheet geometry for a window; see `ModalLayout.resolve` and `ScreenLayout.modalLayout`.
46
+ public struct ModalLayout: Equatable {
47
+ public let isFoldable: Bool
46
48
  /// Window coordinates of the area popups center in and sheets rest on the bottom of.
47
- let placement: CGRect
48
- let popup: PopupGeometry
49
- let sheet: SheetGeometry
50
- let scrimOpacity: CGFloat
49
+ public let placement: CGRect
50
+ public let popup: PopupGeometry
51
+ public let sheet: SheetGeometry
52
+ public let scrimOpacity: CGFloat
51
53
  }
52
54
 
53
- extension ScreenLayout {
55
+ public extension ScreenLayout {
54
56
  /// Foldable = iPhone Duo or a window whose short side is at least 600 (RN parity), so phones
55
57
  /// in landscape keep their look.
56
58
  var modalLayout: ModalLayout {
59
+ ModalLayout.resolve(width: width, height: height, safeInsets: insets, isDuoDevice: isDuoDevice, hinge: hinge)
60
+ }
61
+ }
62
+
63
+ public extension ModalLayout {
64
+ /// Resolves popup / bottom sheet geometry from plain window metrics, for hosts without a kits screen
65
+ /// (`ScreenLayout.current.modalLayout` covers the key window).
66
+ ///
67
+ /// Points, window coordinates. `safeInsets` is the window safe area; on iPhone Duo it also carries the
68
+ /// control column. `hinge` is the vertical hinge of a half-folded iPhone Duo, nil while flat.
69
+ static func resolve(
70
+ width: CGFloat,
71
+ height: CGFloat,
72
+ safeInsets insets: EdgeInsets = EdgeInsets(),
73
+ isDuoDevice: Bool = false,
74
+ hinge: CGRect? = nil
75
+ ) -> ModalLayout {
57
76
  let isFoldable = isDuoDevice || min(width, height) >= ModalMetrics.foldableMinWidth
58
77
  guard isFoldable else {
59
78
  let placement = CGRect(x: 0, y: 0, width: width, height: height)
60
79
  return ModalLayout(
61
80
  isFoldable: false,
62
81
  placement: placement,
63
- popup: Self.popupGeometry(placementWidth: width, maxHeight: nil, margin: Spacing.XL, radius: Radius.L),
82
+ popup: popupGeometry(placementWidth: width, maxHeight: nil, margin: Spacing.XL, radius: Radius.L),
64
83
  sheet: SheetGeometry(width: nil, maxHeight: nil, minHeight: 0, margin: 0, radius: Radius.M),
65
84
  scrimOpacity: ModalMetrics.phoneScrimOpacity
66
85
  )
67
86
  }
68
87
 
69
88
  // the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
70
- let hinge = self.hinge.flatMap { isDuoDevice && $0.minX > 0 && $0.maxX < width ? $0 : nil }
89
+ let hinge = hinge.flatMap { isDuoDevice && $0.minX > 0 && $0.maxX < width ? $0 : nil }
71
90
  let left = max(insets.leading, hinge?.maxX ?? 0)
72
91
  let placement = CGRect(
73
92
  x: left,
@@ -83,7 +102,7 @@ extension ScreenLayout {
83
102
  return ModalLayout(
84
103
  isFoldable: true,
85
104
  placement: placement,
86
- popup: Self.popupGeometry(
105
+ popup: popupGeometry(
87
106
  placementWidth: placement.width,
88
107
  maxHeight: min(ModalMetrics.popupMaxHeight, placement.height - Spacing.XL * 2),
89
108
  margin: isCompact ? Spacing.M : Spacing.XL,
@@ -109,13 +128,19 @@ extension ScreenLayout {
109
128
  }
110
129
 
111
130
  /// Popup / sheet close and back on foldables: 32 icon button, 20 icon.
112
- struct ModalIconButton: View {
131
+ public struct ModalIconButton: View {
113
132
  @Environment(\.appTheme) private var theme
114
133
  let icon: String
115
134
  let accessibilityId: String
116
135
  let action: () -> Void
117
136
 
118
- var body: some View {
137
+ public init(icon: String, accessibilityId: String, action: @escaping () -> Void) {
138
+ self.icon = icon
139
+ self.accessibilityId = accessibilityId
140
+ self.action = action
141
+ }
142
+
143
+ public var body: some View {
119
144
  Icon(source: icon, size: ModalMetrics.iconSize, color: theme.colors.text.default)
120
145
  .frame(width: ModalMetrics.iconButtonSize, height: ModalMetrics.iconButtonSize)
121
146
  .contentShape(Rectangle())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo-kits/native-kits",
3
- "version": "0.168.1-beta.34-debug",
3
+ "version": "0.168.1-beta.35-debug",
4
4
  "private": false,
5
5
  "dependeNavigationncies": {},
6
6
  "devDependencies": {},