@momo-kits/native-kits 0.168.1-beta.38-debug → 0.168.1-beta.39-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.
- package/CLAUDE.md +3 -2
- package/compose/build.gradle.kts +1 -1
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +72 -81
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +54 -163
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +9 -3
- package/ios/Input/Input.swift +3 -1
- package/ios/Input/InputTextArea.swift +3 -1
- package/ios/Layout/ModalLayout.swift +152 -0
- package/ios/Layout/ScreenLayout.swift +28 -24
- package/ios/Navigation/BottomSheet.swift +29 -157
- package/ios/Navigation/Component/HeaderRight.swift +1 -1
- package/ios/Navigation/ModalScreen.swift +18 -7
- package/ios/Popup/PopupDisplay.swift +4 -2
- package/ios/Popup/PopupInput.swift +4 -2
- package/ios/Popup/PopupLayout.swift +10 -9
- package/ios/Popup/PopupNotify.swift +26 -23
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
- package/package.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -77,11 +77,12 @@ Publishing is automated (`publish.sh` + GitLab CI on `[ci build]` / `main`). Do
|
|
|
77
77
|
- iPhone Duo with a side strip ≥ 60pt: back + toolkit leave the bar for `HeaderSideBar` (`navigation/component/SideBar.kt`, 48pt glass controls); custom header-right stays in the bar. `sideBar.top` is 170pt in portrait, 120pt on the inner display in landscape (height ≥ 600), 24pt on the outer display in landscape, or below the header when the status bar is on top; UIKit's `statusBarFrame` is useless on Duo. Unlike RN the column is clamped above footer (24pt gap) / rail (12pt gap).
|
|
78
78
|
- Reserved regions (iOS 27.1 `reservedRegionsOfKind:`, reached through the ObjC runtime so older SDKs still build): a probe `UIView` (`platform/ReservedRegions.ios.kt` on the Compose root view; `ReservedRegionsProbe` inside SwiftUI `momoScreenLayout()`) re-reads them in `layoutSubviews`, which UIKit re-runs when they change. They push `sideBar.top` below the status cluster as it grows for calls / Live Activities, and `sideBar.bottom` (≥ 24pt) above a camera at the bottom end of the strip.
|
|
79
79
|
- Tab bar on Duo is `bottomtab/DuoTabBar.kt`: a rail in the side strip (`sideBar.bottom` above the window bottom, QR below it) or, without a side bar, a floating bar spanning 6/8 grid columns. Both overlay the content; `duoFloatingTabBarInset` pads tab content, footer and FAB.
|
|
80
|
+
- Duo tab selection motion (`bottomtab/DuoLiquidSelection.kt` / `ios/Navigation/BottomTab/DuoLiquidSelection.swift`, port of RN `useLiquidSelection.ts`, momo-kits !682): press lifts the lens, a drag past 10pt takes over (Compose: the bar's `pointerInput` consumes and so cancels the tab's clickable; SwiftUI: one `DragGesture` over the bar, tabs are not `Button`s), long press calls `BottomTab(onTabLongPress)` and release still selects, Reduce Motion (`platform/ReduceMotion`) falls back to a plain slide. SwiftUI integrates the lens spring on a display link because the stretch and the tabs' active tint read it every frame. Constants mirror RN — change both together.
|
|
80
81
|
- Bar compression (`bottomtab/DuoBarCompression.kt`, HIG "Vertical controls"): when toolbar + rail don't fit in the strip, one is compressed — the toolkit into a `navigation_menu` button, the rail into one button showing the current tab — and tapping it swaps them; `BottomTab(compressionBehavior)` picks which starts compressed. If neither fits beside the other compressed, both rest compressed and a tap opens one for a moment. Side bar columns report their full height (0 when the screen puts nothing there) so the decision follows each screen's toolkit.
|
|
81
82
|
- Glass header: on Duo with a side bar, Default/Extended headers without search and with a `ScrollState` let content scroll under the bar (`usesDuoGlassHeader`); the bar fades in a translucent surface + hairline over 16pt (Compose has no backdrop blur — RN's fallback look), the gradient leaves with the content.
|
|
82
83
|
- Quick return header: glass headers and Animated headers (with a `ScrollState`) on the Duo side bar layout slide out with the content and back in on a reverse scroll; a half-shown header settles in or out once the scroll stops. The side bar is drawn apart from the header, so it stays put.
|
|
83
|
-
- Overlays on
|
|
84
|
-
- Bottom sheet on Duo:
|
|
84
|
+
- Overlays on foldables (`layout/ModalLayout.kt` / `ios/Layout/ModalLayout.swift`, Figma "Modal - Foldable Guideline", constants shared with RN): foldable = `isIPhoneDuoDevice` or a window short side ≥ 600, so phones (landscape too) keep their look. The resolver returns the placement (safe area, so left of the Duo control column; right of an active vertical division when a Duo is half folded — Swift also needs `UIHingeInteraction` `.partiallyOpen`; Android half fold stays flat), popup geometry (width clamp(placement − 2·margin, 280, 450), margin 24 or 12 on the Duo outer display / half fold, max height min(600, placement − 48), radius 24; only the PopupNotify description scrolls) and sheet geometry (width min(placement − 24, 653) ≥ 296, bottom anchored, max height window − top inset − 12, min height 230, radius 24 top). Scrim is black 20% over the whole window on foldables (0.6 on phones). Snackbars keep clear of the strip. On every device (RN parity) popup close and sheet header back / close are `ModalIconButton`: 32pt circle on `background.surface` with a 1pt `border.default` stroke, 20pt `text.default` icon; the popup close sits inside the card 12pt from the top right (`PopupPromotion` keeps its close under the image), the default sheet header is 56 tall, 12 padding, 8 gap.
|
|
85
|
+
- Bottom sheet on Duo: stays in the placement, never on or under the side strip; back / close stay in the header row (no side column). `BottomHeader.Title(onBack)` / `.title(onBack:)` closes the sheet, then runs (RN `leftOptions.onPressIconLeft`).
|
|
85
86
|
- Font scale deliberately uses the short side (`min(w, h)`), unlike RN which reads the window width — landscape must not inflate every font.
|
|
86
87
|
- Font scale measures the **window**, never `UIScreen.main`: on iPhone Duo the main screen stays on one display while the window follows the one in use. Compose iOS `getScreenDimensions()` reads `LocalWindowInfo.containerSize` (recomposes on fold/unfold); SwiftUI `DesignSystemKits` KVO-observes each `UIWindowScene.effectiveGeometry` and republishes `windowShortSide`.
|
|
87
88
|
- `StackScreen` pads content/footer/search/FAB by the side insets and provides an inset-consumed layout to its content; a bottom-tab root stays full width (tab bar + each tab's StackScreen handle insets). Grid columns use `contentWidth`.
|
package/compose/build.gradle.kts
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package vn.momo.kits.platform
|
|
2
|
+
|
|
3
|
+
import android.provider.Settings
|
|
4
|
+
import androidx.compose.runtime.Composable
|
|
5
|
+
import androidx.compose.runtime.remember
|
|
6
|
+
import androidx.compose.ui.platform.LocalConfiguration
|
|
7
|
+
import androidx.compose.ui.platform.LocalContext
|
|
8
|
+
|
|
9
|
+
@Composable
|
|
10
|
+
actual fun rememberReduceMotion(): Boolean {
|
|
11
|
+
val context = LocalContext.current
|
|
12
|
+
// re-read on configuration changes; the setting has no observer of its own
|
|
13
|
+
val configuration = LocalConfiguration.current
|
|
14
|
+
return remember(context, configuration) {
|
|
15
|
+
Settings.Global.getFloat(context.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1f) == 0f
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -2,8 +2,6 @@ package vn.momo.kits.components
|
|
|
2
2
|
|
|
3
3
|
import androidx.compose.foundation.background
|
|
4
4
|
import androidx.compose.foundation.border
|
|
5
|
-
import androidx.compose.foundation.clickable
|
|
6
|
-
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
7
5
|
import androidx.compose.foundation.rememberScrollState
|
|
8
6
|
import androidx.compose.foundation.verticalScroll
|
|
9
7
|
import androidx.compose.foundation.layout.*
|
|
@@ -22,9 +20,9 @@ import vn.momo.kits.application.LocalLocalize
|
|
|
22
20
|
import vn.momo.kits.const.*
|
|
23
21
|
import vn.momo.kits.modifier.conditional
|
|
24
22
|
import vn.momo.kits.modifier.setAutomationId
|
|
25
|
-
import vn.momo.kits.layout.
|
|
26
|
-
import vn.momo.kits.layout.
|
|
27
|
-
import vn.momo.kits.layout.
|
|
23
|
+
import vn.momo.kits.layout.MODAL_ICON_BUTTON_SIZE
|
|
24
|
+
import vn.momo.kits.layout.ModalIconButton
|
|
25
|
+
import vn.momo.kits.layout.rememberModalLayout
|
|
28
26
|
import kotlin.math.min
|
|
29
27
|
|
|
30
28
|
data class PopupAction(
|
|
@@ -38,28 +36,24 @@ enum class PopupActionDirection {
|
|
|
38
36
|
AUTO
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
// Card width
|
|
39
|
+
// Card width on foldables (ModalLayout, RN Popup/utils.ts); unbounded on phones, where each popup's padding sets it.
|
|
42
40
|
@Composable
|
|
43
41
|
internal fun popupMaxWidth(): Dp {
|
|
44
|
-
val
|
|
45
|
-
return if (
|
|
42
|
+
val modal = rememberModalLayout()
|
|
43
|
+
return if (modal.isFoldable) modal.popup.maxWidth else Dp.Unspecified
|
|
46
44
|
}
|
|
47
45
|
|
|
48
|
-
// The
|
|
46
|
+
// The placement already keeps foldable popups off the edges, so their own side padding goes.
|
|
49
47
|
@Composable
|
|
50
48
|
internal fun popupHorizontalPadding(padding: Dp): Dp =
|
|
51
|
-
if (
|
|
49
|
+
if (rememberModalLayout().isFoldable) 0.dp else padding
|
|
52
50
|
|
|
53
|
-
// Tallest a popup gets on
|
|
51
|
+
// Tallest a popup gets on foldables; null on phones.
|
|
54
52
|
@Composable
|
|
55
|
-
internal fun popupMaxHeight(): Dp?
|
|
56
|
-
val layout = getScreenLayout()
|
|
57
|
-
return if (layout.isIPhoneDuoDevice) layout.duoModalMaxHeight else null
|
|
58
|
-
}
|
|
53
|
+
internal fun popupMaxHeight(): Dp? = rememberModalLayout().popup.maxHeight
|
|
59
54
|
|
|
60
|
-
// Rounder on iPhone Duo, closer to its system alerts.
|
|
61
55
|
@Composable
|
|
62
|
-
internal fun popupRadius(): Dp =
|
|
56
|
+
internal fun popupRadius(): Dp = rememberModalLayout().popup.radius
|
|
63
57
|
|
|
64
58
|
private fun heightForLines(
|
|
65
59
|
layout: TextLayoutResult,
|
|
@@ -152,19 +146,21 @@ fun PopupNotify(
|
|
|
152
146
|
callback?.invoke()
|
|
153
147
|
}
|
|
154
148
|
|
|
155
|
-
val
|
|
156
|
-
val
|
|
157
|
-
val
|
|
158
|
-
val shape = RoundedCornerShape(
|
|
149
|
+
val popup = rememberModalLayout().popup
|
|
150
|
+
val maxHeight = popup.maxHeight
|
|
151
|
+
val descriptionScrollState = rememberScrollState()
|
|
152
|
+
val shape = RoundedCornerShape(popup.radius)
|
|
159
153
|
|
|
160
154
|
Box(
|
|
161
|
-
Modifier
|
|
155
|
+
Modifier
|
|
156
|
+
.widthIn(min = popup.minWidth, max = popup.maxWidth)
|
|
157
|
+
.fillMaxWidth()
|
|
158
|
+
.setAutomationId("popup_notify"),
|
|
159
|
+
contentAlignment = Alignment.TopEnd
|
|
162
160
|
) {
|
|
163
161
|
Column(
|
|
164
162
|
modifier = Modifier
|
|
165
|
-
.widthIn(max = popupMaxWidth())
|
|
166
163
|
.fillMaxWidth()
|
|
167
|
-
.padding(horizontal = horizontalPadding)
|
|
168
164
|
.clip(shape)
|
|
169
165
|
.background(AppTheme.current.colors.background.surface, shape)
|
|
170
166
|
.conditional(IsShowBaseLineDebug) {
|
|
@@ -174,37 +170,56 @@ fun PopupNotify(
|
|
|
174
170
|
heightIn(max = maxHeight ?: Dp.Unspecified)
|
|
175
171
|
}
|
|
176
172
|
) {
|
|
177
|
-
|
|
173
|
+
if(props.image.isNotEmpty()) {
|
|
174
|
+
Image(
|
|
175
|
+
source = props.image,
|
|
176
|
+
modifier = Modifier.fillMaxWidth().aspectRatio(1.777f),
|
|
177
|
+
options = Options(alignment = Alignment.Center)
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// with a max height only the description scrolls; image, title and actions stay
|
|
178
182
|
Column(
|
|
179
|
-
|
|
180
|
-
weight(1f, fill = false)
|
|
181
|
-
|
|
183
|
+
modifier = Modifier
|
|
184
|
+
.conditional(maxHeight != null) { weight(1f, fill = false) }
|
|
185
|
+
.padding(Spacing.XL)
|
|
182
186
|
) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
187
|
+
Text(
|
|
188
|
+
style = Typography.headerDefaultBold,
|
|
189
|
+
maxLines = 2,
|
|
190
|
+
text = props.title,
|
|
191
|
+
modifier = Modifier
|
|
192
|
+
.conditional(props.isShowCloseIcon && props.image.isEmpty()) {
|
|
193
|
+
padding(end = MODAL_ICON_BUTTON_SIZE + Spacing.M - Spacing.XL)
|
|
194
|
+
}
|
|
195
|
+
.setAutomationId("title_popup_permission")
|
|
196
|
+
)
|
|
197
|
+
if (maxHeight != null) {
|
|
198
|
+
// still capped at ~8.5 lines, then shrinks further when the popup reaches its max height
|
|
199
|
+
Box(
|
|
200
|
+
Modifier
|
|
201
|
+
.padding(top = Spacing.S)
|
|
202
|
+
.weight(1f, fill = false)
|
|
203
|
+
.conditional(isScroll) { heightIn(max = scrollHeight) }
|
|
204
|
+
.verticalScroll(descriptionScrollState)
|
|
205
|
+
) {
|
|
200
206
|
Text(
|
|
201
|
-
text =
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
maxLines = 1,
|
|
205
|
-
modifier = Modifier.padding(top = Spacing.S)
|
|
207
|
+
text = props.description,
|
|
208
|
+
onTextLayout = { layoutResult.value = it },
|
|
209
|
+
style = Typography.bodyDefaultRegular
|
|
206
210
|
)
|
|
207
211
|
}
|
|
212
|
+
} else {
|
|
213
|
+
content(Modifier.padding(top = Spacing.S))
|
|
214
|
+
}
|
|
215
|
+
if (props.error.isNotEmpty()) {
|
|
216
|
+
Text(
|
|
217
|
+
text = LocalLocalize.current.translate("errorCode") + props.error,
|
|
218
|
+
style = Typography.descriptionXsRegular,
|
|
219
|
+
color = AppTheme.current.colors.text.hint,
|
|
220
|
+
maxLines = 1,
|
|
221
|
+
modifier = Modifier.padding(top = Spacing.S)
|
|
222
|
+
)
|
|
208
223
|
}
|
|
209
224
|
}
|
|
210
225
|
|
|
@@ -218,37 +233,13 @@ fun PopupNotify(
|
|
|
218
233
|
}
|
|
219
234
|
}
|
|
220
235
|
|
|
221
|
-
if(props.isShowCloseIcon) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
.background(
|
|
229
|
-
color = AppTheme.current.colors.text.default,
|
|
230
|
-
shape = RoundedCornerShape(Radius.M)
|
|
231
|
-
)
|
|
232
|
-
.border(
|
|
233
|
-
width = 2.dp,
|
|
234
|
-
color = AppTheme.current.colors.background.surface,
|
|
235
|
-
shape = RoundedCornerShape(Radius.M)
|
|
236
|
-
)
|
|
237
|
-
.clip(RoundedCornerShape(100))
|
|
238
|
-
.clickable(
|
|
239
|
-
interactionSource = remember { MutableInteractionSource() },
|
|
240
|
-
indication = null,
|
|
241
|
-
onClick = { onClose { props.onIconClose() } }
|
|
242
|
-
),
|
|
243
|
-
contentAlignment = Alignment.Center
|
|
244
|
-
) {
|
|
245
|
-
Icon(
|
|
246
|
-
source = "navigation_close",
|
|
247
|
-
color = AppTheme.current.colors.background.surface,
|
|
248
|
-
size = 16.dp,
|
|
249
|
-
modifier = Modifier.setAutomationId("ic_popup_close")
|
|
250
|
-
)
|
|
251
|
-
}
|
|
236
|
+
if (props.isShowCloseIcon) {
|
|
237
|
+
ModalIconButton(
|
|
238
|
+
icon = "navigation_close",
|
|
239
|
+
automationId = "ic_popup_close",
|
|
240
|
+
onClick = { onClose { props.onIconClose() } },
|
|
241
|
+
modifier = Modifier.padding(top = Spacing.M, end = Spacing.M),
|
|
242
|
+
)
|
|
252
243
|
}
|
|
253
244
|
}
|
|
254
245
|
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
package vn.momo.kits.layout
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.background
|
|
4
|
+
import androidx.compose.foundation.border
|
|
5
|
+
import androidx.compose.foundation.layout.Box
|
|
6
|
+
import androidx.compose.foundation.layout.size
|
|
7
|
+
import androidx.compose.foundation.shape.CircleShape
|
|
8
|
+
import androidx.compose.runtime.Composable
|
|
9
|
+
import androidx.compose.runtime.Immutable
|
|
10
|
+
import androidx.compose.runtime.remember
|
|
11
|
+
import androidx.compose.ui.Alignment
|
|
12
|
+
import androidx.compose.ui.Modifier
|
|
13
|
+
import androidx.compose.ui.draw.clip
|
|
14
|
+
import androidx.compose.ui.unit.Dp
|
|
15
|
+
import androidx.compose.ui.unit.DpRect
|
|
16
|
+
import androidx.compose.ui.unit.dp
|
|
17
|
+
import androidx.compose.ui.unit.height
|
|
18
|
+
import androidx.compose.ui.unit.width
|
|
19
|
+
import vn.momo.kits.components.Icon
|
|
20
|
+
import vn.momo.kits.const.AppTheme
|
|
21
|
+
import vn.momo.kits.const.Radius
|
|
22
|
+
import vn.momo.kits.const.Spacing
|
|
23
|
+
import vn.momo.kits.modifier.noFeedbackClickable
|
|
24
|
+
import vn.momo.kits.modifier.setAutomationId
|
|
25
|
+
|
|
26
|
+
// Foldable spec for Popup and BottomSheet (Figma "Modal - Foldable Guideline"); mirrors RN and SwiftUI, keep in sync.
|
|
27
|
+
// Public so host apps can size their own (non-kits) popups and sheets the same way.
|
|
28
|
+
val POPUP_MAX_WIDTH = 450.dp
|
|
29
|
+
val POPUP_MIN_WIDTH = 280.dp
|
|
30
|
+
val POPUP_MAX_HEIGHT = 600.dp
|
|
31
|
+
val SHEET_MAX_WIDTH = 653.dp
|
|
32
|
+
val SHEET_MIN_WIDTH = 296.dp
|
|
33
|
+
val SHEET_MIN_HEIGHT = 230.dp
|
|
34
|
+
val FOLDABLE_MIN_WIDTH = 600.dp
|
|
35
|
+
internal val MODAL_ICON_BUTTON_SIZE = 32.dp
|
|
36
|
+
private val CLOSE_ICON_SIZE = 20.dp
|
|
37
|
+
private const val PHONE_SCRIM_OPACITY = 0.6f
|
|
38
|
+
private const val FOLDABLE_SCRIM_OPACITY = 0.2f
|
|
39
|
+
|
|
40
|
+
@Immutable
|
|
41
|
+
data class PopupGeometry(
|
|
42
|
+
val minWidth: Dp,
|
|
43
|
+
val maxWidth: Dp,
|
|
44
|
+
// null: as tall as the content, phones keep their own caps
|
|
45
|
+
val maxHeight: Dp?,
|
|
46
|
+
val margin: Dp,
|
|
47
|
+
val radius: Dp,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
@Immutable
|
|
51
|
+
data class SheetGeometry(
|
|
52
|
+
// null: spans the window
|
|
53
|
+
val width: Dp?,
|
|
54
|
+
// null: phones keep their own cap
|
|
55
|
+
val maxHeight: Dp?,
|
|
56
|
+
val minHeight: Dp,
|
|
57
|
+
val margin: Dp,
|
|
58
|
+
val radius: Dp,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
/** Popup / bottom sheet geometry for the current window; see [modalLayoutOf]. */
|
|
62
|
+
@Immutable
|
|
63
|
+
data class ModalLayout(
|
|
64
|
+
val isFoldable: Boolean,
|
|
65
|
+
// window coordinates of the area popups center in and sheets rest on the bottom of
|
|
66
|
+
val placement: DpRect,
|
|
67
|
+
val popup: PopupGeometry,
|
|
68
|
+
val sheet: SheetGeometry,
|
|
69
|
+
val scrimOpacity: Float,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
// Foldable = iPhone Duo or a window whose short side is at least FOLDABLE_MIN_WIDTH (RN parity),
|
|
73
|
+
// so phones in landscape keep their look.
|
|
74
|
+
@Composable
|
|
75
|
+
internal fun rememberModalLayout(): ModalLayout {
|
|
76
|
+
val layout = getScreenLayout()
|
|
77
|
+
return remember(layout) { modalLayoutOf(layout) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
internal fun modalLayoutOf(layout: ScreenLayout): ModalLayout = modalLayoutOf(
|
|
81
|
+
width = layout.width,
|
|
82
|
+
height = layout.height,
|
|
83
|
+
insetLeft = layout.insetLeft,
|
|
84
|
+
insetTop = layout.insetTop,
|
|
85
|
+
insetRight = layout.insetRight,
|
|
86
|
+
insetBottom = layout.insetBottom,
|
|
87
|
+
isIPhoneDuoDevice = layout.isIPhoneDuoDevice,
|
|
88
|
+
hinge = layout.hinge,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Resolves popup / bottom sheet geometry from plain window metrics, for hosts without a kits screen.
|
|
93
|
+
*
|
|
94
|
+
* All values are in dp and window coordinates. The insets are the raw safe area (system bars and
|
|
95
|
+
* display cutout); on iPhone Duo they also carry the control column. [hinge] is the vertical hinge of
|
|
96
|
+
* a half-folded iPhone Duo, null while flat. Pure: no composition needed.
|
|
97
|
+
*/
|
|
98
|
+
fun modalLayoutOf(
|
|
99
|
+
width: Dp,
|
|
100
|
+
height: Dp,
|
|
101
|
+
insetLeft: Dp = 0.dp,
|
|
102
|
+
insetTop: Dp = 0.dp,
|
|
103
|
+
insetRight: Dp = 0.dp,
|
|
104
|
+
insetBottom: Dp = 0.dp,
|
|
105
|
+
isIPhoneDuoDevice: Boolean = false,
|
|
106
|
+
hinge: DpRect? = null,
|
|
107
|
+
): ModalLayout {
|
|
108
|
+
val isFoldable = isIPhoneDuoDevice || minOf(width, height) >= FOLDABLE_MIN_WIDTH
|
|
109
|
+
if (!isFoldable) {
|
|
110
|
+
val placement = DpRect(0.dp, 0.dp, width, height)
|
|
111
|
+
return ModalLayout(
|
|
112
|
+
isFoldable = false,
|
|
113
|
+
placement = placement,
|
|
114
|
+
popup = popupGeometry(placement.width, null, Spacing.XL, Radius.L),
|
|
115
|
+
sheet = SheetGeometry(width = null, maxHeight = null, minHeight = 0.dp, margin = 0.dp, radius = Radius.M),
|
|
116
|
+
scrimOpacity = PHONE_SCRIM_OPACITY,
|
|
117
|
+
)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
|
|
121
|
+
val hinge = hinge?.takeIf { isIPhoneDuoDevice && it.left > 0.dp && it.right < width }
|
|
122
|
+
val placement = DpRect(
|
|
123
|
+
left = maxOf(insetLeft, hinge?.right ?: 0.dp),
|
|
124
|
+
top = insetTop,
|
|
125
|
+
right = width - insetRight,
|
|
126
|
+
bottom = height - insetBottom,
|
|
127
|
+
)
|
|
128
|
+
// outer display and half fold leave little room, so the margins tighten
|
|
129
|
+
val isCompact = isIPhoneDuoDevice && (hinge != null || minOf(width, height) < FOLDABLE_MIN_WIDTH)
|
|
130
|
+
val popupMargin = if (isCompact) Spacing.M else Spacing.XL
|
|
131
|
+
val sheetMargin = Spacing.M
|
|
132
|
+
val sheetMaxHeight = height - insetTop - sheetMargin
|
|
133
|
+
val sheetMinWidth = minOf(SHEET_MIN_WIDTH, placement.width)
|
|
134
|
+
return ModalLayout(
|
|
135
|
+
isFoldable = true,
|
|
136
|
+
placement = placement,
|
|
137
|
+
popup = popupGeometry(
|
|
138
|
+
placementWidth = placement.width,
|
|
139
|
+
maxHeight = minOf(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
140
|
+
margin = popupMargin,
|
|
141
|
+
radius = Radius.XL,
|
|
142
|
+
),
|
|
143
|
+
sheet = SheetGeometry(
|
|
144
|
+
width = minOf(placement.width - sheetMargin * 2, SHEET_MAX_WIDTH).coerceAtLeast(sheetMinWidth),
|
|
145
|
+
maxHeight = sheetMaxHeight,
|
|
146
|
+
minHeight = minOf(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
147
|
+
margin = sheetMargin,
|
|
148
|
+
radius = Radius.XL,
|
|
149
|
+
),
|
|
150
|
+
scrimOpacity = FOLDABLE_SCRIM_OPACITY,
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// clamp(placement - 2 margin, 280, 450); the 280 floor gives way to a narrower placement
|
|
155
|
+
private fun popupGeometry(placementWidth: Dp, maxHeight: Dp?, margin: Dp, radius: Dp): PopupGeometry {
|
|
156
|
+
val minWidth = minOf(POPUP_MIN_WIDTH, placementWidth)
|
|
157
|
+
return PopupGeometry(
|
|
158
|
+
minWidth = minWidth,
|
|
159
|
+
maxWidth = (placementWidth - margin * 2).coerceIn(minWidth, POPUP_MAX_WIDTH.coerceAtLeast(minWidth)),
|
|
160
|
+
maxHeight = maxHeight,
|
|
161
|
+
margin = margin,
|
|
162
|
+
radius = radius,
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Popup close and sheet header back / close: 32 circle on the surface with a border, 20 icon.
|
|
167
|
+
@Composable
|
|
168
|
+
fun ModalIconButton(
|
|
169
|
+
icon: String,
|
|
170
|
+
automationId: String,
|
|
171
|
+
onClick: () -> Unit,
|
|
172
|
+
modifier: Modifier = Modifier,
|
|
173
|
+
) {
|
|
174
|
+
val colors = AppTheme.current.colors
|
|
175
|
+
Box(
|
|
176
|
+
modifier
|
|
177
|
+
.size(MODAL_ICON_BUTTON_SIZE)
|
|
178
|
+
.clip(CircleShape)
|
|
179
|
+
.background(colors.background.surface)
|
|
180
|
+
.border(1.dp, colors.border.default, CircleShape)
|
|
181
|
+
.noFeedbackClickable(onClick = onClick)
|
|
182
|
+
.setAutomationId(automationId),
|
|
183
|
+
contentAlignment = Alignment.Center,
|
|
184
|
+
) {
|
|
185
|
+
Icon(source = icon, size = CLOSE_ICON_SIZE, color = colors.text.default)
|
|
186
|
+
}
|
|
187
|
+
}
|
|
@@ -10,6 +10,7 @@ import androidx.compose.ui.platform.LocalDensity
|
|
|
10
10
|
import androidx.compose.ui.platform.LocalLayoutDirection
|
|
11
11
|
import androidx.compose.ui.platform.LocalWindowInfo
|
|
12
12
|
import androidx.compose.ui.unit.Dp
|
|
13
|
+
import androidx.compose.ui.unit.DpRect
|
|
13
14
|
import androidx.compose.ui.unit.dp
|
|
14
15
|
import vn.momo.kits.const.Spacing
|
|
15
16
|
import vn.momo.kits.navigation.component.HEADER_HEIGHT
|
|
@@ -59,6 +60,8 @@ data class ScreenLayout(
|
|
|
59
60
|
val duoTopInset: Dp = insetTop,
|
|
60
61
|
// iPhone Duo inner display in portrait: the header row shares the status bar band, between its clusters.
|
|
61
62
|
val statusBarClearance: StatusBarClearance? = null,
|
|
63
|
+
// Half-folded iPhone Duo: the hinge in window coordinates, running top to bottom; null while flat.
|
|
64
|
+
val hinge: DpRect? = null,
|
|
62
65
|
) {
|
|
63
66
|
val headerBarHeight: Dp get() = headerHeight - headerStatusBarHeight
|
|
64
67
|
}
|
|
@@ -91,11 +94,6 @@ internal object DuoMetrics {
|
|
|
91
94
|
val floatingTabBarHeight = 62.dp
|
|
92
95
|
val floatingTabBarMargin = 20.dp
|
|
93
96
|
val floatingTabBarInsetOverlap = 13.dp
|
|
94
|
-
// Width of a system alert on the inner display, in both orientations.
|
|
95
|
-
val modalMaxWidth = 440.dp
|
|
96
|
-
// Fits a PopupNotify with image, scrolled description and actions at the max width (RN
|
|
97
|
-
// Application/device.ts); taller content scrolls instead of filling the inner display.
|
|
98
|
-
val modalMaxHeight = 640.dp
|
|
99
97
|
}
|
|
100
98
|
|
|
101
99
|
private val IPHONE_HEADER_MIN_HEIGHT = 72.dp
|
|
@@ -153,19 +151,12 @@ internal fun calculateScreenLayout(topInset: Dp, parent: ScreenLayout? = null):
|
|
|
153
151
|
asymmetricInsets = leftPx != rightPx,
|
|
154
152
|
isDuoDevice = isPhone && reservedRegions.isFoldable,
|
|
155
153
|
reservedRegions = reservedRegions.occlusion,
|
|
154
|
+
division = reservedRegions.division,
|
|
156
155
|
)
|
|
157
156
|
}
|
|
158
157
|
}
|
|
159
158
|
}
|
|
160
159
|
|
|
161
|
-
// Room for a dialog on iPhone Duo: inside the safe area, so clear of the side toolbar strip, and
|
|
162
|
-
// capped so it stays a dialog on the inner display.
|
|
163
|
-
internal val ScreenLayout.duoModalMaxWidth: Dp
|
|
164
|
-
get() = minOf(width - insetLeft - insetRight - Spacing.XL * 2, DuoMetrics.modalMaxWidth)
|
|
165
|
-
|
|
166
|
-
internal val ScreenLayout.duoModalMaxHeight: Dp
|
|
167
|
-
get() = minOf(height - insetTop - insetBottom - Spacing.XL * 2, DuoMetrics.modalMaxHeight)
|
|
168
|
-
|
|
169
160
|
// Content inside the safe-area padding: the insets are spent and the side bar belongs to the screen.
|
|
170
161
|
internal fun ScreenLayout.consumeHorizontalInsets(): ScreenLayout =
|
|
171
162
|
copy(width = contentWidth, insetLeft = 0.dp, insetRight = 0.dp, sideBar = null)
|
|
@@ -256,6 +247,7 @@ private fun screenLayoutOf(
|
|
|
256
247
|
asymmetricInsets: Boolean,
|
|
257
248
|
isDuoDevice: Boolean,
|
|
258
249
|
reservedRegions: List<ReservedRegion>,
|
|
250
|
+
division: ReservedRegion?,
|
|
259
251
|
): ScreenLayout {
|
|
260
252
|
val isIPhoneDuo = isPhone && isIPhoneDuoWindow(width, height, asymmetricInsets)
|
|
261
253
|
val isInnerPortrait = height > width && width >= DuoMetrics.innerMinHeight
|
|
@@ -317,5 +309,8 @@ private fun screenLayoutOf(
|
|
|
317
309
|
isIPhoneDuoDevice = isDuoDevice || (isPhone && asymmetricInsets),
|
|
318
310
|
duoTopInset = maxOf(topInset, if (height > width) sideInset * 2 else 0.dp),
|
|
319
311
|
statusBarClearance = statusBarClearance,
|
|
312
|
+
// only a hinge splitting the window into left and right halves moves overlays
|
|
313
|
+
hinge = division?.takeIf { isPhone && it.height > it.width }
|
|
314
|
+
?.let { DpRect(it.x, it.y, it.x + it.width, it.y + it.height) },
|
|
320
315
|
)
|
|
321
316
|
}
|