@momo-kits/native-kits 0.300.7 → 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/build.gradle.kts +13 -0
- package/compose/build.gradle.kts +195 -0
- package/compose/build.gradle.kts.backup +195 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
- 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 +1067 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -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 +315 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +212 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +422 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +244 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
- 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 +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +387 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HelpCenterRequest.kt +33 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/ToolkitRequests.kt +38 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +135 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
- 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 +39 -0
- package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt +53 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +31 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -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 +143 -0
- package/gradle/libs.versions.toml +66 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +24 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- 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/README.md +120 -0
- 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 +63 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
package vn.momo.kits.utils
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.*
|
|
4
|
+
import org.jetbrains.compose.resources.DrawableResource
|
|
5
|
+
import org.jetbrains.compose.resources.InternalResourceApi
|
|
6
|
+
import org.jetbrains.compose.resources.ResourceItem
|
|
7
|
+
import org.jetbrains.compose.resources.readResourceBytes
|
|
8
|
+
@OptIn(InternalResourceApi::class)
|
|
9
|
+
@Composable
|
|
10
|
+
internal fun readJson(name: String): String {
|
|
11
|
+
val path = name.plus(".json")
|
|
12
|
+
val candidatePaths = listOf(
|
|
13
|
+
path,
|
|
14
|
+
"composeResources/vn.momo.compose.resources/$path",
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
val jsonContent by rememberState(path, { "" }) {
|
|
18
|
+
val cached = resourceCache.getOrPut(path) {
|
|
19
|
+
var content = ""
|
|
20
|
+
for (candidate in candidatePaths) {
|
|
21
|
+
try {
|
|
22
|
+
content = readResourceBytes(candidate).decodeToString()
|
|
23
|
+
break
|
|
24
|
+
} catch (_: Exception) {
|
|
25
|
+
// try next candidate
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
ResourceCache.JSON(content)
|
|
29
|
+
} as ResourceCache.JSON
|
|
30
|
+
|
|
31
|
+
cached.json
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return jsonContent
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
private val resourceCache = mutableMapOf<String, ResourceCache>()
|
|
39
|
+
|
|
40
|
+
private sealed interface ResourceCache {
|
|
41
|
+
class JSON(val json: String) : ResourceCache
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Composable
|
|
45
|
+
fun <T> rememberState(
|
|
46
|
+
key: Any,
|
|
47
|
+
getDefault: () -> T,
|
|
48
|
+
block: suspend () -> T
|
|
49
|
+
): MutableState<T> {
|
|
50
|
+
val state = remember(key) { mutableStateOf(getDefault()) }
|
|
51
|
+
LaunchedEffect(key) {
|
|
52
|
+
state.value = block()
|
|
53
|
+
}
|
|
54
|
+
return state
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package vn.momo.kits.utils
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import vn.momo.kits.application.LocalComponentInformation
|
|
5
|
+
|
|
6
|
+
@Composable
|
|
7
|
+
internal fun getComponentId(
|
|
8
|
+
componentName: String? = null,
|
|
9
|
+
accessibilityLabel: String? = null,
|
|
10
|
+
): String {
|
|
11
|
+
val componentInformation = LocalComponentInformation.current
|
|
12
|
+
if (accessibilityLabel != null) return accessibilityLabel
|
|
13
|
+
if (componentInformation?.componentId != null) return componentInformation.componentId
|
|
14
|
+
return ""
|
|
15
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
package vn.momo.kits.utils
|
|
2
|
+
|
|
3
|
+
import androidx.compose.foundation.layout.WindowInsets
|
|
4
|
+
import androidx.compose.foundation.layout.WindowInsetsSides
|
|
5
|
+
import androidx.compose.foundation.layout.displayCutout
|
|
6
|
+
import androidx.compose.foundation.layout.only
|
|
7
|
+
import androidx.compose.foundation.layout.union
|
|
8
|
+
import androidx.compose.foundation.layout.windowInsetsPadding
|
|
9
|
+
import androidx.compose.foundation.layout.asPaddingValues
|
|
10
|
+
import androidx.compose.foundation.layout.systemBars
|
|
11
|
+
import androidx.compose.runtime.Composable
|
|
12
|
+
import androidx.compose.ui.Modifier
|
|
13
|
+
import androidx.compose.ui.composed
|
|
14
|
+
import androidx.compose.ui.draw.drawBehind
|
|
15
|
+
import androidx.compose.ui.geometry.Offset
|
|
16
|
+
import androidx.compose.ui.graphics.Color
|
|
17
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
18
|
+
import androidx.compose.ui.unit.Dp
|
|
19
|
+
import androidx.compose.ui.unit.dp
|
|
20
|
+
import androidx.compose.ui.unit.min
|
|
21
|
+
import vn.momo.kits.const.AppNavigationBar
|
|
22
|
+
import vn.momo.kits.const.AppStatusBar
|
|
23
|
+
import vn.momo.kits.platform.getPlatformName
|
|
24
|
+
import kotlin.math.abs
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
internal fun Modifier.bottomBorder(strokeWidth: Dp, color: Color) = composed(
|
|
28
|
+
factory = {
|
|
29
|
+
val density = LocalDensity.current
|
|
30
|
+
val strokeWidthPx = density.run { strokeWidth.toPx() }
|
|
31
|
+
if (strokeWidth > 0.dp) {
|
|
32
|
+
Modifier.drawBehind {
|
|
33
|
+
val width = size.width
|
|
34
|
+
val height = size.height - strokeWidthPx / 2
|
|
35
|
+
|
|
36
|
+
drawLine(
|
|
37
|
+
color = color,
|
|
38
|
+
start = Offset(x = 0f, y = height),
|
|
39
|
+
end = Offset(x = width, y = height),
|
|
40
|
+
strokeWidth = strokeWidthPx
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
Modifier
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
fun <T> Boolean.ifTrue(trueCase: T, falseCase: T): T = if (this) trueCase else falseCase
|
|
50
|
+
fun <T> String.ifNotNull(trueCase: T, falseCase: T): T = if (this.isBlank()) falseCase else trueCase
|
|
51
|
+
|
|
52
|
+
fun formatNumberToMoney(number: Long, currency: String = "đ"): String {
|
|
53
|
+
if (number == 0L) {
|
|
54
|
+
return "0$currency"
|
|
55
|
+
}
|
|
56
|
+
val array = mutableListOf<Char>()
|
|
57
|
+
var result = ""
|
|
58
|
+
var isNegative = false
|
|
59
|
+
|
|
60
|
+
if (number < 0) {
|
|
61
|
+
isNegative = true
|
|
62
|
+
}
|
|
63
|
+
val numberString = abs(number).toString()
|
|
64
|
+
if (numberString.length < 3) {
|
|
65
|
+
return numberString + currency
|
|
66
|
+
}
|
|
67
|
+
var count = 0
|
|
68
|
+
for (i in numberString.length - 1 downTo 0) {
|
|
69
|
+
count += 1
|
|
70
|
+
array.add(numberString[i])
|
|
71
|
+
if (count == 3 && i >= 1) {
|
|
72
|
+
array.add('.')
|
|
73
|
+
count = 0
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
for (i in array.size - 1 downTo 0) {
|
|
78
|
+
result += array[i]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (isNegative) {
|
|
82
|
+
result = "-$result"
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return result + currency
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Composable
|
|
89
|
+
fun getAppStatusBarHeight(): Dp {
|
|
90
|
+
return if (AppStatusBar.current == 0.dp) {
|
|
91
|
+
WindowInsets.systemBars.asPaddingValues().calculateTopPadding()
|
|
92
|
+
} else {
|
|
93
|
+
AppStatusBar.current
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
internal val horizontalSafeAreaInsets: WindowInsets
|
|
98
|
+
@Composable get() = WindowInsets.systemBars.union(WindowInsets.displayCutout).only(WindowInsetsSides.Horizontal)
|
|
99
|
+
|
|
100
|
+
// Left/right safe area like SwiftUI (landscape camera/notch); consumed, so nested StackScreens don't pad twice.
|
|
101
|
+
internal fun Modifier.horizontalSafeAreaPadding(): Modifier = composed {
|
|
102
|
+
windowInsetsPadding(horizontalSafeAreaInsets)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
@Composable
|
|
106
|
+
internal fun getNavigationBarHeight(): Dp {
|
|
107
|
+
return if (AppNavigationBar.current == 0.dp) {
|
|
108
|
+
val systemBottomPadding = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
|
|
109
|
+
if (getPlatformName() == "iOS") {
|
|
110
|
+
min(systemBottomPadding, 21.dp)
|
|
111
|
+
} else {
|
|
112
|
+
systemBottomPadding
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
AppNavigationBar.current
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package vn.momo.kits.application
|
|
2
|
+
|
|
3
|
+
import kotlinx.serialization.json.JsonObject
|
|
4
|
+
import kotlin.test.AfterTest
|
|
5
|
+
import kotlin.test.Test
|
|
6
|
+
import kotlin.test.assertEquals
|
|
7
|
+
import kotlin.test.assertSame
|
|
8
|
+
|
|
9
|
+
class KitsHostTest {
|
|
10
|
+
@AfterTest
|
|
11
|
+
fun reset() = KitsHost.uninstall()
|
|
12
|
+
|
|
13
|
+
@Test
|
|
14
|
+
fun withoutAnInstallTheBindingDoesNothing() {
|
|
15
|
+
val binding = KitsHost.binding
|
|
16
|
+
binding.dismiss(KitsDismissTarget.Current)
|
|
17
|
+
binding.trackEvent("event", JsonObject(emptyMap()))
|
|
18
|
+
var called = false
|
|
19
|
+
assertSame(KitsRequest.None, binding.getLanguage { called = true })
|
|
20
|
+
assertEquals(false, called)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Test
|
|
24
|
+
fun theLastInstalledBindingIsUsedUntilUninstalled() {
|
|
25
|
+
val first = RecordingBinding()
|
|
26
|
+
val second = RecordingBinding()
|
|
27
|
+
KitsHost.install(first)
|
|
28
|
+
KitsHost.install(second)
|
|
29
|
+
KitsHost.binding.dismiss(KitsDismissTarget.All)
|
|
30
|
+
assertEquals(emptyList(), first.dismissed)
|
|
31
|
+
assertEquals(listOf(KitsDismissTarget.All), second.dismissed)
|
|
32
|
+
KitsHost.uninstall()
|
|
33
|
+
assertSame(NoOpKitsBinding, KitsHost.binding)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private class RecordingBinding : KitsBinding {
|
|
37
|
+
val dismissed = mutableListOf<KitsDismissTarget>()
|
|
38
|
+
override fun dismiss(target: KitsDismissTarget) {
|
|
39
|
+
dismissed += target
|
|
40
|
+
}
|
|
41
|
+
override fun trackEvent(eventName: String, attributes: JsonObject) = Unit
|
|
42
|
+
override fun getLanguage(callback: (String) -> Unit): KitsRequest = KitsRequest.None
|
|
43
|
+
}
|
|
44
|
+
}
|
package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/HelpCenterRequestTest.kt
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// File: HelpCenterRequestTest.kt
|
|
2
|
+
// Created At: 2026-10-19 +07:00
|
|
3
|
+
// Created By: AI | AI Agent: Codex | Model: GPT-6
|
|
4
|
+
package vn.momo.kits.navigation.component
|
|
5
|
+
|
|
6
|
+
import kotlinx.serialization.json.JsonObject
|
|
7
|
+
import kotlinx.serialization.json.JsonPrimitive
|
|
8
|
+
import vn.momo.kits.application.MiniAppContext
|
|
9
|
+
import kotlin.test.Test
|
|
10
|
+
import kotlin.test.assertEquals
|
|
11
|
+
import kotlin.test.assertNull
|
|
12
|
+
|
|
13
|
+
class HelpCenterRequestTest {
|
|
14
|
+
@Test
|
|
15
|
+
fun preservesApplicationIdentityAndLocalizedObjects() {
|
|
16
|
+
val context = MiniAppContext(
|
|
17
|
+
appId = "app-id",
|
|
18
|
+
appCode = "app-code",
|
|
19
|
+
appIcon = "app-icon",
|
|
20
|
+
appName = mapOf("vi" to "Tên ứng dụng", "en" to "App name"),
|
|
21
|
+
description = mapOf("vi" to "Mô tả", "en" to "Description"),
|
|
22
|
+
)
|
|
23
|
+
val request = context.helpCenterRequest()
|
|
24
|
+
assertEquals(context.appId, request.appId)
|
|
25
|
+
assertEquals(context.appCode, request.code)
|
|
26
|
+
assertEquals(context.appIcon, request.icon)
|
|
27
|
+
assertEquals(JsonObject(mapOf("vi" to JsonPrimitive("Tên ứng dụng"),
|
|
28
|
+
"en" to JsonPrimitive("App name"))), request.name)
|
|
29
|
+
assertEquals(JsonObject(mapOf("vi" to JsonPrimitive("Mô tả"),
|
|
30
|
+
"en" to JsonPrimitive("Description"))), request.description)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Test
|
|
34
|
+
fun preservesPlainStringsAndAbsentValues() {
|
|
35
|
+
val request = MiniAppContext(appName = "App name").helpCenterRequest()
|
|
36
|
+
assertEquals(JsonPrimitive("App name"), request.name)
|
|
37
|
+
assertNull(request.description)
|
|
38
|
+
}
|
|
39
|
+
}
|
package/compose/src/commonTest/kotlin/vn/momo/kits/navigation/component/ToolkitRequestsTest.kt
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// File: ToolkitRequestsTest.kt
|
|
2
|
+
// Created At: 2026-10-12 +07:00 | Created By: AI | AI Agent: Codex | Model: GPT-6
|
|
3
|
+
package vn.momo.kits.navigation.component
|
|
4
|
+
|
|
5
|
+
import kotlin.test.Test
|
|
6
|
+
import kotlin.test.assertEquals
|
|
7
|
+
import vn.momo.kits.application.KitsRequest
|
|
8
|
+
|
|
9
|
+
class ToolkitRequestsTest {
|
|
10
|
+
@Test
|
|
11
|
+
fun closingCancelsPendingRequestsAndSuppressesLateCallbacks() {
|
|
12
|
+
val owner = ToolkitRequests()
|
|
13
|
+
val handle = Handle()
|
|
14
|
+
var callback: (Boolean) -> Unit = {}
|
|
15
|
+
var results = 0
|
|
16
|
+
owner.launch<Boolean>({ callback = it; handle }) { results++ }
|
|
17
|
+
owner.close()
|
|
18
|
+
owner.close()
|
|
19
|
+
callback(true)
|
|
20
|
+
assertEquals(1, handle.cancellations)
|
|
21
|
+
assertEquals(0, results)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@Test
|
|
25
|
+
fun completedRequestsAreReleasedAndClosedOwnersNeverStartNewRequests() {
|
|
26
|
+
val owner = ToolkitRequests()
|
|
27
|
+
val handle = Handle()
|
|
28
|
+
var starts = 0
|
|
29
|
+
var results = 0
|
|
30
|
+
owner.launch<Boolean>({ callback -> starts++; callback(false); handle }) { results++ }
|
|
31
|
+
owner.close()
|
|
32
|
+
owner.launch<Boolean>({ starts++; handle }) { results++ }
|
|
33
|
+
assertEquals(0, handle.cancellations)
|
|
34
|
+
assertEquals(1, starts)
|
|
35
|
+
assertEquals(1, results)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Test
|
|
39
|
+
fun subscriptionsStayOpenUntilTheOwnerCloses() {
|
|
40
|
+
val owner = ToolkitRequests()
|
|
41
|
+
val handle = Handle()
|
|
42
|
+
owner.observe { handle }
|
|
43
|
+
assertEquals(0, handle.cancellations)
|
|
44
|
+
owner.close()
|
|
45
|
+
owner.observe { handle }
|
|
46
|
+
assertEquals(1, handle.cancellations)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private class Handle : KitsRequest {
|
|
50
|
+
var cancellations = 0
|
|
51
|
+
override fun cancel() { cancellations++ }
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
@file:OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
|
|
2
|
+
|
|
3
|
+
package vn.momo.kits.const
|
|
4
|
+
|
|
5
|
+
import androidx.compose.runtime.Composable
|
|
6
|
+
import androidx.compose.runtime.remember
|
|
7
|
+
import androidx.compose.ui.text.font.FontFamily
|
|
8
|
+
import androidx.compose.ui.text.font.FontWeight
|
|
9
|
+
import androidx.compose.ui.text.platform.Font
|
|
10
|
+
import kotlinx.cinterop.ExperimentalForeignApi
|
|
11
|
+
import kotlinx.cinterop.addressOf
|
|
12
|
+
import kotlinx.cinterop.usePinned
|
|
13
|
+
import platform.Foundation.NSBundle
|
|
14
|
+
import platform.Foundation.NSData
|
|
15
|
+
import platform.Foundation.dataWithContentsOfFile
|
|
16
|
+
import platform.posix.memcpy
|
|
17
|
+
|
|
18
|
+
@Composable
|
|
19
|
+
internal actual fun hostFontFamily(fileName: String, weight: FontWeight): FontFamily? = remember(fileName, weight) {
|
|
20
|
+
val name = fileName.substringBeforeLast('.')
|
|
21
|
+
val ext = fileName.substringAfterLast('.', "")
|
|
22
|
+
// Host fonts sit loose at the bundle root, not in compose-resources.
|
|
23
|
+
val path = NSBundle.mainBundle.pathForResource(name, ext) ?: return@remember null
|
|
24
|
+
FontFamily(
|
|
25
|
+
Font(
|
|
26
|
+
identity = fileName,
|
|
27
|
+
getData = {
|
|
28
|
+
NSData.dataWithContentsOfFile(path)?.toByteArray() ?: ByteArray(0)
|
|
29
|
+
},
|
|
30
|
+
weight = weight,
|
|
31
|
+
),
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@OptIn(ExperimentalForeignApi::class)
|
|
36
|
+
private fun NSData.toByteArray(): ByteArray {
|
|
37
|
+
val size = length.toInt()
|
|
38
|
+
if (size == 0) return ByteArray(0)
|
|
39
|
+
return ByteArray(size).apply {
|
|
40
|
+
usePinned { pinned -> memcpy(pinned.addressOf(0), bytes, length) }
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.DisposableEffect
|
|
5
|
+
import androidx.compose.runtime.remember
|
|
6
|
+
import androidx.navigationevent.NavigationEvent
|
|
7
|
+
import androidx.navigationevent.NavigationEventDispatcher
|
|
8
|
+
import androidx.navigationevent.NavigationEventInput
|
|
9
|
+
|
|
10
|
+
@Suppress("ParamsComparedByRef")
|
|
11
|
+
@Composable
|
|
12
|
+
internal fun AttachHostBackGesture(dispatcher: NavigationEventDispatcher, navigator: Navigator) {
|
|
13
|
+
val input = remember(dispatcher) { HostNavigationEventInput() }
|
|
14
|
+
val target = remember(input, navigator) {
|
|
15
|
+
object : HostBackTarget {
|
|
16
|
+
override fun canPop() = navigator.canPop()
|
|
17
|
+
override fun onBack() = navigator.onBackSafe()
|
|
18
|
+
override fun backStarted() = input.backStarted()
|
|
19
|
+
override fun backProgressed(progress: Float) = input.backProgressed(progress)
|
|
20
|
+
override fun backCompleted() = input.backCompleted()
|
|
21
|
+
override fun backCancelled() = input.backCancelled()
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
DisposableEffect(dispatcher, target) {
|
|
26
|
+
dispatcher.addInput(input)
|
|
27
|
+
HostBackGestureBridge.attach(target)
|
|
28
|
+
onDispose {
|
|
29
|
+
HostBackGestureBridge.detach(target)
|
|
30
|
+
dispatcher.removeInput(input)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
internal class HostNavigationEventInput : NavigationEventInput() {
|
|
36
|
+
fun backStarted() = dispatchOnBackStarted(NavigationEvent(swipeEdge = NavigationEvent.EDGE_LEFT))
|
|
37
|
+
|
|
38
|
+
fun backProgressed(progress: Float) = dispatchOnBackProgressed(
|
|
39
|
+
NavigationEvent(swipeEdge = NavigationEvent.EDGE_LEFT, progress = progress)
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
fun backCancelled() = dispatchOnBackCancelled()
|
|
43
|
+
|
|
44
|
+
fun backCompleted() = dispatchOnBackCompleted()
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
package vn.momo.kits.navigation
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.DisposableEffect
|
|
5
|
+
import platform.Foundation.NSNotification
|
|
6
|
+
import platform.Foundation.NSNotificationCenter
|
|
7
|
+
import platform.Foundation.NSOperationQueue
|
|
8
|
+
import platform.darwin.NSObjectProtocol
|
|
9
|
+
|
|
10
|
+
private const val STATUS_BAR_TAPPED_NOTIFICATION = "statusBarSelected"
|
|
11
|
+
|
|
12
|
+
@Composable
|
|
13
|
+
internal actual fun RegisterScrollToTop(callback: (() -> Unit)?) {
|
|
14
|
+
val binding = LocalKitsBinding.current
|
|
15
|
+
DisposableEffect(callback, binding) {
|
|
16
|
+
val token: NSObjectProtocol? = if (callback != null) {
|
|
17
|
+
NSNotificationCenter.defaultCenter.addObserverForName(
|
|
18
|
+
name = STATUS_BAR_TAPPED_NOTIFICATION,
|
|
19
|
+
`object` = null,
|
|
20
|
+
queue = NSOperationQueue.mainQueue,
|
|
21
|
+
) { _: NSNotification? ->
|
|
22
|
+
runCatching { callback() }.onFailure {
|
|
23
|
+
binding?.logError("[ScrollToTop] callback failed")
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
} else null
|
|
27
|
+
onDispose {
|
|
28
|
+
token?.let { NSNotificationCenter.defaultCenter.removeObserver(it) }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package vn.momo.kits.platform
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.LaunchedEffect
|
|
5
|
+
import androidx.compose.runtime.State
|
|
6
|
+
import androidx.compose.runtime.mutableStateOf
|
|
7
|
+
import androidx.compose.runtime.remember
|
|
8
|
+
import androidx.compose.ui.InternalComposeUiApi
|
|
9
|
+
import androidx.compose.ui.backhandler.LocalCompatNavigationEventDispatcherOwner
|
|
10
|
+
import androidx.navigationevent.NavigationEventTransitionState
|
|
11
|
+
import vn.momo.kits.navigation.HostBackGestureBridge
|
|
12
|
+
|
|
13
|
+
// transitionState is a passive observer; its progress is touch.x / view width.
|
|
14
|
+
@OptIn(InternalComposeUiApi::class)
|
|
15
|
+
@Composable
|
|
16
|
+
actual fun rememberBackGestureProgress(): State<Float?> {
|
|
17
|
+
val dispatcher = LocalCompatNavigationEventDispatcherOwner.current?.navigationEventDispatcher
|
|
18
|
+
val progress = remember { mutableStateOf<Float?>(null) }
|
|
19
|
+
|
|
20
|
+
LaunchedEffect(dispatcher) {
|
|
21
|
+
if (dispatcher == null) {
|
|
22
|
+
progress.value = null
|
|
23
|
+
return@LaunchedEffect
|
|
24
|
+
}
|
|
25
|
+
dispatcher.transitionState.collect { state ->
|
|
26
|
+
progress.value = (state as? NavigationEventTransitionState.InProgress)
|
|
27
|
+
?.takeIf { it.direction == NavigationEventTransitionState.TRANSITIONING_BACK }
|
|
28
|
+
?.latestEvent
|
|
29
|
+
?.progress
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return progress
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
actual fun reportFloatingArrowBack(shouldUse: Boolean) {
|
|
37
|
+
HostBackGestureBridge.shouldUseFloatingArrowBack = shouldUse
|
|
38
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
package vn.momo.kits.platform
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.CompositionLocalProvider
|
|
5
|
+
import androidx.compose.runtime.DisposableEffect
|
|
6
|
+
import androidx.compose.runtime.mutableStateOf
|
|
7
|
+
import androidx.compose.runtime.remember
|
|
8
|
+
import androidx.compose.ui.platform.LocalDensity
|
|
9
|
+
import androidx.compose.ui.unit.Density
|
|
10
|
+
import kotlinx.cinterop.ExperimentalForeignApi
|
|
11
|
+
import kotlinx.cinterop.ObjCAction
|
|
12
|
+
import platform.Foundation.NSNotification
|
|
13
|
+
import platform.Foundation.NSNotificationCenter
|
|
14
|
+
import platform.Foundation.NSSelectorFromString
|
|
15
|
+
import platform.UIKit.UIContentSizeCategoryDidChangeNotification
|
|
16
|
+
import platform.UIKit.UIFont
|
|
17
|
+
import platform.UIKit.UIFontTextStyleBody
|
|
18
|
+
import platform.darwin.NSObject
|
|
19
|
+
|
|
20
|
+
// Body point size / 17, as in the SwiftUI kit, so both iOS surfaces scale alike.
|
|
21
|
+
private const val DEFAULT_BODY_POINT_SIZE = 17.0
|
|
22
|
+
|
|
23
|
+
private fun currentOsFontScale(): Float {
|
|
24
|
+
return (UIFont.preferredFontForTextStyle(UIFontTextStyleBody).pointSize / DEFAULT_BODY_POINT_SIZE).toFloat()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Compose MP iOS reads fontScale only once, at ComposeUIViewController creation.
|
|
28
|
+
@OptIn(ExperimentalForeignApi::class)
|
|
29
|
+
@Composable
|
|
30
|
+
actual fun ProvideOsFontScale(content: @Composable () -> Unit) {
|
|
31
|
+
val osFontScale = remember { mutableStateOf(currentOsFontScale()) }
|
|
32
|
+
|
|
33
|
+
val listener = remember {
|
|
34
|
+
object : NSObject() {
|
|
35
|
+
@Suppress("unused")
|
|
36
|
+
@ObjCAction
|
|
37
|
+
fun contentSizeChanged(arg: NSNotification) {
|
|
38
|
+
osFontScale.value = currentOsFontScale()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
DisposableEffect(Unit) {
|
|
44
|
+
NSNotificationCenter.defaultCenter.addObserver(
|
|
45
|
+
observer = listener,
|
|
46
|
+
selector = NSSelectorFromString(listener::contentSizeChanged.name + ":"),
|
|
47
|
+
name = UIContentSizeCategoryDidChangeNotification,
|
|
48
|
+
`object` = null,
|
|
49
|
+
)
|
|
50
|
+
onDispose {
|
|
51
|
+
NSNotificationCenter.defaultCenter.removeObserver(
|
|
52
|
+
observer = listener,
|
|
53
|
+
name = UIContentSizeCategoryDidChangeNotification,
|
|
54
|
+
`object` = null,
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
val density = LocalDensity.current
|
|
60
|
+
CompositionLocalProvider(
|
|
61
|
+
LocalDensity provides Density(density.density, osFontScale.value),
|
|
62
|
+
) {
|
|
63
|
+
content()
|
|
64
|
+
}
|
|
65
|
+
}
|