@momo-kits/native-kits 0.168.1-sizescale.1-debug → 0.169.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.
Files changed (64) hide show
  1. package/CLAUDE.md +4 -3
  2. package/PUBLISH_GUIDE.md +29 -658
  3. package/compose/build.gradle.kts +2 -2
  4. package/compose/compose.podspec +1 -1
  5. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +4 -5
  6. package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
  7. package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +2 -2
  8. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +21 -15
  9. package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +76 -83
  10. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +3 -3
  11. package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +1 -1
  12. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +11 -14
  13. package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +3 -4
  14. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +187 -0
  15. package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +8 -13
  16. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +57 -163
  17. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +17 -12
  18. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +4 -7
  19. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +5 -7
  20. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +18 -11
  21. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +34 -23
  22. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +321 -149
  23. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +79 -71
  24. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +87 -261
  25. package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +104 -0
  26. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +3 -2
  27. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +3 -1
  28. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
  29. package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +2 -0
  30. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +1 -2
  31. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +3 -2
  32. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
  33. package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +9 -3
  34. package/gradle.properties +1 -3
  35. package/ios/Input/Input.swift +3 -1
  36. package/ios/Input/InputTextArea.swift +3 -1
  37. package/ios/Layout/ModalLayout.swift +152 -0
  38. package/ios/Layout/ScreenLayout.swift +28 -24
  39. package/ios/Navigation/BottomSheet.swift +29 -156
  40. package/ios/Navigation/BottomTab/BottomTab.swift +46 -52
  41. package/ios/Navigation/BottomTab/BottomTabBar.swift +281 -115
  42. package/ios/Navigation/BottomTab/CurvedContainer.swift +51 -47
  43. package/ios/Navigation/BottomTab/DuoTabBar.swift +62 -195
  44. package/ios/Navigation/BottomTab/TabBarMetrics.swift +84 -0
  45. package/ios/Navigation/Component/HeaderRight.swift +1 -1
  46. package/ios/Navigation/ModalScreen.swift +18 -7
  47. package/ios/Navigation/StackScreen.swift +3 -1
  48. package/ios/Popup/PopupDisplay.swift +4 -2
  49. package/ios/Popup/PopupInput.swift +4 -2
  50. package/ios/Popup/PopupLayout.swift +10 -9
  51. package/ios/Popup/PopupNotify.swift +32 -25
  52. package/ios/Typography/Text.swift +2 -2
  53. package/ios/native-kits.podspec +1 -1
  54. package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
  55. package/ios-demo/Resources/tabbar_scan_qr_button.json +1 -0
  56. package/ios-demo/Resources/tabbar_scan_qr_label.json +1 -0
  57. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +272 -59
  58. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/NavigationDemo.swift +103 -0
  59. package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/PopupNotifyDemo.swift +29 -1
  60. package/local.properties +8 -0
  61. package/package.json +1 -1
  62. package/publish.sh +170 -513
  63. package/compose/build.gradle.kts.backup +0 -198
  64. package/compose/src/commonMain/kotlin/vn/momo/kits/const/KitSizeScale.kt +0 -45
@@ -7,7 +7,7 @@ plugins {
7
7
  alias(libs.plugins.android.library)
8
8
  alias(libs.plugins.compose)
9
9
  alias(libs.plugins.kotlin.compose.compiler)
10
- // alias(libs.plugins.vanniktech.mavenPublish)
10
+ // alias(libs.plugins.vanniktech.mavenPublish)
11
11
  id(libs.plugins.jetbrains.kotlin.cocoapods.get().pluginId)
12
12
  kotlin("plugin.serialization")
13
13
  }
@@ -40,7 +40,7 @@ kotlin {
40
40
  }
41
41
 
42
42
  cocoapods {
43
- version = "0.168.1-sizescale.1-debug"
43
+ version = "0.169.1-debug"
44
44
  summary = "IOS Shared module"
45
45
  homepage = "https://momo.vn"
46
46
  ios.deploymentTarget = "15.0"
@@ -1,6 +1,6 @@
1
1
  Pod::Spec.new do |spec|
2
2
  spec.name = 'compose'
3
- spec.version = '0.168.1-beta.8-debug'
3
+ spec.version = '0.169.1-debug'
4
4
  spec.homepage = 'https://momo.vn'
5
5
  spec.source = { :http=> ''}
6
6
  spec.authors = ''
@@ -30,7 +30,6 @@ import com.airbnb.lottie.compose.rememberLottieDynamicProperties
30
30
  import com.airbnb.lottie.compose.rememberLottieDynamicProperty
31
31
  import vn.momo.kits.const.AppNavigationBar
32
32
  import vn.momo.kits.const.AppStatusBar
33
- import vn.momo.kits.const.LocalSizeScale
34
33
  import vn.momo.kits.navigation.Navigator
35
34
  import vn.momo.kits.utils.readJson
36
35
  import androidx.activity.compose.BackHandler as AndroidBackHandler
@@ -42,9 +41,8 @@ actual fun isPhoneIdiom(): Boolean = false
42
41
  @Composable
43
42
  actual fun getScreenDimensions(): ScreenDimension {
44
43
  val config = LocalConfiguration.current
45
- val sizeScale = LocalSizeScale.current
46
44
  return ScreenDimension(
47
- (config.screenWidthDp / sizeScale).toInt(), (config.screenHeightDp / sizeScale).toInt()
45
+ config.screenWidthDp, config.screenHeightDp
48
46
  )
49
47
  }
50
48
 
@@ -90,10 +88,11 @@ actual fun LottieAnimation(
90
88
  isPlaying: Boolean,
91
89
  onEvent: ((String) -> Unit)?,
92
90
  modifier: Modifier,
93
- useCompose: Boolean
91
+ useCompose: Boolean,
92
+ progress: (() -> Float)?,
94
93
  ) {
95
94
  if (useCompose) {
96
- ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier)
95
+ ComposeLottieAnimation(path, tintColor, bgColor, iterations, isPlaying, onEvent, modifier, progress)
97
96
  return
98
97
  }
99
98
 
@@ -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
+ }
@@ -7,7 +7,7 @@ import androidx.compose.runtime.remember
7
7
  import vn.momo.kits.const.AppTheme
8
8
  import vn.momo.kits.const.Theme
9
9
  import vn.momo.kits.navigation.LocalMaxApi
10
- import vn.momo.kits.const.ProvideKitScale
10
+ import vn.momo.kits.platform.ProvideOsFontScale
11
11
  import vn.momo.maxapi.IMaxApi
12
12
 
13
13
 
@@ -37,7 +37,7 @@ fun WidgetContainer(
37
37
  }
38
38
  }
39
39
 
40
- ProvideKitScale {
40
+ ProvideOsFontScale {
41
41
  CompositionLocalProvider(
42
42
  AppTheme provides resolvedTheme,
43
43
  LocalContext provides mergedContext,
@@ -69,21 +69,7 @@ fun Information(
69
69
  iconSource = "24_notifications_alert_octagon"
70
70
  }
71
71
 
72
- // Host fonts are one file per weight: swap fontFamily and disable synthesis so the SemiBold file isn't
73
- // faux-bolded again; fontWeight still applies when no host font is bundled and the system font is used.
74
- val highlightWeight = Typography.headerXsSemibold.fontWeight
75
- val highlightFontFamily = getFontFamily(AppTheme.current.font, highlightWeight)
76
- val annotatedDescription = remember(description, highlightText, highlightFontFamily) {
77
- highlightDescription(
78
- description,
79
- highlightText,
80
- SpanStyle(
81
- fontFamily = highlightFontFamily,
82
- fontWeight = highlightWeight,
83
- fontSynthesis = FontSynthesis.None,
84
- ),
85
- )
86
- }
72
+ val annotatedDescription = rememberHighlightDescription(description, highlightText)
87
73
 
88
74
  Column(
89
75
  modifier = Modifier.border(
@@ -157,6 +143,26 @@ fun Information(
157
143
 
158
144
  }
159
145
 
146
+ // Highlighted keywords keep the caller's text size; only the weight changes.
147
+ @Composable
148
+ internal fun rememberHighlightDescription(description: String, highlightText: List<String>): AnnotatedString {
149
+ // Host fonts are one file per weight: swap fontFamily and disable synthesis so the SemiBold file isn't
150
+ // faux-bolded again; fontWeight still applies when no host font is bundled and the system font is used.
151
+ val highlightWeight = Typography.headerXsSemibold.fontWeight
152
+ val highlightFontFamily = getFontFamily(AppTheme.current.font, highlightWeight)
153
+ return remember(description, highlightText, highlightFontFamily) {
154
+ highlightDescription(
155
+ description,
156
+ highlightText,
157
+ SpanStyle(
158
+ fontFamily = highlightFontFamily,
159
+ fontWeight = highlightWeight,
160
+ fontSynthesis = FontSynthesis.None,
161
+ ),
162
+ )
163
+ }
164
+ }
165
+
160
166
  // Whole-word matches only; the longest keyword wins when keywords overlap (RN parity).
161
167
  private fun highlightDescription(
162
168
  description: String,
@@ -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.duoModalMaxHeight
26
- import vn.momo.kits.layout.duoModalMaxWidth
27
- import vn.momo.kits.layout.getScreenLayout
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 cap on iPhone Duo (the modal bounds, RN Popup/utils.ts); unbounded elsewhere.
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 layout = getScreenLayout()
45
- return if (layout.isIPhoneDuoDevice) layout.duoModalMaxWidth else Dp.Unspecified
42
+ val modal = rememberModalLayout()
43
+ return if (modal.isFoldable) modal.popup.maxWidth else Dp.Unspecified
46
44
  }
47
45
 
48
- // The modal bounds already keep iPhone Duo popups off the edges, so their own side padding goes.
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 (getScreenLayout().isIPhoneDuoDevice) 0.dp else padding
49
+ if (rememberModalLayout().isFoldable) 0.dp else padding
52
50
 
53
- // Tallest a popup gets on iPhone Duo, landscape and the inner display included; null elsewhere.
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 = if (getScreenLayout().isIPhoneDuoDevice) Radius.XL else Radius.L
56
+ internal fun popupRadius(): Dp = rememberModalLayout().popup.radius
63
57
 
64
58
  private fun heightForLines(
65
59
  layout: TextLayoutResult,
@@ -93,6 +87,7 @@ data class PopupNotifyProps(
93
87
  val buttonDirection: PopupActionDirection = PopupActionDirection.ROW,
94
88
  val onIconClose: () -> Unit,
95
89
  val isShowCloseIcon: Boolean = true,
90
+ val highlightText: List<String> = emptyList(),
96
91
  )
97
92
 
98
93
  @Composable
@@ -104,6 +99,7 @@ fun PopupNotify(
104
99
 
105
100
  val density = LocalDensity.current
106
101
  var scrollHeight: Dp by remember { mutableStateOf(0.dp) }
102
+ val description = rememberHighlightDescription(props.description, props.highlightText)
107
103
 
108
104
  LaunchedEffect(layoutResult.value) {
109
105
  if ((layoutResult.value?.lineCount ?: 0) > 3) {
@@ -129,7 +125,7 @@ fun PopupNotify(
129
125
  ) {
130
126
  item {
131
127
  Text(
132
- text = props.description,
128
+ text = description,
133
129
  onTextLayout = { layoutResult.value = it },
134
130
  style = Typography.bodyDefaultRegular
135
131
  )
@@ -140,7 +136,7 @@ fun PopupNotify(
140
136
  { modifier ->
141
137
  Box(modifier = modifier) {
142
138
  Text(
143
- text = props.description,
139
+ text = description,
144
140
  onTextLayout = { layoutResult.value = it },
145
141
  style = Typography.bodyDefaultRegular
146
142
  )
@@ -152,19 +148,21 @@ fun PopupNotify(
152
148
  callback?.invoke()
153
149
  }
154
150
 
155
- val maxHeight = popupMaxHeight()
156
- val bodyScrollState = rememberScrollState()
157
- val horizontalPadding = popupHorizontalPadding(12.dp)
158
- val shape = RoundedCornerShape(popupRadius())
151
+ val popup = rememberModalLayout().popup
152
+ val maxHeight = popup.maxHeight
153
+ val descriptionScrollState = rememberScrollState()
154
+ val shape = RoundedCornerShape(popup.radius)
159
155
 
160
156
  Box(
161
- Modifier.setAutomationId("popup_notify"), contentAlignment = Alignment.TopEnd
157
+ Modifier
158
+ .widthIn(min = popup.minWidth, max = popup.maxWidth)
159
+ .fillMaxWidth()
160
+ .setAutomationId("popup_notify"),
161
+ contentAlignment = Alignment.TopEnd
162
162
  ) {
163
163
  Column(
164
164
  modifier = Modifier
165
- .widthIn(max = popupMaxWidth())
166
165
  .fillMaxWidth()
167
- .padding(horizontal = horizontalPadding)
168
166
  .clip(shape)
169
167
  .background(AppTheme.current.colors.background.surface, shape)
170
168
  .conditional(IsShowBaseLineDebug) {
@@ -174,37 +172,56 @@ fun PopupNotify(
174
172
  heightIn(max = maxHeight ?: Dp.Unspecified)
175
173
  }
176
174
  ) {
177
- // scrolls when iPhone Duo landscape is too short; actions stay visible
175
+ if(props.image.isNotEmpty()) {
176
+ Image(
177
+ source = props.image,
178
+ modifier = Modifier.fillMaxWidth().aspectRatio(1.777f),
179
+ options = Options(alignment = Alignment.Center)
180
+ )
181
+ }
182
+
183
+ // with a max height only the description scrolls; image, title and actions stay
178
184
  Column(
179
- Modifier.conditional(maxHeight != null) {
180
- weight(1f, fill = false).verticalScroll(bodyScrollState)
181
- }
185
+ modifier = Modifier
186
+ .conditional(maxHeight != null) { weight(1f, fill = false) }
187
+ .padding(Spacing.XL)
182
188
  ) {
183
- if(props.image.isNotEmpty()) {
184
- Image(
185
- source = props.image,
186
- modifier = Modifier.fillMaxWidth().aspectRatio(1.777f),
187
- options = Options(alignment = Alignment.Center)
188
- )
189
- }
190
-
191
- Column(modifier = Modifier.padding(Spacing.XL)) {
192
- Text(
193
- style = Typography.headerDefaultBold,
194
- maxLines = 2,
195
- text = props.title,
196
- modifier = Modifier.setAutomationId("title_popup_permission")
197
- )
198
- content(Modifier.padding(top = Spacing.S))
199
- if (props.error.isNotEmpty()) {
189
+ Text(
190
+ style = Typography.headerDefaultBold,
191
+ maxLines = 2,
192
+ text = props.title,
193
+ modifier = Modifier
194
+ .conditional(props.isShowCloseIcon && props.image.isEmpty()) {
195
+ padding(end = MODAL_ICON_BUTTON_SIZE + Spacing.M - Spacing.XL)
196
+ }
197
+ .setAutomationId("title_popup_permission")
198
+ )
199
+ if (maxHeight != null) {
200
+ // still capped at ~8.5 lines, then shrinks further when the popup reaches its max height
201
+ Box(
202
+ Modifier
203
+ .padding(top = Spacing.S)
204
+ .weight(1f, fill = false)
205
+ .conditional(isScroll) { heightIn(max = scrollHeight) }
206
+ .verticalScroll(descriptionScrollState)
207
+ ) {
200
208
  Text(
201
- text = LocalLocalize.current.translate("errorCode") + props.error,
202
- style = Typography.descriptionXsRegular,
203
- color = AppTheme.current.colors.text.hint,
204
- maxLines = 1,
205
- modifier = Modifier.padding(top = Spacing.S)
209
+ text = props.description,
210
+ onTextLayout = { layoutResult.value = it },
211
+ style = Typography.bodyDefaultRegular
206
212
  )
207
213
  }
214
+ } else {
215
+ content(Modifier.padding(top = Spacing.S))
216
+ }
217
+ if (props.error.isNotEmpty()) {
218
+ Text(
219
+ text = LocalLocalize.current.translate("errorCode") + props.error,
220
+ style = Typography.descriptionXsRegular,
221
+ color = AppTheme.current.colors.text.hint,
222
+ maxLines = 1,
223
+ modifier = Modifier.padding(top = Spacing.S)
224
+ )
208
225
  }
209
226
  }
210
227
 
@@ -218,37 +235,13 @@ fun PopupNotify(
218
235
  }
219
236
  }
220
237
 
221
- if(props.isShowCloseIcon) {
222
- Box(
223
- Modifier
224
- .width(22.dp)
225
- .height(22.dp)
226
- // centered on the card's top right corner
227
- .offset(x = 11.dp - horizontalPadding, y = (-11).dp)
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
- }
238
+ if (props.isShowCloseIcon) {
239
+ ModalIconButton(
240
+ icon = "navigation_close",
241
+ automationId = "ic_popup_close",
242
+ onClick = { onClose { props.onIconClose() } },
243
+ modifier = Modifier.padding(top = Spacing.M, end = Spacing.M),
244
+ )
252
245
  }
253
246
  }
254
247
  }
@@ -26,9 +26,9 @@ import kotlin.math.roundToInt
26
26
  private val THUMB_SIZE = 20.dp
27
27
  private val THUMB_BORDER = 3.dp
28
28
  private val TRACK_HEIGHT = 4.dp
29
- private val LABEL_PAD_H get() = Spacing.XS
30
- private val LABEL_PAD_V get() = Spacing.XXS
31
- private val LABEL_GAP get() = Spacing.XS // space between label and thumb top
29
+ private val LABEL_PAD_H = Spacing.XS
30
+ private val LABEL_PAD_V = Spacing.XXS
31
+ private val LABEL_GAP = Spacing.XS // space between label and thumb top
32
32
 
33
33
 
34
34
  private fun clamp(value: Float, min: Float, max: Float): Float =
@@ -68,7 +68,7 @@ class TooltipState {
68
68
  fun rememberTooltipState(): TooltipState {
69
69
  return remember { TooltipState() }
70
70
  }
71
- private val TOOLTIP_OFFSET get() = Spacing.S
71
+ private val TOOLTIP_OFFSET = Spacing.S
72
72
  private val ARROW_SIZE = 6.dp
73
73
  private class TooltipPositionProvider(
74
74
  private val placement: TooltipPlacement,
@@ -1,19 +1,16 @@
1
1
  package vn.momo.kits.const
2
2
 
3
- import androidx.compose.ui.unit.Dp
4
3
  import androidx.compose.ui.unit.dp
5
4
 
6
- private fun spacing(value: Int): Dp = (value / KitSizeScale.rate).dp
7
-
8
5
  object Spacing {
9
- val XXS: Dp get() = spacing(2)
10
- val XS: Dp get() = spacing(4)
11
- val S: Dp get() = spacing(8)
12
- val M: Dp get() = spacing(12)
13
- val L: Dp get() = spacing(16)
14
- val XL: Dp get() = spacing(24)
15
- val XXL: Dp get() = spacing(32)
16
- val Size3XL: Dp get() = spacing(48)
17
- val Size4XL: Dp get() = spacing(56)
18
- val Size5XL: Dp get() = spacing(64)
19
- }
6
+ val XXS = 2.dp
7
+ val XS = 4.dp
8
+ val S = 8.dp
9
+ val M = 12.dp
10
+ val L = 16.dp
11
+ val XL = 24.dp
12
+ val XXL = 32.dp
13
+ val Size3XL = 48.dp
14
+ val Size4XL = 56.dp
15
+ val Size5XL = 64.dp
16
+ }
@@ -27,12 +27,11 @@ fun scaleSize(size: Float): Float {
27
27
  }
28
28
  val scaleSizeMaxRate: Float = MAX_FONT_SCALE
29
29
  // Short side, not width: landscape must not inflate every font.
30
- val sizeScale = LocalSizeScale.current
31
- val deviceWidth = getScreenDimensions().let { minOf(it.width, it.height) } * sizeScale
30
+ val deviceWidth = getScreenDimensions().let { minOf(it.width, it.height) }
32
31
  val deviceScale = deviceWidth / DEFAULT_SCREEN_SIZE
33
32
 
34
33
  val density = LocalDensity.current
35
- val fontScale = density.fontScale * sizeScale
34
+ val fontScale = density.fontScale
36
35
 
37
36
  var fontSizeScaleDevice = size
38
37
  var fontSizeScaleOS = size
@@ -59,7 +58,7 @@ fun scaleSize(size: TextUnit): TextUnit {
59
58
  val density = LocalDensity.current
60
59
 
61
60
  val scaled = scaleSize(size.value)
62
- val spValue = scaled / (density.fontScale * LocalSizeScale.current)
61
+ val spValue = scaled / density.fontScale
63
62
 
64
63
  return TextUnit(value = spValue, type = TextUnitType.Sp)
65
64
  }
@@ -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
+ }