@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
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package vn.momo.kits.platform
|
|
2
|
+
|
|
3
|
+
import androidx.compose.runtime.Composable
|
|
4
|
+
import androidx.compose.runtime.DisposableEffect
|
|
5
|
+
import androidx.compose.runtime.mutableStateOf
|
|
6
|
+
import androidx.compose.runtime.remember
|
|
7
|
+
import kotlinx.cinterop.ExperimentalForeignApi
|
|
8
|
+
import kotlinx.cinterop.ObjCAction
|
|
9
|
+
import platform.Foundation.NSNotification
|
|
10
|
+
import platform.Foundation.NSNotificationCenter
|
|
11
|
+
import platform.Foundation.NSSelectorFromString
|
|
12
|
+
import platform.UIKit.UIAccessibilityIsReduceMotionEnabled
|
|
13
|
+
import platform.UIKit.UIAccessibilityReduceMotionStatusDidChangeNotification
|
|
14
|
+
import platform.darwin.NSObject
|
|
15
|
+
|
|
16
|
+
@OptIn(ExperimentalForeignApi::class)
|
|
17
|
+
@Composable
|
|
18
|
+
actual fun rememberReduceMotion(): Boolean {
|
|
19
|
+
val reduceMotion = remember { mutableStateOf(UIAccessibilityIsReduceMotionEnabled()) }
|
|
20
|
+
|
|
21
|
+
val listener = remember {
|
|
22
|
+
object : NSObject() {
|
|
23
|
+
@Suppress("unused")
|
|
24
|
+
@ObjCAction
|
|
25
|
+
fun reduceMotionChanged(arg: NSNotification) {
|
|
26
|
+
reduceMotion.value = UIAccessibilityIsReduceMotionEnabled()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DisposableEffect(Unit) {
|
|
32
|
+
NSNotificationCenter.defaultCenter.addObserver(
|
|
33
|
+
observer = listener,
|
|
34
|
+
selector = NSSelectorFromString(listener::reduceMotionChanged.name + ":"),
|
|
35
|
+
name = UIAccessibilityReduceMotionStatusDidChangeNotification,
|
|
36
|
+
`object` = null,
|
|
37
|
+
)
|
|
38
|
+
onDispose {
|
|
39
|
+
NSNotificationCenter.defaultCenter.removeObserver(
|
|
40
|
+
observer = listener,
|
|
41
|
+
name = UIAccessibilityReduceMotionStatusDidChangeNotification,
|
|
42
|
+
`object` = null,
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return reduceMotion.value
|
|
48
|
+
}
|
|
@@ -57,9 +57,8 @@ private fun regionKind(name: String): Any? {
|
|
|
57
57
|
private val msgSendRegionsOfKindOptions = dlsym(RTLD_DEFAULT, "objc_msgSend")
|
|
58
58
|
?.reinterpret<CFunction<(COpaquePointer?, COpaquePointer?, COpaquePointer?, ULong) -> COpaquePointer?>>()
|
|
59
59
|
|
|
60
|
-
// Apple's foldable check: only a
|
|
61
|
-
//
|
|
62
|
-
// apart from a large iPhone in landscape or a narrowed window.
|
|
60
|
+
// Apple's foldable check: only a hinge reports `.division`, inactive while flat (hence IncludeInactive).
|
|
61
|
+
// Screen size can't tell a foldable from a large iPhone in landscape or a narrowed window.
|
|
63
62
|
@OptIn(ExperimentalForeignApi::class)
|
|
64
63
|
private fun UIView.hasDivisionRegion(): Boolean {
|
|
65
64
|
if (window == null || !respondsToSelector(regionsOfKindOptions)) return false
|
|
@@ -75,10 +74,11 @@ private fun UIView.hasDivisionRegion(): Boolean {
|
|
|
75
74
|
return (regions?.count ?: 0uL) > 0uL
|
|
76
75
|
}
|
|
77
76
|
|
|
77
|
+
// Active regions only: a division region is active while the device is half folded.
|
|
78
78
|
@OptIn(ExperimentalForeignApi::class)
|
|
79
|
-
private fun UIView.
|
|
79
|
+
private fun UIView.activeRegions(kindName: String, target: UIView): List<ReservedRegion> {
|
|
80
80
|
if (window == null || !respondsToSelector(regionsOfKind)) return emptyList()
|
|
81
|
-
val kind = regionKind(
|
|
81
|
+
val kind = regionKind(kindName) ?: return emptyList()
|
|
82
82
|
val regions = when (val result = performSelector(regionsOfKind, withObject = kind)) {
|
|
83
83
|
is List<*> -> result
|
|
84
84
|
is NSArray -> List(result.count.toInt()) { result.objectAtIndex(it.toULong()) }
|
|
@@ -109,7 +109,12 @@ private class ReservedRegionsProbe(
|
|
|
109
109
|
super.layoutSubviews()
|
|
110
110
|
// re-read until found: the window may not report the hinge on the first pass
|
|
111
111
|
if (!isKnownFoldable) isKnownFoldable = hasDivisionRegion()
|
|
112
|
-
val
|
|
112
|
+
val host = superview
|
|
113
|
+
val regions = ReservedRegions(
|
|
114
|
+
occlusion = host?.let { activeRegions("occlusionRegionKind", it) } ?: emptyList(),
|
|
115
|
+
isFoldable = isKnownFoldable,
|
|
116
|
+
division = host?.takeIf { isKnownFoldable }?.let { activeRegions("divisionRegionKind", it).firstOrNull() },
|
|
117
|
+
)
|
|
113
118
|
if (regions != last) {
|
|
114
119
|
last = regions
|
|
115
120
|
onChange(regions)
|
|
@@ -4,7 +4,7 @@ android-minSdk = "24"
|
|
|
4
4
|
android-targetSdk = "36"
|
|
5
5
|
ktor-version = "3.0.0-rc-1"
|
|
6
6
|
coroutines = "1.9.0"
|
|
7
|
-
kotlin = "2.
|
|
7
|
+
kotlin = "2.4.20"
|
|
8
8
|
kSerialize = "1.7.1"
|
|
9
9
|
compose = "1.10.3"
|
|
10
10
|
navigation-multiplatform = "2.9.2"
|
|
@@ -19,7 +19,6 @@ androidx-appcompat = "1.7.0"
|
|
|
19
19
|
material = "1.10.0"
|
|
20
20
|
vanniktechMavenPublish = "0.34.0"
|
|
21
21
|
kits = "0.167.1-duo.1"
|
|
22
|
-
nativemaxapi = "0.3.17"
|
|
23
22
|
gif-image = "0.1.2"
|
|
24
23
|
|
|
25
24
|
[libraries]
|
|
@@ -45,7 +44,6 @@ airbnb-lottie = { group = "com.airbnb.android", name = "lottie-compose", version
|
|
|
45
44
|
# shared.framework). compottie-core pulls only `keight-core` (which declares
|
|
46
45
|
# keight.js.JsAny, so the earlier unlinked-symbol error stays fixed too).
|
|
47
46
|
compottie = { module = "io.github.alexzhirkevich:compottie-core", version.ref = "compottie" }
|
|
48
|
-
native-max-api = { group = "vn.momo.maxapi", name = "NativeMaxApi", version.ref = "nativemaxapi" }
|
|
49
47
|
kits = { module = "vn.momo.kits:kits", version.ref = "kits" }
|
|
50
48
|
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
|
|
51
49
|
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
|
package/gradle.properties
CHANGED
|
@@ -21,8 +21,10 @@ public class MiniAppContext {
|
|
|
21
21
|
// MiniAppContext.userScaleRate / useOSScaleRate, which win per field over DesignSystemKits.
|
|
22
22
|
public var userScaleRate: CGFloat? = nil
|
|
23
23
|
public var useOSScaleRate: Bool? = nil
|
|
24
|
+
// Caps the font scale at size × rate, nil means no cap (Compose MiniAppContext.scaleSizeMaxRate).
|
|
25
|
+
public var scaleSizeMaxRate: CGFloat? = nil
|
|
24
26
|
|
|
25
|
-
public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: [String: Any] = [:], toolkitConfig: [String: Any] = [:], providerId: String = "momo", permissions: [[String: Any]] = [], userScaleRate: CGFloat? = nil, useOSScaleRate: Bool? = nil) {
|
|
27
|
+
public init(appId: String, appCode: String, appName: Any? = nil, appIcon: String, description: Any? = nil, support: [String: Any] = [:], toolkitConfig: [String: Any] = [:], providerId: String = "momo", permissions: [[String: Any]] = [], userScaleRate: CGFloat? = nil, useOSScaleRate: Bool? = nil, scaleSizeMaxRate: CGFloat? = nil) {
|
|
26
28
|
self.appId = appId
|
|
27
29
|
self.appCode = appCode
|
|
28
30
|
self.appName = appName
|
|
@@ -34,6 +36,7 @@ public class MiniAppContext {
|
|
|
34
36
|
self.permissions = permissions
|
|
35
37
|
self.userScaleRate = userScaleRate
|
|
36
38
|
self.useOSScaleRate = useOSScaleRate
|
|
39
|
+
self.scaleSizeMaxRate = scaleSizeMaxRate
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -51,12 +54,11 @@ public struct KitConfig: Equatable {
|
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
public class ApplicationEnvironment: ObservableObject {
|
|
54
|
-
//
|
|
57
|
+
// Public so modules outside MoMoUIKits (e.g. the demo pod) can reach the host bridge.
|
|
55
58
|
public let applicationContext: MiniAppContext?
|
|
56
59
|
public let composeApi: KitComposeApi?
|
|
57
60
|
public let config: KitConfig?
|
|
58
61
|
public let maxApi: MaxApi?
|
|
59
|
-
// AI-GENERATED END: expose the host bridge to modules outside MoMoUIKits (e.g. the demo pod)
|
|
60
62
|
|
|
61
63
|
public init(applicationContext: MiniAppContext? = nil, composeApi: KitComposeApi? = nil, config: KitConfig? = nil, maxApi: MaxApi? = nil) {
|
|
62
64
|
self.applicationContext = applicationContext
|
|
@@ -67,7 +69,7 @@ public class ApplicationEnvironment: ObservableObject {
|
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
extension ApplicationEnvironment {
|
|
70
|
-
/// Closes the mini app
|
|
72
|
+
/// Closes the mini app through `composeApi`, else `maxApi` (Compose `maxApi.dismiss`).
|
|
71
73
|
func requestDismiss() {
|
|
72
74
|
if let composeApi {
|
|
73
75
|
composeApi.requestCallback(funcName: "dismiss", params: nil, onResponse: nil)
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// File: ios/Application/DesignSystemKits.swift
|
|
2
|
-
// Created At: 2026-10-02 14:17:29 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-opus-5-5
|
|
6
|
-
|
|
7
|
-
// AI-GENERATED START: app-wide design-system holder mirroring Compose's DesignSystemKits
|
|
8
1
|
import SwiftUI
|
|
9
2
|
|
|
10
3
|
/// Host-owned design-system inputs; mirrors Compose's `DesignSystemKitsConfigs` field for field.
|
|
@@ -27,15 +20,16 @@ public struct DesignSystemKitsConfigs: Equatable {
|
|
|
27
20
|
}
|
|
28
21
|
}
|
|
29
22
|
|
|
30
|
-
///
|
|
31
|
-
///
|
|
32
|
-
/// tracked here. Views re-render on change as long as the subtree got `.momoFontScale()` (`NavigationContainer`
|
|
33
|
-
/// applies it). Swift reserves `init`, so there is no `init(source:)` twin: the host observes and pushes.
|
|
23
|
+
/// Compose's `DesignSystemKits` without `init(source:)` (Swift reserves `init`): the host pushes `setConfigs(_:)` at
|
|
24
|
+
/// startup and on every change. Also tracks Dynamic Type; views re-render only under `.momoFontScale()`.
|
|
34
25
|
public final class DesignSystemKits: ObservableObject {
|
|
35
26
|
public static let shared = DesignSystemKits()
|
|
36
27
|
|
|
37
28
|
@Published private var configs = DesignSystemKitsConfigs()
|
|
38
29
|
@Published public private(set) var osFontScale: CGFloat = DesignSystemKits.currentOsFontScale()
|
|
30
|
+
/// Republished when the window scene resizes (iPhone Duo fold/unfold) so the font scale follows.
|
|
31
|
+
@Published public private(set) var windowShortSide: CGFloat = DesignSystemKits.currentWindowShortSide()
|
|
32
|
+
private var geometryObservations: [ObjectIdentifier: NSKeyValueObservation] = [:]
|
|
39
33
|
|
|
40
34
|
private init() {
|
|
41
35
|
NotificationCenter.default.addObserver(
|
|
@@ -44,6 +38,17 @@ public final class DesignSystemKits: ObservableObject {
|
|
|
44
38
|
name: UIContentSizeCategory.didChangeNotification,
|
|
45
39
|
object: nil
|
|
46
40
|
)
|
|
41
|
+
NotificationCenter.default.addObserver(
|
|
42
|
+
self,
|
|
43
|
+
selector: #selector(sceneDidActivate(_:)),
|
|
44
|
+
name: UIScene.didActivateNotification,
|
|
45
|
+
object: nil
|
|
46
|
+
)
|
|
47
|
+
onMain {
|
|
48
|
+
UIApplication.shared.connectedScenes
|
|
49
|
+
.compactMap { $0 as? UIWindowScene }
|
|
50
|
+
.forEach(self.observeGeometry(of:))
|
|
51
|
+
}
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
public func setConfigs(_ configs: DesignSystemKitsConfigs) {
|
|
@@ -62,7 +67,8 @@ public final class DesignSystemKits: ObservableObject {
|
|
|
62
67
|
FontScale(
|
|
63
68
|
userScaleRate: configs.userScaleRate,
|
|
64
69
|
useOSScaleRate: configs.useOSScaleRate,
|
|
65
|
-
osFontScale: osFontScale
|
|
70
|
+
osFontScale: osFontScale,
|
|
71
|
+
windowShortSide: windowShortSide
|
|
66
72
|
)
|
|
67
73
|
}
|
|
68
74
|
|
|
@@ -72,6 +78,47 @@ public final class DesignSystemKits: ObservableObject {
|
|
|
72
78
|
osFontScale = next
|
|
73
79
|
}
|
|
74
80
|
|
|
81
|
+
@objc private func sceneDidActivate(_ notification: Notification) {
|
|
82
|
+
guard let scene = notification.object as? UIWindowScene else { return }
|
|
83
|
+
observeGeometry(of: scene)
|
|
84
|
+
refreshWindowShortSide()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private func observeGeometry(of scene: UIWindowScene) {
|
|
88
|
+
guard #available(iOS 16.0, *) else { return }
|
|
89
|
+
let key = ObjectIdentifier(scene)
|
|
90
|
+
guard geometryObservations[key] == nil else { return }
|
|
91
|
+
geometryObservations[key] = scene.observe(\.effectiveGeometry, options: [.new]) { [weak self] _, _ in
|
|
92
|
+
// The window is resized after the scene geometry, so read it on the next turn.
|
|
93
|
+
DispatchQueue.main.async { self?.refreshWindowShortSide() }
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private func refreshWindowShortSide() {
|
|
98
|
+
let next = Self.currentWindowShortSide()
|
|
99
|
+
guard next > 0, next != windowShortSide else { return }
|
|
100
|
+
windowShortSide = next
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// UIScreen.main stays on one display on iPhone Duo, so measure the foreground window instead.
|
|
104
|
+
static func currentWindowShortSide() -> CGFloat {
|
|
105
|
+
guard Thread.isMainThread else {
|
|
106
|
+
return min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
|
|
107
|
+
}
|
|
108
|
+
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
|
|
109
|
+
let scene = scenes.first { $0.activationState == .foregroundActive } ?? scenes.first
|
|
110
|
+
let window = scene?.windows.first { $0.isKeyWindow } ?? scene?.windows.first
|
|
111
|
+
let size: CGSize
|
|
112
|
+
if let window, window.bounds.width > 0 {
|
|
113
|
+
size = window.bounds.size
|
|
114
|
+
} else if let scene {
|
|
115
|
+
size = scene.coordinateSpace.bounds.size
|
|
116
|
+
} else {
|
|
117
|
+
size = UIScreen.main.bounds.size
|
|
118
|
+
}
|
|
119
|
+
return min(size.width, size.height)
|
|
120
|
+
}
|
|
121
|
+
|
|
75
122
|
/// Same factor Compose's iOS `ProvideOsFontScale` derives from
|
|
76
123
|
/// `UIFont.preferredFont(forTextStyle: .body).pointSize / 17`, so both iOS surfaces scale alike.
|
|
77
124
|
static func currentOsFontScale() -> CGFloat {
|
|
@@ -97,4 +144,3 @@ public extension EnvironmentValues {
|
|
|
97
144
|
set { self[DesignSystemKitsConfigsKey.self] = newValue }
|
|
98
145
|
}
|
|
99
146
|
}
|
|
100
|
-
// AI-GENERATED END: app-wide design-system holder mirroring Compose's DesignSystemKits
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// File: ios/Application/DesignSystemKitsPayload.swift
|
|
2
|
-
// Created At: 2026-10-02 15:40:00 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-opus-5-5
|
|
6
|
-
|
|
7
|
-
// AI-GENERATED START: JSON entry point for hosts that can't share Swift types with the kit
|
|
8
1
|
import Foundation
|
|
9
2
|
|
|
10
3
|
public extension DesignSystemKits {
|
|
@@ -65,4 +58,3 @@ private struct TrustBannerPayload: Decodable {
|
|
|
65
58
|
)
|
|
66
59
|
}
|
|
67
60
|
}
|
|
68
|
-
// AI-GENERATED END: JSON entry point for hosts that can't share Swift types with the kit
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// File: ios/Application/LanguageSource.swift
|
|
2
|
-
// Created At: 2026-07-29 10:00:00 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-opus-5[1m]
|
|
6
|
-
|
|
7
|
-
// AI-GENERATED START: observe the host app's active language so Localize can follow it
|
|
8
1
|
import Foundation
|
|
9
2
|
|
|
10
3
|
/// Read-only view of the host app's active language, plus change delivery.
|
|
@@ -16,9 +9,8 @@ public protocol LanguageSource: AnyObject {
|
|
|
16
9
|
func stopObserving()
|
|
17
10
|
}
|
|
18
11
|
|
|
19
|
-
///
|
|
20
|
-
///
|
|
21
|
-
/// same key on `UserDefaults.standard` in-process, so KVO on it sees every one of them.
|
|
12
|
+
/// All three host writers (RN bridge `RNResource`, `JSONLocalization`, KMP `LocalizationProvider`) write the same
|
|
13
|
+
/// `UserDefaults.standard` key in-process, so KVO on it sees every language change.
|
|
22
14
|
public final class UserDefaultsLanguageSource: NSObject, LanguageSource {
|
|
23
15
|
public static let defaultKey = "language"
|
|
24
16
|
|
|
@@ -90,4 +82,3 @@ public final class UserDefaultsLanguageSource: NSObject, LanguageSource {
|
|
|
90
82
|
onChange?(currentLanguage)
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
|
-
// AI-GENERATED END: observe the host app's active language so Localize can follow it
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// MoMoUIKits
|
|
4
|
-
//
|
|
5
|
-
// SwiftUI mirror of Compose's `application/Localize.kt`, itself a port of
|
|
6
|
-
// momo-kits React Native's `Application/Localize.ts`. Holds the merged
|
|
7
|
-
// dictionary (kit defaults + host overrides) and the active language,
|
|
8
|
-
// switched at runtime via `changeLanguage`. `Localize` is an `ObservableObject`
|
|
9
|
-
// so a language switch republishes to consumers of `translate`/`translateData`,
|
|
10
|
-
// mirroring Compose's snapshot-state-backed `language`.
|
|
11
|
-
//
|
|
1
|
+
// SwiftUI mirror of Compose's `application/Localize.kt` (port of RN `Application/Localize.ts`):
|
|
2
|
+
// kit defaults + host overrides and the active language, published like Compose's snapshot state.
|
|
12
3
|
|
|
13
4
|
import Foundation
|
|
14
5
|
import SwiftUI
|
|
@@ -28,16 +19,13 @@ public final class Localize: ObservableObject {
|
|
|
28
19
|
public static let VI = "vi"
|
|
29
20
|
public static let EN = "en"
|
|
30
21
|
|
|
31
|
-
// AI-GENERATED START: follow the host app language and publish dictionary changes
|
|
32
22
|
/// App-wide instance bound to the host language; the environment default uses it too,
|
|
33
23
|
/// so every screen agrees on one language.
|
|
34
24
|
public static let shared = Localize()
|
|
35
|
-
// AI-GENERATED END: follow the host app language and publish dictionary changes
|
|
36
25
|
|
|
37
26
|
private var assets: LocalizationObject
|
|
38
27
|
@Published public private(set) var currentLanguage: String = Localize.VI
|
|
39
28
|
|
|
40
|
-
// AI-GENERATED START: follow the host app language and publish dictionary changes
|
|
41
29
|
/// Bumped by `addTranslations` — `assets` is not published, so without this the dictionary
|
|
42
30
|
/// can change without any consumer re-rendering.
|
|
43
31
|
@Published public private(set) var revision: Int = 0
|
|
@@ -47,7 +35,7 @@ public final class Localize: ObservableObject {
|
|
|
47
35
|
/// `NavigationContainer` uses this to skip its legacy one-shot `MaxApi` pull.
|
|
48
36
|
var observesAppLanguage: Bool { languageSource != nil }
|
|
49
37
|
|
|
50
|
-
///
|
|
38
|
+
/// `languageSource: nil` opts out: the language starts at `vi` and moves only on `changeLanguage`.
|
|
51
39
|
public init(
|
|
52
40
|
_ translations: LocalizationObject = LocalizationObject(),
|
|
53
41
|
languageSource: LanguageSource? = UserDefaultsLanguageSource()
|
|
@@ -90,7 +78,6 @@ public final class Localize: ObservableObject {
|
|
|
90
78
|
public func changeLanguage(_ language: String?) {
|
|
91
79
|
apply(Localize.normalize(language))
|
|
92
80
|
}
|
|
93
|
-
// AI-GENERATED END: follow the host app language and publish dictionary changes
|
|
94
81
|
|
|
95
82
|
public func translate(_ key: String) -> String {
|
|
96
83
|
let dictionary = currentLanguage == Localize.EN ? assets.en : assets.vi
|
|
@@ -111,9 +98,7 @@ public final class Localize: ObservableObject {
|
|
|
111
98
|
/// Existing keys win (mirrors Compose: `merge(translations, assets)`).
|
|
112
99
|
public func addTranslations(_ translations: LocalizationObject) {
|
|
113
100
|
assets = Localize.merge(base: translations, override: assets)
|
|
114
|
-
// AI-GENERATED START: publish dictionary changes so consumers re-render
|
|
115
101
|
onMain { self.revision &+= 1 }
|
|
116
|
-
// AI-GENERATED END: publish dictionary changes so consumers re-render
|
|
117
102
|
}
|
|
118
103
|
|
|
119
104
|
private static func merge(base: LocalizationObject, override: LocalizationObject) -> LocalizationObject {
|
|
@@ -333,41 +318,29 @@ public final class Localize: ObservableObject {
|
|
|
333
318
|
)
|
|
334
319
|
}
|
|
335
320
|
|
|
336
|
-
/// Snapshots `currentLanguage`
|
|
337
|
-
///
|
|
338
|
-
/// `@Environment` does not subscribe to `@Published` the way `@EnvironmentObject` does.
|
|
321
|
+
/// Snapshots `currentLanguage` so `changeLanguage` is an environment *change*: the reference never changes, and
|
|
322
|
+
/// `@Environment` doesn't subscribe to `@Published` the way `@EnvironmentObject` does.
|
|
339
323
|
private struct LocalizeBox: Equatable {
|
|
340
324
|
let localize: Localize
|
|
341
325
|
let language: String
|
|
342
|
-
//
|
|
326
|
+
// Invalidates consumers on dictionary changes too, not just language switches.
|
|
343
327
|
let revision: Int
|
|
344
|
-
// AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
|
|
345
328
|
|
|
346
329
|
init(_ localize: Localize) {
|
|
347
330
|
self.localize = localize
|
|
348
331
|
self.language = localize.currentLanguage
|
|
349
|
-
// AI-GENERATED START: invalidate consumers when the dictionary changes, not just the language
|
|
350
332
|
self.revision = localize.revision
|
|
351
|
-
// AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
|
|
352
333
|
}
|
|
353
334
|
|
|
354
335
|
static func == (lhs: LocalizeBox, rhs: LocalizeBox) -> Bool {
|
|
355
|
-
// AI-GENERATED START: invalidate consumers when the dictionary changes, not just the language
|
|
356
336
|
lhs.localize === rhs.localize && lhs.language == rhs.language && lhs.revision == rhs.revision
|
|
357
|
-
// AI-GENERATED END: invalidate consumers when the dictionary changes, not just the language
|
|
358
337
|
}
|
|
359
338
|
}
|
|
360
339
|
|
|
361
340
|
private struct LocalizeKey: EnvironmentKey {
|
|
362
|
-
///
|
|
363
|
-
///
|
|
364
|
-
/// trapping the way `@EnvironmentObject` does.
|
|
365
|
-
// AI-GENERATED START: default to the app-language-observing shared instance
|
|
366
|
-
/// `defaultValue` is a `static let`, so this box is never rebuilt: without a provider the
|
|
367
|
-
/// language is right on first render but does not live-update. Wrap the root in
|
|
368
|
-
/// `.momoLocalize()` (or use `NavigationContainer`) to get updates.
|
|
341
|
+
/// Never traps like `@EnvironmentObject`, but as a `static let` it is never rebuilt: without `.momoLocalize()`
|
|
342
|
+
/// (or `NavigationContainer`) the language is right on first render but does not live-update.
|
|
369
343
|
static let defaultValue = LocalizeBox(Localize.shared)
|
|
370
|
-
// AI-GENERATED END: default to the app-language-observing shared instance
|
|
371
344
|
}
|
|
372
345
|
|
|
373
346
|
public extension EnvironmentValues {
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
// File: ios/Application/LocalizeModifier.swift
|
|
2
|
-
// Created At: 2026-07-29 10:00:00 +07:00
|
|
3
|
-
// Created By: AI
|
|
4
|
-
// AI Agent: Claude Code
|
|
5
|
-
// Model: claude-opus-5[1m]
|
|
6
|
-
|
|
7
|
-
// AI-GENERATED START: inject a language-observing Localize into any SwiftUI subtree
|
|
8
1
|
import SwiftUI
|
|
9
2
|
|
|
10
3
|
public extension View {
|
|
@@ -15,9 +8,8 @@ public extension View {
|
|
|
15
8
|
}
|
|
16
9
|
}
|
|
17
10
|
|
|
18
|
-
/// `@ObservedObject` is load-bearing: `@Environment(\.localize)` only
|
|
19
|
-
///
|
|
20
|
-
/// set `\.localize` would inject a snapshot that never updates.
|
|
11
|
+
/// `@ObservedObject` is load-bearing: `@Environment(\.localize)` invalidates only when *this* body re-runs on a
|
|
12
|
+
/// publish; a helper that just set `\.localize` would inject a snapshot that never updates.
|
|
21
13
|
private struct MomoLocalizeModifier: ViewModifier {
|
|
22
14
|
@ObservedObject var localize: Localize
|
|
23
15
|
|
|
@@ -27,4 +19,3 @@ private struct MomoLocalizeModifier: ViewModifier {
|
|
|
27
19
|
.environment(\.localize, localize)
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
|
-
// AI-GENERATED END: inject a language-observing Localize into any SwiftUI subtree
|
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// MoMoUIKits
|
|
4
|
-
//
|
|
5
|
-
// Swift mirror of the host-app bridge exposed on Kotlin as `vn.momo.maxapi.IMaxApi`
|
|
6
|
-
// (`LocalMaxApi`). `IMaxApi` itself is an external compiled dependency with no
|
|
7
|
-
// source in this repo, so this protocol intentionally exposes only the methods
|
|
8
|
-
// this kit's Kotlin source actually calls — not a full guess at IMaxApi's real surface.
|
|
9
|
-
// Callbacks carry IMaxApi's `["response": …]` payload.
|
|
10
|
-
//
|
|
1
|
+
// Swift mirror of the host bridge `vn.momo.maxapi.IMaxApi` (`LocalMaxApi`). IMaxApi is an external
|
|
2
|
+
// binary, so only the methods the kit calls are declared; callbacks carry its `["response": …]` payload.
|
|
11
3
|
|
|
12
4
|
import UIKit
|
|
13
5
|
|
|
@@ -32,7 +24,7 @@ public extension MaxApi {
|
|
|
32
24
|
UIImpactFeedbackGenerator(style: .light).impactOccurred()
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
// Hosts that don't bridge the toolkit keep it inert
|
|
27
|
+
// Hosts that don't bridge the toolkit keep it inert.
|
|
36
28
|
func isFavoriteApp(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
|
|
37
29
|
func onToolAction(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
|
|
38
30
|
func showTools(_ params: [String: Any?], callback: @escaping ([String: Any?]?) -> Void) {}
|
package/ios/Avatar/Avatar.swift
CHANGED
package/ios/Badge/Badge.swift
CHANGED
|
@@ -41,17 +41,14 @@ public struct Badge: View {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
private var badgeColor: Color {
|
|
44
|
-
//
|
|
45
|
-
let defaultColor: Color = isNumber(label)
|
|
46
|
-
? theme.colors.error.primary
|
|
47
|
-
: theme.colors.warning.primary
|
|
48
|
-
|
|
49
|
-
// Mirror Compose: only apply backgroundColor when it is one of the
|
|
50
|
-
// allowed primaryColors; otherwise fall back to the label-based default.
|
|
44
|
+
// Mirrors Compose: backgroundColor applies only when it is one of primaryColors.
|
|
51
45
|
if let bgColor = backgroundColor, primaryColors.contains(bgColor) {
|
|
52
46
|
return bgColor
|
|
53
47
|
}
|
|
54
|
-
|
|
48
|
+
if isNumber(label) {
|
|
49
|
+
return theme.colors.error.primary
|
|
50
|
+
}
|
|
51
|
+
return theme.colors.warning.primary
|
|
55
52
|
}
|
|
56
53
|
|
|
57
54
|
public var body: some View {
|
|
@@ -198,10 +198,8 @@ public struct BadgeRibbon: View {
|
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
-
///
|
|
202
|
-
///
|
|
203
|
-
/// rotation) — the label gets the same scale applied a second time so it stays right-reading
|
|
204
|
-
/// while only the ribbon shape flips.
|
|
201
|
+
/// Compose's `RoundedBadgeRibbon`: a ribbon sized to its text, mirrored per corner with
|
|
202
|
+
/// scaleX/scaleY (never rotated); the label is scaled again so only the shape flips.
|
|
205
203
|
public struct RoundedBadgeRibbon: View {
|
|
206
204
|
@Environment(\.appTheme) private var theme
|
|
207
205
|
@Environment(\.momoFontScale) private var fontScale
|
|
@@ -312,7 +310,6 @@ extension String {
|
|
|
312
310
|
struct BadgeRibbon_Previews: PreviewProvider {
|
|
313
311
|
static var previews: some View {
|
|
314
312
|
VStack(spacing: 30) {
|
|
315
|
-
// Basic ribbon examples
|
|
316
313
|
BadgeRibbon(position: .topRight, label: "New")
|
|
317
314
|
BadgeRibbon(position: .topLeft, label: "Hot", isRound: true)
|
|
318
315
|
BadgeRibbon(position: .bottomLeft, label: "Sale")
|
package/ios/Button/Button.swift
CHANGED
|
@@ -229,9 +229,8 @@ public struct Button: View {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
|
|
232
|
-
///
|
|
233
|
-
/// horizontal inset and the whole button
|
|
234
|
-
/// matching `animatedPadding`/`alpha` in Button.kt.
|
|
232
|
+
/// Compose's press feedback (`animatedPadding` / `alpha` in Button.kt): the background shrinks by an animated
|
|
233
|
+
/// horizontal inset and the whole button fades to 0.5.
|
|
235
234
|
private struct ButtonPressFeedbackStyle: ButtonStyle {
|
|
236
235
|
let isEnabled: Bool
|
|
237
236
|
let background: Color
|
|
@@ -264,11 +263,8 @@ private struct ButtonPressFeedbackStyle: ButtonStyle {
|
|
|
264
263
|
}
|
|
265
264
|
}
|
|
266
265
|
|
|
267
|
-
///
|
|
268
|
-
/// the
|
|
269
|
-
/// the content even when `isFull == false`. iOS 17 fixed the label to hug its
|
|
270
|
-
/// content, so only legacy OSes need the `fixedSize` clamp (kept off on 17+ to
|
|
271
|
-
/// preserve tail truncation of long titles).
|
|
266
|
+
/// The style label takes the full proposed width before iOS 17, stretching the background
|
|
267
|
+
/// past the content; `fixedSize` there only, as on 17+ it would stop long titles truncating.
|
|
272
268
|
private struct HugContentOnLegacyOS: ViewModifier {
|
|
273
269
|
let isFull: Bool
|
|
274
270
|
|
|
@@ -52,8 +52,8 @@ public struct CalculatorKeyboard: View {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
/// Integer `+ - * /` with the usual precedence
|
|
56
|
-
///
|
|
55
|
+
/// Integer `+ - * /` with the usual precedence. Not NSExpression: it crashes when a number or
|
|
56
|
+
/// result leaves `Int` range, where this returns nil.
|
|
57
57
|
static func evaluate(_ expression: String) -> Int? {
|
|
58
58
|
var numbers: [Int] = []
|
|
59
59
|
var operators: [Character] = []
|
|
@@ -92,11 +92,9 @@ public struct CalculatorKeyboard: View {
|
|
|
92
92
|
|
|
93
93
|
var result = terms[0]
|
|
94
94
|
for (sign, term) in zip(signs, terms.dropFirst()) {
|
|
95
|
-
let
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if overflow { return nil }
|
|
99
|
-
result = next
|
|
95
|
+
let step = sign == "+" ? result.addingReportingOverflow(term) : result.subtractingReportingOverflow(term)
|
|
96
|
+
if step.overflow { return nil }
|
|
97
|
+
result = step.partialValue
|
|
100
98
|
}
|
|
101
99
|
return result
|
|
102
100
|
}
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import SwiftUI
|
|
2
2
|
|
|
3
|
-
///
|
|
4
|
-
///
|
|
5
|
-
/// Mirrors the Compose API: a paging horizontal carousel driven by an
|
|
6
|
-
/// `itemCount` and a `content` builder that receives the real (modulo) index.
|
|
7
|
-
/// Supports infinite `loop`, `autoplay` with a configurable interval,
|
|
8
|
-
/// inactive-slide `opacity`/`scale` effects, optional `contentPadding`,
|
|
9
|
-
/// snap behavior, and scroll enable/disable. Snap / scroll-index callbacks
|
|
10
|
-
/// report the real item index.
|
|
11
|
-
///
|
|
12
|
-
/// Uses a custom drag-driven pager (not a ScrollView) so behavior is identical
|
|
13
|
-
/// across versions and supports the loop virtualization + transform effects
|
|
14
|
-
/// that `TabView(.page)` cannot express.
|
|
3
|
+
/// Compose `Carousel`; `content` and the snap / scroll-index callbacks get the real (modulo) index. A drag-driven
|
|
4
|
+
/// pager, as ScrollView and `TabView(.page)` can't express the loop virtualization or inactive-slide effects.
|
|
15
5
|
public struct Carousel<Content: View>: View {
|
|
16
6
|
// MARK: Lifecycle
|
|
17
7
|
|
|
@@ -93,11 +83,8 @@ public struct Carousel<Content: View>: View {
|
|
|
93
83
|
// Offset so the current page is centered within the viewport padding.
|
|
94
84
|
let baseOffset = -CGFloat(currentPage) * step + contentPadding
|
|
95
85
|
|
|
96
|
-
//
|
|
97
|
-
//
|
|
98
|
-
// eager views, a real memory/perf regression versus Compose's lazy `HorizontalPager`.
|
|
99
|
-
// Clear spacers of the skipped width keep the HStack's total layout size (and thus
|
|
100
|
-
// the existing `baseOffset` math) unchanged.
|
|
86
|
+
// Only a window around `currentPage` renders (`loop` means `itemCount * 1000` slides; Compose's
|
|
87
|
+
// pager is lazy); clear spacers of the skipped width keep the HStack size for `baseOffset`.
|
|
101
88
|
let windowRadius = 3
|
|
102
89
|
let windowStart = max(0, currentPage - windowRadius)
|
|
103
90
|
let windowEnd = min(virtualPageCount - 1, currentPage + windowRadius)
|
|
@@ -29,7 +29,6 @@ public struct Checkbox: View{
|
|
|
29
29
|
|
|
30
30
|
public var body: some View {
|
|
31
31
|
HStack(spacing: Spacing.S) {
|
|
32
|
-
// Checkbox
|
|
33
32
|
SwiftUI.Button(action: onCheck) {
|
|
34
33
|
ZStack {
|
|
35
34
|
RoundedRectangle(cornerRadius: Radius.XS)
|
|
@@ -50,7 +49,6 @@ public struct Checkbox: View{
|
|
|
50
49
|
.buttonStyle(ActiveOpacityButtonStyle(activeOpacity: 0.8))
|
|
51
50
|
.disabled(disabled)
|
|
52
51
|
|
|
53
|
-
// Title
|
|
54
52
|
if !title.isEmpty {
|
|
55
53
|
MomoText(title, typography: .descriptionDefaultRegular)
|
|
56
54
|
}
|