@momo-kits/native-kits 0.300.7-debug → 0.300.8-beta.1-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 +12 -8
- package/README.md +8 -7
- package/compose/build.gradle.kts +2 -4
- package/compose/build.gradle.kts.backup +1 -3
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +1 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +3 -2
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsBinding.kt +60 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/KitsHost.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +20 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +5 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +7 -17
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +18 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +2 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +15 -18
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +4 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +13 -73
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +1 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +1 -53
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +3 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +2 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +12 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +17 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +20 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +3 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +7 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +1 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +83 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +3 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +6 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +13 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +2 -4
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +5 -22
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +6 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +55 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +1 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +3 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +1 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +22 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +2 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +11 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +18 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +5 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +123 -64
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +24 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +11 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +16 -19
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +59 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +69 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +14 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +5 -10
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +43 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +330 -149
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +87 -70
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +1 -5
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +92 -261
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -2
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +31 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +46 -72
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +8 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +29 -24
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +8 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +9 -9
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +26 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +1 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +4 -3
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +2 -3
- package/compose/src/commonTest/kotlin/vn/momo/kits/application/KitsHostTest.kt +44 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt +2 -7
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +9 -18
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +1 -1
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +3 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +5 -6
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +12 -12
- 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 +11 -6
- package/gradle/libs.versions.toml +1 -3
- package/gradle.properties +1 -3
- package/ios/Application/ApplicationEnvironment.swift +6 -4
- package/ios/Application/DesignSystemKits.swift +59 -13
- package/ios/Application/DesignSystemKitsPayload.swift +0 -8
- package/ios/Application/LanguageSource.swift +2 -11
- package/ios/Application/Localize.swift +8 -35
- package/ios/Application/LocalizeModifier.swift +2 -11
- package/ios/Application/MaxApi.swift +3 -11
- package/ios/Avatar/Avatar.swift +0 -1
- package/ios/Badge/Badge.swift +5 -8
- package/ios/Badge/BadgeRibbon.swift +2 -5
- package/ios/Button/Button.swift +4 -8
- package/ios/CalculatorKeyboard/CalculatorKeyboard.swift +5 -7
- package/ios/Carousel/Carousel.swift +4 -17
- package/ios/Checkbox/Checkbox.swift +0 -2
- package/ios/Collapse/Collapse.swift +17 -11
- package/ios/Colors+Radius+Spacing/Theme.swift +0 -7
- package/ios/DateTimePicker/DateTimePicker.swift +4 -10
- package/ios/DateTimePicker/DateTimePickerTypes.swift +1 -3
- package/ios/DateTimePicker/DateTimePickerUtils.swift +0 -3
- package/ios/DateTimePicker/WheelPicker.swift +2 -4
- package/ios/Extensions/ActiveOpacityButtonStyle.swift +2 -3
- package/ios/Extensions/Color++.swift +2 -4
- package/ios/Extensions/SkeletonUICompat.swift +0 -8
- package/ios/Icon/Icon.swift +3 -6
- package/ios/IconButton/IconButton.swift +2 -5
- package/ios/Input/ErrorView.swift +0 -7
- package/ios/Input/Input.swift +9 -20
- package/ios/Input/InputPhoneNumber.swift +37 -20
- package/ios/Input/InputSearch.swift +23 -12
- package/ios/Input/InputTextArea.swift +4 -13
- package/ios/InputDropDown/InputDropDown.swift +1 -11
- package/ios/InputMoney/InputMoney.swift +9 -28
- package/ios/InputOTP/InputOTP.swift +2 -9
- package/ios/Layout/HeaderLayout.swift +72 -0
- package/ios/Layout/Item.swift +1 -2
- package/ios/Layout/ModalLayout.swift +144 -0
- package/ios/Layout/ScreenLayout.swift +48 -31
- package/ios/Layout/Section.swift +2 -3
- package/ios/Loader/Loader.swift +3 -12
- package/ios/Lottie/LottieView.swift +0 -11
- package/ios/Navigation/BottomSheet.swift +73 -94
- package/ios/Navigation/BottomTab/BottomTab.swift +58 -73
- package/ios/Navigation/BottomTab/BottomTabBar.swift +286 -121
- package/ios/Navigation/BottomTab/CurvedContainer.swift +52 -54
- package/ios/Navigation/BottomTab/DuoBarCompression.swift +5 -12
- package/ios/Navigation/BottomTab/DuoTabBar.swift +67 -202
- package/ios/Navigation/BottomTab/TabBarMetrics.swift +97 -0
- package/ios/Navigation/Component/FloatingButton.swift +4 -11
- package/ios/Navigation/Component/Header.swift +35 -54
- package/ios/Navigation/Component/HeaderBackground.swift +2 -8
- package/ios/Navigation/Component/HeaderJourney.swift +4 -8
- package/ios/Navigation/Component/HeaderLocation.swift +4 -8
- package/ios/Navigation/Component/HeaderRight.swift +20 -22
- package/ios/Navigation/Component/HeaderTitle.swift +1 -6
- package/ios/Navigation/Component/HeaderUser.swift +4 -10
- package/ios/Navigation/Component/SideBar.swift +6 -21
- package/ios/Navigation/Component/SnackBar.swift +9 -13
- package/ios/Navigation/HostBackGestureBridge.swift +2 -9
- package/ios/Navigation/ModalScreen.swift +24 -13
- package/ios/Navigation/Navigation.swift +35 -19
- package/ios/Navigation/NavigationContainer.swift +4 -15
- package/ios/Navigation/Navigator.swift +21 -39
- package/ios/Navigation/StackScreen.swift +64 -51
- package/ios/Navigation/StackTransition.swift +7 -14
- package/ios/Navigation/SwipeBackHaptic.swift +2 -7
- package/ios/Navigation/Tracking/ScreenTracker.swift +2 -7
- package/ios/Pagination/PaginationDot.swift +0 -9
- package/ios/Pagination/PaginationNumber.swift +1 -9
- package/ios/Pagination/PaginationScroll.swift +2 -14
- package/ios/Pagination/PaginationWhiteDot.swift +1 -10
- package/ios/Popup/PopupDisplay.swift +7 -5
- package/ios/Popup/PopupInput.swift +6 -4
- package/ios/Popup/PopupLayout.swift +17 -9
- package/ios/Popup/PopupNotify.swift +32 -25
- package/ios/PopupView/FullscreenPopup.swift +3 -4
- package/ios/PopupView/PopupView.swift +2 -2
- package/ios/PopupView/Utils++.swift +1 -2
- package/ios/ProgressInfo/ProgressInfo.swift +2 -13
- package/ios/Skeleton/Skeleton.swift +5 -16
- package/ios/Slider/Slider.swift +5 -12
- package/ios/StatusBarTap/StatusBarTap.h +2 -3
- package/ios/StatusBarTap/StatusBarTap.m +3 -16
- package/ios/Stepper/Stepper.swift +8 -27
- package/ios/Steps/Steps.swift +29 -26
- package/ios/Swipeable/SwipeCell.swift +2 -2
- package/ios/Swipeable/SwipeCellModel.swift +3 -6
- package/ios/TabView/TabView.swift +14 -28
- package/ios/Template/TrustBanner/TrustBanner.swift +2 -9
- package/ios/Title/Title.swift +1 -3
- package/ios/Tooltip/Tooltip.swift +4 -9
- package/ios/Typography/FontScale.swift +79 -24
- package/ios/Typography/Text.swift +6 -12
- package/ios/Typography/Typography.swift +8 -11
- package/ios/Uploader/Uploader.swift +2 -17
- package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
- package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/AnimatedHeaderDemo.swift +11 -2
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +296 -59
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/InputPhoneNumberDemo.swift +15 -4
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/LocalizeDemo.swift +0 -8
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +114 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/TypographyDemo.swift +16 -0
- package/package.json +1 -1
- package/publish.sh +8 -2
- package/scripts/ci/build-swiftui.sh +22 -0
- package/scripts/ci/resolve-version.mjs +144 -0
- package/settings.gradle.kts +0 -1
|
@@ -5,13 +5,8 @@ import androidx.compose.ui.text.font.FontFamily
|
|
|
5
5
|
import androidx.compose.ui.text.font.FontWeight
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* App host (MoMo Platform) đã bundle sẵn toàn bộ font từ `font-source`:
|
|
11
|
-
* - Android: `assets/fonts/<fileName>` (gradle task `syncMomoFonts`)
|
|
12
|
-
* - iOS: file rời ở bundle root (pbxproj fileRef được `post_install.rb` trỏ về font-source)
|
|
13
|
-
*
|
|
14
|
-
* Trả về `null` nếu host không có font đó — caller tự fallback [FontFamily.Default].
|
|
8
|
+
* Loads [fileName] from the host app's bundled fonts instead of a copy in the kit: Android `assets/fonts/`
|
|
9
|
+
* (host task `syncMomoFonts`), iOS bundle root (`post_install.rb`). Null when missing; callers fall back.
|
|
15
10
|
*/
|
|
16
11
|
@Composable
|
|
17
12
|
internal expect fun hostFontFamily(fileName: String, weight: FontWeight): FontFamily?
|
|
@@ -21,11 +21,14 @@ const val MAX_DEVICE_SCALE = 5
|
|
|
21
21
|
@Composable
|
|
22
22
|
fun scaleSize(size: Float): Float {
|
|
23
23
|
val context = LocalContext.current
|
|
24
|
+
// Opt-in ceiling: a set scaleSizeMaxRate caps both the userScaleRate and the OS path at size × capRate.
|
|
25
|
+
val capRate = context?.scaleSizeMaxRate
|
|
26
|
+
fun cap(scaled: Float): Float = if (capRate != null) min(scaled, size * capRate) else scaled
|
|
24
27
|
val useOsScale = context?.useOSScaleRate ?: DesignSystemKits.getConfigs().useOSScaleRate
|
|
25
28
|
if (!useOsScale) {
|
|
26
|
-
return size * (context?.userScaleRate ?: DesignSystemKits.getConfigs().userScaleRate)
|
|
29
|
+
return cap(size * (context?.userScaleRate ?: DesignSystemKits.getConfigs().userScaleRate))
|
|
27
30
|
}
|
|
28
|
-
val scaleSizeMaxRate: Float = MAX_FONT_SCALE
|
|
31
|
+
val scaleSizeMaxRate: Float = capRate ?: MAX_FONT_SCALE
|
|
29
32
|
// Short side, not width: landscape must not inflate every font.
|
|
30
33
|
val deviceWidth = getScreenDimensions().let { minOf(it.width, it.height) }
|
|
31
34
|
val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
|
|
@@ -37,17 +40,18 @@ fun scaleSize(size: Float): Float {
|
|
|
37
40
|
var fontSizeScaleOS = size
|
|
38
41
|
|
|
39
42
|
if (deviceScale > 1) {
|
|
40
|
-
fontSizeScaleDevice =
|
|
41
|
-
min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
|
|
43
|
+
fontSizeScaleDevice = min(deviceScale * fontSizeScaleDevice, fontSizeScaleDevice + MAX_DEVICE_SCALE)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
if (fontScale > 1) {
|
|
45
47
|
fontSizeScaleOS = min(fontScale * fontSizeScaleOS, fontSizeScaleOS * scaleSizeMaxRate)
|
|
46
48
|
}
|
|
47
49
|
|
|
48
|
-
return
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
return cap(
|
|
51
|
+
max(
|
|
52
|
+
fontSizeScaleDevice,
|
|
53
|
+
fontSizeScaleOS
|
|
54
|
+
)
|
|
51
55
|
)
|
|
52
56
|
}
|
|
53
57
|
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
// Stretch frame on hold until design confirms it: Stretch lays out like Grid.
|
|
18
|
+
private const val IS_STRETCH_FRAME_ENABLED = false
|
|
19
|
+
// Banner image width on every device: wide windows keep the phone size, centered.
|
|
20
|
+
val HEADER_BANNER_WIDTH = DEFAULT_SCREEN_SIZE.dp
|
|
21
|
+
internal val HEADER_TITLE_GAP = Spacing.S
|
|
22
|
+
internal val HEADER_SIDE_PADDING = Spacing.M
|
|
23
|
+
// shortcut + gap + help/home pill
|
|
24
|
+
val HEADER_CLUSTER_WIDTH = HEADER_BUTTON_SIZE + HEADER_TITLE_GAP + HEADER_PILL_WIDTH
|
|
25
|
+
|
|
26
|
+
/** How a screen lays out its content on wide windows; the header row follows it. */
|
|
27
|
+
enum class ContentLayout {
|
|
28
|
+
// 12 column grid: the header keeps the 12pt side padding.
|
|
29
|
+
Grid,
|
|
30
|
+
// One column of at most HEADER_FRAME_MAX_WIDTH, centered: the header row sits in the same frame.
|
|
31
|
+
// On hold: same as Grid for now.
|
|
32
|
+
Stretch,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Header geometry for the current window; see [headerLayoutOf]. */
|
|
36
|
+
@Immutable
|
|
37
|
+
data class HeaderLayout(
|
|
38
|
+
// short side >= FOLDABLE_MIN_WIDTH, iPhone Duo excluded (it has its own layout)
|
|
39
|
+
val isWide: Boolean,
|
|
40
|
+
// banner kept at HEADER_BANNER_WIDTH, centered: wide windows plus the iPhone Duo inner display
|
|
41
|
+
val isBannerCentered: Boolean,
|
|
42
|
+
// padding from each side of the safe area to the header row (back, title / search, right cluster)
|
|
43
|
+
val frameInset: Dp,
|
|
44
|
+
// width of the header row, so tabs and other header extensions can line up with it
|
|
45
|
+
val frameWidth: Dp,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
// Pass the screen's NavigationOptions.contentLayout so tabs and extensions line up with its header.
|
|
49
|
+
@Composable
|
|
50
|
+
fun rememberHeaderLayout(contentLayout: ContentLayout = ContentLayout.Grid): HeaderLayout {
|
|
51
|
+
val layout = getScreenLayout()
|
|
52
|
+
return remember(layout, contentLayout) { headerLayoutOf(layout, contentLayout) }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fun headerLayoutOf(layout: ScreenLayout, contentLayout: ContentLayout): HeaderLayout {
|
|
56
|
+
val isDuo = layout.isIPhoneDuo || layout.isIPhoneDuoDevice
|
|
57
|
+
val isLargeWindow = minOf(layout.width, layout.height) >= FOLDABLE_MIN_WIDTH
|
|
58
|
+
val isWide = !isDuo && isLargeWindow
|
|
59
|
+
val isStretch = IS_STRETCH_FRAME_ENABLED && contentLayout == ContentLayout.Stretch
|
|
60
|
+
val frameInset = if (isWide && isStretch) {
|
|
61
|
+
maxOf(HEADER_SIDE_PADDING, (layout.contentWidth - HEADER_FRAME_MAX_WIDTH) / 2)
|
|
62
|
+
} else {
|
|
63
|
+
HEADER_SIDE_PADDING
|
|
64
|
+
}
|
|
65
|
+
return HeaderLayout(
|
|
66
|
+
isWide = isWide,
|
|
67
|
+
isBannerCentered = isLargeWindow,
|
|
68
|
+
frameInset = frameInset,
|
|
69
|
+
frameWidth = layout.contentWidth - frameInset * 2,
|
|
70
|
+
)
|
|
71
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
* Popup / bottom sheet geometry from plain window metrics (dp, window coordinates), for hosts without a kits
|
|
93
|
+
* screen. Insets are the raw safe area, plus the control column on iPhone Duo; [hinge] is null while flat.
|
|
94
|
+
*/
|
|
95
|
+
fun modalLayoutOf(
|
|
96
|
+
width: Dp,
|
|
97
|
+
height: Dp,
|
|
98
|
+
insetLeft: Dp = 0.dp,
|
|
99
|
+
insetTop: Dp = 0.dp,
|
|
100
|
+
insetRight: Dp = 0.dp,
|
|
101
|
+
insetBottom: Dp = 0.dp,
|
|
102
|
+
isIPhoneDuoDevice: Boolean = false,
|
|
103
|
+
hinge: DpRect? = null,
|
|
104
|
+
): ModalLayout {
|
|
105
|
+
val isFoldable = isIPhoneDuoDevice || minOf(width, height) >= FOLDABLE_MIN_WIDTH
|
|
106
|
+
if (!isFoldable) {
|
|
107
|
+
val placement = DpRect(0.dp, 0.dp, width, height)
|
|
108
|
+
return ModalLayout(
|
|
109
|
+
isFoldable = false,
|
|
110
|
+
placement = placement,
|
|
111
|
+
popup = popupGeometry(placement.width, null, Spacing.XL, Radius.XL),
|
|
112
|
+
sheet = SheetGeometry(width = null, maxHeight = null, minHeight = 0.dp, margin = 0.dp, radius = Radius.XL),
|
|
113
|
+
scrimOpacity = PHONE_SCRIM_OPACITY,
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// the safe area keeps overlays clear of the iPhone Duo control column; half folded they move to the right half
|
|
118
|
+
val hinge = hinge?.takeIf { isIPhoneDuoDevice && it.left > 0.dp && it.right < width }
|
|
119
|
+
val placement = DpRect(
|
|
120
|
+
left = maxOf(insetLeft, hinge?.right ?: 0.dp),
|
|
121
|
+
top = insetTop,
|
|
122
|
+
right = width - insetRight,
|
|
123
|
+
bottom = height - insetBottom,
|
|
124
|
+
)
|
|
125
|
+
// outer display and half fold leave little room, so the margins tighten
|
|
126
|
+
val isCompact = isIPhoneDuoDevice && (hinge != null || minOf(width, height) < FOLDABLE_MIN_WIDTH)
|
|
127
|
+
val popupMargin = if (isCompact) Spacing.M else Spacing.XL
|
|
128
|
+
val sheetMargin = Spacing.M
|
|
129
|
+
val sheetMaxHeight = height - insetTop - sheetMargin
|
|
130
|
+
val sheetMinWidth = minOf(SHEET_MIN_WIDTH, placement.width)
|
|
131
|
+
return ModalLayout(
|
|
132
|
+
isFoldable = true,
|
|
133
|
+
placement = placement,
|
|
134
|
+
popup = popupGeometry(
|
|
135
|
+
placementWidth = placement.width,
|
|
136
|
+
maxHeight = minOf(POPUP_MAX_HEIGHT, placement.height - Spacing.XL * 2),
|
|
137
|
+
margin = popupMargin,
|
|
138
|
+
radius = Radius.XL,
|
|
139
|
+
),
|
|
140
|
+
sheet = SheetGeometry(
|
|
141
|
+
width = minOf(placement.width - sheetMargin * 2, SHEET_MAX_WIDTH).coerceAtLeast(sheetMinWidth),
|
|
142
|
+
maxHeight = sheetMaxHeight,
|
|
143
|
+
minHeight = minOf(SHEET_MIN_HEIGHT, sheetMaxHeight),
|
|
144
|
+
margin = sheetMargin,
|
|
145
|
+
radius = Radius.XL,
|
|
146
|
+
),
|
|
147
|
+
scrimOpacity = FOLDABLE_SCRIM_OPACITY,
|
|
148
|
+
)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// clamp(placement - 2 margin, 280, 450); the 280 floor gives way to a narrower placement
|
|
152
|
+
private fun popupGeometry(placementWidth: Dp, maxHeight: Dp?, margin: Dp, radius: Dp): PopupGeometry {
|
|
153
|
+
val minWidth = minOf(POPUP_MIN_WIDTH, placementWidth)
|
|
154
|
+
return PopupGeometry(
|
|
155
|
+
minWidth = minWidth,
|
|
156
|
+
maxWidth = (placementWidth - margin * 2).coerceIn(minWidth, POPUP_MAX_WIDTH.coerceAtLeast(minWidth)),
|
|
157
|
+
maxHeight = maxHeight,
|
|
158
|
+
margin = margin,
|
|
159
|
+
radius = radius,
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Popup close and sheet header back / close: 32 circle on the surface with a border, 20 icon.
|
|
164
|
+
@Composable
|
|
165
|
+
fun ModalIconButton(
|
|
166
|
+
icon: String,
|
|
167
|
+
automationId: String,
|
|
168
|
+
onClick: () -> Unit,
|
|
169
|
+
modifier: Modifier = Modifier,
|
|
170
|
+
) {
|
|
171
|
+
val colors = AppTheme.current.colors
|
|
172
|
+
Box(
|
|
173
|
+
modifier
|
|
174
|
+
.size(MODAL_ICON_BUTTON_SIZE)
|
|
175
|
+
.clip(CircleShape)
|
|
176
|
+
.background(colors.background.surface)
|
|
177
|
+
.border(1.dp, colors.border.default, CircleShape)
|
|
178
|
+
.noFeedbackClickable(onClick = onClick)
|
|
179
|
+
.setAutomationId(automationId),
|
|
180
|
+
contentAlignment = Alignment.Center,
|
|
181
|
+
) {
|
|
182
|
+
Icon(source = icon, size = CLOSE_ICON_SIZE, color = colors.text.default)
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -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
|
|
@@ -51,13 +52,16 @@ data class ScreenLayout(
|
|
|
51
52
|
val headerStatusBarHeight: Dp,
|
|
52
53
|
// iPhone Duo moves back and toolkit into a column in the side safe area; null while they stay in the bar.
|
|
53
54
|
val sideBar: SideBarLayout? = null,
|
|
54
|
-
//
|
|
55
|
+
// iPhone Duo folded or not, whatever the window size (its hinge, or the outer display's one-sided strip);
|
|
56
|
+
// drives popups, modal and bottom sheet.
|
|
55
57
|
val isIPhoneDuoDevice: Boolean = isIPhoneDuo,
|
|
56
58
|
// Portrait iPhone Duo puts the status bar in the side strip, about twice as tall as the strip is wide.
|
|
57
59
|
// Stored so it survives consumeHorizontalInsets().
|
|
58
60
|
val duoTopInset: Dp = insetTop,
|
|
59
61
|
// iPhone Duo inner display in portrait: the header row shares the status bar band, between its clusters.
|
|
60
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,
|
|
61
65
|
) {
|
|
62
66
|
val headerBarHeight: Dp get() = headerHeight - headerStatusBarHeight
|
|
63
67
|
}
|
|
@@ -101,8 +105,7 @@ internal val LocalScreenLayout = compositionLocalOf<ScreenLayout?> { null }
|
|
|
101
105
|
|
|
102
106
|
// Port of RN `useScreenLayout`; follows fold/unfold and rotation through the window size and safe area.
|
|
103
107
|
@Composable
|
|
104
|
-
fun getScreenLayout(): ScreenLayout =
|
|
105
|
-
LocalScreenLayout.current ?: calculateScreenLayout(getAppStatusBarHeight())
|
|
108
|
+
fun getScreenLayout(): ScreenLayout = LocalScreenLayout.current ?: calculateScreenLayout(getAppStatusBarHeight())
|
|
106
109
|
|
|
107
110
|
@Composable
|
|
108
111
|
internal fun calculateScreenLayout(topInset: Dp, parent: ScreenLayout? = null): ScreenLayout {
|
|
@@ -147,14 +150,16 @@ internal fun calculateScreenLayout(topInset: Dp, parent: ScreenLayout? = null):
|
|
|
147
150
|
asymmetricInsets = leftPx != rightPx,
|
|
148
151
|
isDuoDevice = isPhone && reservedRegions.isFoldable,
|
|
149
152
|
reservedRegions = reservedRegions.occlusion,
|
|
153
|
+
division = reservedRegions.division,
|
|
150
154
|
)
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
// Content inside the safe-area padding: the insets are spent and the side bar belongs to the screen.
|
|
156
|
-
internal fun ScreenLayout.consumeHorizontalInsets(): ScreenLayout
|
|
157
|
-
copy(width = contentWidth, insetLeft = 0.dp, insetRight = 0.dp, sideBar = null)
|
|
160
|
+
internal fun ScreenLayout.consumeHorizontalInsets(): ScreenLayout {
|
|
161
|
+
return copy(width = contentWidth, insetLeft = 0.dp, insetRight = 0.dp, sideBar = null)
|
|
162
|
+
}
|
|
158
163
|
|
|
159
164
|
// titleCenterY: window y the title row centers on for the outer display in landscape.
|
|
160
165
|
private fun headerGeometry(
|
|
@@ -186,9 +191,8 @@ private fun statusBarRowGeometry(): Pair<Dp, Dp> = DuoMetrics.innerStatusBarCent
|
|
|
186
191
|
|
|
187
192
|
private data class StripOcclusion(val top: Dp, val topCenter: Dp, val bottom: Dp)
|
|
188
193
|
|
|
189
|
-
//
|
|
190
|
-
//
|
|
191
|
-
// of the region reaching furthest from the top.
|
|
194
|
+
// Reach of system regions into a side strip from each end (the camera sits at either end by rotation),
|
|
195
|
+
// plus the center y of the region reaching furthest from the top.
|
|
192
196
|
private fun stripOcclusion(regions: List<ReservedRegion>, stripLeft: Dp, stripRight: Dp, windowHeight: Dp): StripOcclusion {
|
|
193
197
|
var top = 0.dp
|
|
194
198
|
var topCenter = 0.dp
|
|
@@ -242,6 +246,7 @@ private fun screenLayoutOf(
|
|
|
242
246
|
asymmetricInsets: Boolean,
|
|
243
247
|
isDuoDevice: Boolean,
|
|
244
248
|
reservedRegions: List<ReservedRegion>,
|
|
249
|
+
division: ReservedRegion?,
|
|
245
250
|
): ScreenLayout {
|
|
246
251
|
val isIPhoneDuo = isPhone && isIPhoneDuoWindow(width, height, asymmetricInsets)
|
|
247
252
|
val isInnerPortrait = height > width && width >= DuoMetrics.innerMinHeight
|
|
@@ -299,8 +304,12 @@ private fun screenLayoutOf(
|
|
|
299
304
|
headerHeight = headerHeight,
|
|
300
305
|
headerStatusBarHeight = headerStatusBarHeight,
|
|
301
306
|
sideBar = sideBar,
|
|
302
|
-
|
|
307
|
+
// the outer display reports no hinge; its one-sided strip still gives it away
|
|
308
|
+
isIPhoneDuoDevice = isDuoDevice || (isPhone && asymmetricInsets),
|
|
303
309
|
duoTopInset = maxOf(topInset, if (height > width) sideInset * 2 else 0.dp),
|
|
304
310
|
statusBarClearance = statusBarClearance,
|
|
311
|
+
// only a hinge splitting the window into left and right halves moves overlays
|
|
312
|
+
hinge = division?.takeIf { isPhone && it.height > it.width }
|
|
313
|
+
?.let { DpRect(it.x, it.y, it.x + it.width, it.y + it.height) },
|
|
305
314
|
)
|
|
306
315
|
}
|
|
@@ -18,10 +18,12 @@ fun Modifier.setAutomationId(accessibilityId: String, mergeDescendants: Boolean
|
|
|
18
18
|
semantics(mergeDescendants = mergeDescendants) {
|
|
19
19
|
testTag = accessibilityId
|
|
20
20
|
}
|
|
21
|
-
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
22
23
|
|
|
23
|
-
fun Modifier.kitsAutomationId(accessibilityId: String, label: String? = null)
|
|
24
|
-
this then KitsAutomationIdElement(accessibilityId, label)
|
|
24
|
+
fun Modifier.kitsAutomationId(accessibilityId: String, label: String? = null): Modifier {
|
|
25
|
+
return this then KitsAutomationIdElement(accessibilityId, label)
|
|
26
|
+
}
|
|
25
27
|
|
|
26
28
|
private data class KitsAutomationIdElement(
|
|
27
29
|
private val accessibilityId: String,
|