@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
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// MoMoUIKits
|
|
4
|
-
//
|
|
5
|
-
// SwiftUI mirror of Compose's `navigation/BottomSheet.kt`.
|
|
6
|
-
// A sheet that slides up from the bottom over a dimmed scrim, with a drag
|
|
7
|
-
// handle, a header (title or custom), a divider and the content body.
|
|
8
|
-
// Dragging down past a threshold (or tapping the scrim) dismisses it.
|
|
9
|
-
// Driven by `Navigator.showBottomSheet`.
|
|
10
|
-
//
|
|
1
|
+
// SwiftUI mirror of Compose's `navigation/BottomSheet.kt`, driven by `Navigator.showBottomSheet`:
|
|
2
|
+
// drag handle, header and body over a dimmed scrim; a long drag down or a scrim tap dismisses it.
|
|
11
3
|
|
|
12
4
|
import SwiftUI
|
|
13
5
|
|
|
@@ -15,16 +7,25 @@ import SwiftUI
|
|
|
15
7
|
|
|
16
8
|
/// Mirrors Compose's `sealed class BottomHeader` (Title / Custom).
|
|
17
9
|
public struct BottomSheetHeader {
|
|
10
|
+
struct Back {
|
|
11
|
+
let icon: String
|
|
12
|
+
let action: () -> Void
|
|
13
|
+
}
|
|
14
|
+
|
|
18
15
|
enum Style {
|
|
19
|
-
case title(String)
|
|
16
|
+
case title(String, back: Back?)
|
|
20
17
|
case custom(() -> AnyView)
|
|
21
18
|
}
|
|
22
19
|
|
|
23
20
|
let style: Style
|
|
24
21
|
|
|
25
|
-
/// Mirrors `BottomHeader.Title`.
|
|
26
|
-
public static func title(
|
|
27
|
-
|
|
22
|
+
/// Mirrors `BottomHeader.Title`. `onBack` shows a back button; the sheet closes, then it runs.
|
|
23
|
+
public static func title(
|
|
24
|
+
_ text: String = "Bottom Sheet Title",
|
|
25
|
+
backIcon: String = "arrow-back",
|
|
26
|
+
onBack: (() -> Void)? = nil
|
|
27
|
+
) -> BottomSheetHeader {
|
|
28
|
+
BottomSheetHeader(style: .title(text, back: onBack.map { Back(icon: backIcon, action: $0) }))
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/// Mirrors `BottomHeader.Custom`.
|
|
@@ -59,50 +60,29 @@ struct BottomSheetView<Content: View>: View {
|
|
|
59
60
|
@State private var didAppear = false
|
|
60
61
|
@State private var isClosing = false
|
|
61
62
|
@State private var keyboardHeight: CGFloat = 0
|
|
62
|
-
///
|
|
63
|
-
///
|
|
64
|
-
/// `content()`) to reconstruct every frame — mirrors the pattern already used in
|
|
65
|
-
/// `ios/PopupView/PopupView.swift` for smooth drag-to-dismiss.
|
|
63
|
+
/// Kept apart from `sheetOffset` so a touch-move invalidates only this value instead of
|
|
64
|
+
/// rebuilding `content()` every frame (as PopupView does for drag-to-dismiss).
|
|
66
65
|
@GestureState private var dragTranslation: CGFloat = 0
|
|
67
66
|
|
|
68
67
|
/// Mirrors Compose's `sheetCloseOffset` (100dp drag threshold to dismiss).
|
|
69
68
|
private let closeThreshold: CGFloat = 100
|
|
70
69
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
private let maxDynamicAlpha: CGFloat = 0.3
|
|
74
|
-
|
|
75
|
-
// UIScreen stays on the outer display on iPhone Duo, even when unfolded
|
|
76
|
-
private var screenHeight: CGFloat { isDuo ? layout.height : UIScreen.main.bounds.height }
|
|
77
|
-
|
|
78
|
-
private var isDuo: Bool { layout.isDuoDevice }
|
|
79
|
-
// iPhone Duo inner display: center the sheet instead of spanning the width
|
|
80
|
-
private var isDuoCentered: Bool { isDuo && layout.width >= 600 }
|
|
70
|
+
private let indicatorHeight: CGFloat = 16
|
|
71
|
+
private let headerRowHeight: CGFloat = 56
|
|
81
72
|
|
|
82
|
-
///
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
min(layout.width, layout.height) - Spacing.L * 2,
|
|
86
|
-
layout.width - max(layout.insets.leading, layout.insets.trailing, Spacing.L) * 2
|
|
87
|
-
)
|
|
88
|
-
}
|
|
73
|
+
/// Half the scrim fades in first, the other half follows the sheet; together they reach
|
|
74
|
+
/// `scrimOpacity` (0.6 on phones, as ModalScreen; 0.2 on foldables).
|
|
75
|
+
private let maxDynamicAlpha: CGFloat = 0.5
|
|
89
76
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
private var sideInsetLeading: CGFloat {
|
|
93
|
-
isDuo && !isDuoCentered && layout.width > layout.height ? layout.insets.leading : 0
|
|
94
|
-
}
|
|
77
|
+
private var modal: ModalLayout { layout.modalLayout }
|
|
78
|
+
private var isFoldable: Bool { modal.isFoldable }
|
|
95
79
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}
|
|
80
|
+
// UIScreen stays on the outer display on iPhone Duo, even when unfolded
|
|
81
|
+
private var screenHeight: CGFloat { isFoldable ? layout.height : UIScreen.main.bounds.height }
|
|
99
82
|
|
|
100
|
-
private var maxHeight: CGFloat {
|
|
101
|
-
isDuo ? layout.height - max(layout.duoTopInset, Spacing.XL) : screenHeight - 90
|
|
102
|
-
}
|
|
83
|
+
private var maxHeight: CGFloat { modal.sheet.maxHeight ?? screenHeight - 90 }
|
|
103
84
|
private var bottomInset: CGFloat { useBottomInset ? safeAreaBottomInset() : 0 }
|
|
104
|
-
///
|
|
105
|
-
/// replaces (rather than adds to) the usual bottom-inset filler.
|
|
85
|
+
/// The keyboard already covers the home-indicator area, so it replaces the filler, not adds to it.
|
|
106
86
|
private var effectiveBottomInset: CGFloat { keyboardHeight > 0 ? keyboardHeight : bottomInset }
|
|
107
87
|
|
|
108
88
|
private var backgroundColor: Color {
|
|
@@ -111,9 +91,8 @@ struct BottomSheetView<Content: View>: View {
|
|
|
111
91
|
|
|
112
92
|
private var effectiveOffset: CGFloat { sheetOffset + dragTranslation }
|
|
113
93
|
|
|
114
|
-
/// Mirrors Compose's `dynamicAlpha`:
|
|
115
|
-
///
|
|
116
|
-
/// dragged down.
|
|
94
|
+
/// Mirrors Compose's `dynamicAlpha`: derived from the live offset (not animated), shrinking
|
|
95
|
+
/// toward 0 as the sheet is dragged down.
|
|
117
96
|
private var dynamicAlpha: CGFloat {
|
|
118
97
|
let denom = sheetHeight > 0 ? sheetHeight : screenHeight
|
|
119
98
|
guard denom > 0 else { return maxDynamicAlpha }
|
|
@@ -121,15 +100,14 @@ struct BottomSheetView<Content: View>: View {
|
|
|
121
100
|
return progress * maxDynamicAlpha
|
|
122
101
|
}
|
|
123
102
|
|
|
124
|
-
///
|
|
125
|
-
///
|
|
126
|
-
|
|
127
|
-
private var totalScrimAlpha: CGFloat { backgroundAlpha + dynamicAlpha }
|
|
103
|
+
/// Compose's `(backgroundAlpha + dynamicAlpha) * scrimOpacity`: additive, so a drag fades the scrim only to half
|
|
104
|
+
/// of `scrimOpacity` (backgroundAlpha holds until an explicit close()).
|
|
105
|
+
private var totalScrimAlpha: CGFloat { (backgroundAlpha + dynamicAlpha) * modal.scrimOpacity }
|
|
128
106
|
|
|
129
107
|
var body: some View {
|
|
130
108
|
ZStack(alignment: .bottom) {
|
|
131
|
-
//
|
|
132
|
-
|
|
109
|
+
// full screen on foldables too
|
|
110
|
+
Colors.black20.opacity(totalScrimAlpha)
|
|
133
111
|
.contentShape(Rectangle())
|
|
134
112
|
.onTapGesture {
|
|
135
113
|
if barrierDismissible { close() }
|
|
@@ -170,13 +148,11 @@ struct BottomSheetView<Content: View>: View {
|
|
|
170
148
|
.frame(width: 40, height: 4)
|
|
171
149
|
Spacer().frame(height: 4)
|
|
172
150
|
headerView
|
|
173
|
-
.frame(height:
|
|
151
|
+
.frame(height: headerRowHeight)
|
|
174
152
|
.padding(.horizontal, Spacing.M)
|
|
175
|
-
.padding(.leading, sideInsetLeading)
|
|
176
|
-
.padding(.trailing, sideInsetTrailing)
|
|
177
153
|
}
|
|
178
154
|
.frame(maxWidth: .infinity)
|
|
179
|
-
.frame(height:
|
|
155
|
+
.frame(height: indicatorHeight + headerRowHeight)
|
|
180
156
|
.contentShape(Rectangle())
|
|
181
157
|
.gesture(dragGesture, including: draggable ? .all : .subviews)
|
|
182
158
|
|
|
@@ -185,15 +161,16 @@ struct BottomSheetView<Content: View>: View {
|
|
|
185
161
|
.frame(height: 1)
|
|
186
162
|
|
|
187
163
|
content()
|
|
188
|
-
.padding(.leading, sideInsetLeading)
|
|
189
|
-
.padding(.trailing, sideInsetTrailing)
|
|
190
164
|
// a tall sheet keeps its header (and footer) and gives the content what is left
|
|
191
165
|
.layoutPriority(-1)
|
|
192
166
|
|
|
193
167
|
if let footer {
|
|
168
|
+
// a sheet held at its min height keeps the footer at the bottom
|
|
169
|
+
Spacer(minLength: 0).layoutPriority(-2)
|
|
194
170
|
BottomSheetFooter(content: footer)
|
|
195
171
|
}
|
|
196
172
|
}
|
|
173
|
+
.frame(minHeight: max(modal.sheet.minHeight - effectiveBottomInset, 0), alignment: .top)
|
|
197
174
|
// The filler stays outside the cap, which shrinks by it instead: the sheet still ends at
|
|
198
175
|
// `maxHeight`, and the iOS 15 fallback never measures the keyboard as content.
|
|
199
176
|
.modifier(CapHeight(maxHeight: maxHeight - effectiveBottomInset))
|
|
@@ -201,7 +178,8 @@ struct BottomSheetView<Content: View>: View {
|
|
|
201
178
|
(footer != nil ? theme.colors.background.surface : backgroundColor)
|
|
202
179
|
.frame(height: effectiveBottomInset)
|
|
203
180
|
}
|
|
204
|
-
.frame(
|
|
181
|
+
.frame(width: modal.sheet.width)
|
|
182
|
+
.frame(maxWidth: modal.sheet.width == nil ? .infinity : nil)
|
|
205
183
|
.clipped()
|
|
206
184
|
.background(
|
|
207
185
|
GeometryReader { geo in
|
|
@@ -209,44 +187,45 @@ struct BottomSheetView<Content: View>: View {
|
|
|
209
187
|
}
|
|
210
188
|
)
|
|
211
189
|
.background(backgroundColor)
|
|
212
|
-
.clipShape(RoundedCorner(radius:
|
|
190
|
+
.clipShape(RoundedCorner(radius: modal.sheet.radius, corners: [.topLeft, .topRight]))
|
|
191
|
+
// centered in the placement: off the iPhone Duo control column, the right half when half folded
|
|
192
|
+
.padding(.leading, isFoldable ? modal.placement.minX : 0)
|
|
193
|
+
.padding(.trailing, isFoldable ? layout.width - modal.placement.maxX : 0)
|
|
213
194
|
}
|
|
214
195
|
|
|
215
196
|
@ViewBuilder
|
|
216
197
|
private var headerView: some View {
|
|
217
198
|
switch header.style {
|
|
218
|
-
case .title(let text):
|
|
219
|
-
HStack(spacing:
|
|
220
|
-
|
|
199
|
+
case .title(let text, let back):
|
|
200
|
+
HStack(spacing: Spacing.S) {
|
|
201
|
+
if let back {
|
|
202
|
+
ModalIconButton(icon: back.icon, accessibilityId: "btn_bottom_sheet_back") { goBack(back) }
|
|
203
|
+
} else {
|
|
204
|
+
Color.clear.frame(width: ModalMetrics.iconButtonSize, height: ModalMetrics.iconButtonSize)
|
|
205
|
+
}
|
|
221
206
|
MomoText(text, typography: .headerDefaultBold, color: Colors.black17)
|
|
222
207
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
223
|
-
|
|
224
|
-
.frame(width: 24, height: 24)
|
|
225
|
-
.contentShape(Rectangle())
|
|
226
|
-
.onTapGesture { close() }
|
|
208
|
+
ModalIconButton(icon: "navigation_close", accessibilityId: "btn_bottom_sheet_close") { close() }
|
|
227
209
|
}
|
|
228
210
|
case .custom(let builder):
|
|
229
211
|
builder()
|
|
230
212
|
}
|
|
231
213
|
}
|
|
232
214
|
|
|
215
|
+
/// RN `leftOptions.onPressIconLeft`: the sheet closes first, then the back runs.
|
|
216
|
+
private func goBack(_ back: BottomSheetHeader.Back) {
|
|
217
|
+
close(then: back.action)
|
|
218
|
+
}
|
|
219
|
+
|
|
233
220
|
// MARK: - Drag handling (mirrors Compose's detectDragGestures)
|
|
234
221
|
|
|
235
222
|
private var dragGesture: some Gesture {
|
|
236
|
-
// `.global
|
|
237
|
-
//
|
|
238
|
-
// every frame by this same gesture's output (`sheet.offset(y: effectiveOffset)`
|
|
239
|
-
// in `body`) — the local coordinate space chasing its own moving reference
|
|
240
|
-
// frame is a plausible source of a continuous drag-time jitter.
|
|
223
|
+
// `.global`: the handle moves with this gesture's own output, so the local space would
|
|
224
|
+
// chase a moving reference frame and jitter.
|
|
241
225
|
DragGesture(coordinateSpace: .global)
|
|
242
226
|
.onChanged { _ in
|
|
243
|
-
//
|
|
244
|
-
//
|
|
245
|
-
// open animation — or the keyboard-driven resize, which shifts this
|
|
246
|
-
// same bottom-anchored top edge — is still in flight doesn't fight a
|
|
247
|
-
// moving target. Without this, the live drag value chases an animated
|
|
248
|
-
// one, producing a couple of corrective jumps before it settles.
|
|
249
|
-
// A closing sheet keeps going down.
|
|
227
|
+
// Settle an in-flight open (or keyboard resize) at rest without animation, or the
|
|
228
|
+
// drag chases an animated value and jumps. A closing sheet keeps going down.
|
|
250
229
|
if sheetOffset != 0 && !isClosing {
|
|
251
230
|
sheetOffset = 0
|
|
252
231
|
}
|
|
@@ -257,9 +236,8 @@ struct BottomSheetView<Content: View>: View {
|
|
|
257
236
|
.onEnded { value in
|
|
258
237
|
guard !isClosing else { return }
|
|
259
238
|
let finalOffset = max(value.translation.height, 0)
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
// slide-out animation starts (mirrors PopupView's `lastDragPosition`).
|
|
239
|
+
// Persist before @GestureState resets to 0, or the sheet snaps back for a frame
|
|
240
|
+
// before close() slides it out (PopupView's `lastDragPosition`).
|
|
263
241
|
sheetOffset = finalOffset
|
|
264
242
|
if finalOffset > closeThreshold {
|
|
265
243
|
close()
|
|
@@ -282,7 +260,7 @@ struct BottomSheetView<Content: View>: View {
|
|
|
282
260
|
|
|
283
261
|
/// Mirrors Compose's `closeEvent`: slide out over 200ms, then fade the scrim
|
|
284
262
|
/// out over 100ms only after the slide finishes, then dismiss.
|
|
285
|
-
private func close() {
|
|
263
|
+
private func close(then onClosed: (() -> Void)? = nil) {
|
|
286
264
|
guard !isClosing else { return }
|
|
287
265
|
isClosing = true
|
|
288
266
|
withAnimation(.timingCurve(0.3, 0, 0.8, 0.15, duration: 0.2)) {
|
|
@@ -294,14 +272,16 @@ struct BottomSheetView<Content: View>: View {
|
|
|
294
272
|
}
|
|
295
273
|
}
|
|
296
274
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
275
|
+
// a newer overlay replaced this one: it stays, and this sheet's back is dropped
|
|
276
|
+
guard navigator.overplay?.id == overplayId else { return }
|
|
297
277
|
navigator.finishOverplayDismiss(id: overplayId)
|
|
278
|
+
onClosed?()
|
|
298
279
|
}
|
|
299
280
|
}
|
|
300
281
|
}
|
|
301
282
|
|
|
302
|
-
/// Compose's `heightIn(max:)
|
|
303
|
-
/// larger, leaving a gap above the header
|
|
304
|
-
/// when taller.
|
|
283
|
+
/// Compose's `heightIn(max:)`: sizes the sheet to its content, capped only when taller. `.frame(maxHeight:)` grows
|
|
284
|
+
/// to the cap whenever the proposal is larger, leaving a gap above the header.
|
|
305
285
|
private struct CapHeight: ViewModifier {
|
|
306
286
|
let maxHeight: CGFloat
|
|
307
287
|
|
|
@@ -314,9 +294,8 @@ private struct CapHeight: ViewModifier {
|
|
|
314
294
|
}
|
|
315
295
|
}
|
|
316
296
|
|
|
317
|
-
/// iOS 15
|
|
318
|
-
///
|
|
319
|
-
/// content), so it is re-measured only when the cap grows, e.g. once the keyboard goes down.
|
|
297
|
+
/// iOS 15 (no `Layout`): hugs the ideal height until it outgrows the cap. A capped sheet can't read its ideal height
|
|
298
|
+
/// without a second copy of the content, so it is re-measured only when the cap grows (e.g. the keyboard hides).
|
|
320
299
|
private struct CapHeightFallback: ViewModifier {
|
|
321
300
|
let maxHeight: CGFloat
|
|
322
301
|
@State private var capped = false
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// MoMoUIKits
|
|
4
|
-
//
|
|
5
|
-
// SwiftUI mirror of Compose's `navigation/bottomtab/BottomTab.kt`: tabbed screens, each in
|
|
6
|
-
// `StackScreen` chrome built from its own `Navigation`, over a `BottomTabBar` (or the iPhone Duo
|
|
7
|
-
// rail / floating bar). Switching tabs cross-fades + scales the content.
|
|
8
|
-
//
|
|
1
|
+
// SwiftUI mirror of Compose's `navigation/bottomtab/BottomTab.kt`: tabs in `StackScreen` chrome, each with its own
|
|
2
|
+
// `Navigation`, over a `BottomTabBar` (or the iPhone Duo rail / floating bar); a switch cross-fades + scales.
|
|
9
3
|
|
|
10
4
|
import SwiftUI
|
|
11
5
|
import UIKit
|
|
@@ -30,10 +24,8 @@ public struct BottomTab: View {
|
|
|
30
24
|
@State private var expandedBar: DuoBar?
|
|
31
25
|
@State private var openedBar: DuoBar?
|
|
32
26
|
|
|
33
|
-
/// `compressionBehavior`:
|
|
34
|
-
///
|
|
35
|
-
/// `onTabPress` gets every tab press with the switch to perform, e.g. after a login gate.
|
|
36
|
-
/// `backToInitialTab`: back off another tab returns to the initial one before leaving the screen.
|
|
27
|
+
/// `compressionBehavior`: iPhone Duo bar that starts compressed when the side bar can't hold both (a tap swaps).
|
|
28
|
+
/// `onTabPress` gets the switch to run, e.g. after a login gate. `backToInitialTab`: back goes to it first.
|
|
37
29
|
public init(
|
|
38
30
|
items: [BottomTabItem],
|
|
39
31
|
floatingButton: BottomTabFloatingButton? = nil,
|
|
@@ -53,10 +45,9 @@ public struct BottomTab: View {
|
|
|
53
45
|
}
|
|
54
46
|
|
|
55
47
|
private var bottomInset: CGFloat { safeAreaBottomInset() }
|
|
56
|
-
// the
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
48
|
+
// the bars float over the content (tab screens keep clear of them through duoTabBarInsets) or sit
|
|
49
|
+
// in the side strip, so only the home indicator is kept clear
|
|
50
|
+
private var reservedBottom: CGFloat { layout.insets.bottom }
|
|
60
51
|
|
|
61
52
|
private var compression: DuoBarCompression {
|
|
62
53
|
DuoBarCompression.resolve(
|
|
@@ -87,7 +78,6 @@ public struct BottomTab: View {
|
|
|
87
78
|
public var body: some View {
|
|
88
79
|
let compression = compression
|
|
89
80
|
ZStack(alignment: .bottom) {
|
|
90
|
-
// Tab content area, inset above the bar.
|
|
91
81
|
TabHost(selectedIndex: selectedIndex, count: items.count) { index in AnyView(tabScreen(for: index)) }
|
|
92
82
|
// each tab hosts itself, so it needs the window's safe area to draw its header under the status bar
|
|
93
83
|
.ignoresSafeArea(.container, edges: [.top, .horizontal])
|
|
@@ -95,28 +85,26 @@ public struct BottomTab: View {
|
|
|
95
85
|
.environment(\.duoTabBarInsets, duoInsets(compression))
|
|
96
86
|
.environment(\.duoBarCompression, compression)
|
|
97
87
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
VStack(spacing: 0) {
|
|
88
|
+
Group {
|
|
89
|
+
if layout.isIPhoneDuo {
|
|
90
|
+
DuoTabBar(
|
|
91
|
+
items: items,
|
|
92
|
+
floatingButton: floatingButton,
|
|
93
|
+
selectedIndex: selectedIndex,
|
|
94
|
+
onTabSelected: selectTab,
|
|
95
|
+
compression: compression
|
|
96
|
+
)
|
|
97
|
+
} else {
|
|
109
98
|
BottomTabBar(
|
|
110
99
|
items: items,
|
|
111
100
|
floatingButton: floatingButton,
|
|
112
101
|
selectedIndex: selectedIndex,
|
|
113
|
-
onTabSelected: selectTab
|
|
102
|
+
onTabSelected: selectTab,
|
|
103
|
+
bottomInset: bottomInset
|
|
114
104
|
)
|
|
115
|
-
theme.colors.background.surface
|
|
116
|
-
.frame(height: bottomInset + Spacing.S)
|
|
117
|
-
.ignoresSafeArea(edges: .horizontal)
|
|
118
105
|
}
|
|
119
106
|
}
|
|
107
|
+
.scaleSizeMaxRate(TabBarMetrics.labelMaxScale)
|
|
120
108
|
}
|
|
121
109
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
122
110
|
.ignoresSafeArea(edges: .bottom)
|
|
@@ -137,6 +125,7 @@ public struct BottomTab: View {
|
|
|
137
125
|
}
|
|
138
126
|
|
|
139
127
|
private func selectTab(_ index: Int) {
|
|
128
|
+
navigator.maxApi?.triggerEventVibration("light")
|
|
140
129
|
let switchTab = { if index != selectedIndex { selectedIndex = index } }
|
|
141
130
|
if let onTabPress { onTabPress(index, switchTab) } else { switchTab() }
|
|
142
131
|
}
|
|
@@ -188,10 +177,8 @@ private struct TabScreenHost: View {
|
|
|
188
177
|
|
|
189
178
|
// MARK: - Tab host
|
|
190
179
|
|
|
191
|
-
/// Compose's tab NavHost with `saveState` / `restoreState
|
|
192
|
-
///
|
|
193
|
-
/// out of the window, so it gets onDisappear / onAppear (and re-runs screen tracking) like a NavHost
|
|
194
|
-
/// destination or a UITabBarController tab. Same scheme as `StackController`.
|
|
180
|
+
/// Compose's tab NavHost with `saveState` / `restoreState`: a tab keeps its UIHostingController (state, scroll).
|
|
181
|
+
/// Hidden, it leaves the window and gets onDisappear / onAppear, re-running screen tracking, as in `StackController`.
|
|
195
182
|
private struct TabHost: UIViewControllerRepresentable {
|
|
196
183
|
let selectedIndex: Int
|
|
197
184
|
let count: Int
|
|
@@ -208,11 +195,11 @@ private struct TabHost: UIViewControllerRepresentable {
|
|
|
208
195
|
|
|
209
196
|
private final class TabController: UIViewController {
|
|
210
197
|
private final class Tab {
|
|
211
|
-
let motion = TabMotion()
|
|
212
198
|
var host: UIHostingController<AnyView>!
|
|
213
199
|
}
|
|
214
200
|
|
|
215
|
-
|
|
201
|
+
/// The tab switch: the screens slide in index order over 280ms, CSS `ease`.
|
|
202
|
+
private static let switchDuration: TimeInterval = 0.28
|
|
216
203
|
|
|
217
204
|
private var tabs: [Int: Tab] = [:]
|
|
218
205
|
private var selectedIndex: Int?
|
|
@@ -226,7 +213,7 @@ private final class TabController: UIViewController {
|
|
|
226
213
|
|
|
227
214
|
override func viewDidLayoutSubviews() {
|
|
228
215
|
super.viewDidLayoutSubviews()
|
|
229
|
-
for subview in view.subviews { subview
|
|
216
|
+
for subview in view.subviews { place(subview) }
|
|
230
217
|
}
|
|
231
218
|
|
|
232
219
|
func update(
|
|
@@ -243,33 +230,43 @@ private final class TabController: UIViewController {
|
|
|
243
230
|
}
|
|
244
231
|
if let selectedIndex, tabs[selectedIndex] == nil { self.selectedIndex = nil }
|
|
245
232
|
// hidden tabs too, so a tab coming back already shows the latest items and environment
|
|
246
|
-
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex
|
|
233
|
+
for (tabIndex, existing) in tabs { existing.host.rootView = rootView(tabIndex) }
|
|
247
234
|
guard (0..<count).contains(index), index != selectedIndex else { return }
|
|
248
235
|
|
|
249
|
-
let
|
|
236
|
+
let previousIndex = selectedIndex
|
|
237
|
+
let previous = previousIndex.flatMap { tabs[$0] }
|
|
250
238
|
selectedIndex = index
|
|
251
239
|
let selected = tabs[index] ?? makeTab(index)
|
|
240
|
+
// a tab selected again while it leaves carries on from where it is
|
|
241
|
+
let entering = selected.host.view.superview == nil
|
|
252
242
|
attach(selected)
|
|
253
243
|
|
|
254
|
-
guard let previous, view.window != nil else {
|
|
255
|
-
selected.
|
|
244
|
+
guard let previous, let previousIndex, view.window != nil else {
|
|
245
|
+
selected.host.view.transform = .identity
|
|
256
246
|
previous.map(leave)
|
|
257
247
|
return
|
|
258
248
|
}
|
|
259
249
|
previous.host.view.isUserInteractionEnabled = false
|
|
260
|
-
|
|
250
|
+
let offset = index > previousIndex ? view.bounds.width : -view.bounds.width
|
|
251
|
+
if entering { selected.host.view.transform = CGAffineTransform(translationX: offset, y: 0) }
|
|
252
|
+
// a frame at the start values first, so a tab created just now slides in with its content
|
|
261
253
|
DispatchQueue.main.async {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
254
|
+
let animator = UIViewPropertyAnimator(
|
|
255
|
+
duration: Self.switchDuration,
|
|
256
|
+
controlPoint1: CGPoint(x: 0.25, y: 0.1),
|
|
257
|
+
controlPoint2: CGPoint(x: 0.25, y: 1)
|
|
258
|
+
) {
|
|
259
|
+
selected.host.view.transform = .identity
|
|
260
|
+
previous.host.view.transform = CGAffineTransform(translationX: -offset, y: 0)
|
|
261
|
+
}
|
|
262
|
+
animator.addCompletion { [weak self] _ in self?.leave(previous) }
|
|
263
|
+
animator.startAnimation()
|
|
267
264
|
}
|
|
268
265
|
}
|
|
269
266
|
|
|
270
267
|
private func makeTab(_ index: Int) -> Tab {
|
|
271
268
|
let tab = Tab()
|
|
272
|
-
let host = UIHostingController(rootView: rootView(index
|
|
269
|
+
let host = UIHostingController(rootView: rootView(index))
|
|
273
270
|
host.view.backgroundColor = .clear
|
|
274
271
|
addChild(host)
|
|
275
272
|
host.didMove(toParent: self)
|
|
@@ -278,14 +275,20 @@ private final class TabController: UIViewController {
|
|
|
278
275
|
return tab
|
|
279
276
|
}
|
|
280
277
|
|
|
281
|
-
private func rootView(_ index: Int
|
|
282
|
-
AnyView(
|
|
278
|
+
private func rootView(_ index: Int) -> AnyView {
|
|
279
|
+
AnyView(content(index).environment(\.self, environment))
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/// Bounds and center, not frame: a sliding tab carries a transform.
|
|
283
|
+
private func place(_ subview: UIView) {
|
|
284
|
+
subview.bounds = view.bounds
|
|
285
|
+
subview.center = CGPoint(x: view.bounds.midX, y: view.bounds.midY)
|
|
283
286
|
}
|
|
284
287
|
|
|
285
288
|
private func attach(_ tab: Tab) {
|
|
286
289
|
let hostView: UIView = tab.host.view
|
|
287
290
|
hostView.isUserInteractionEnabled = true
|
|
288
|
-
hostView
|
|
291
|
+
place(hostView)
|
|
289
292
|
if hostView.superview === view {
|
|
290
293
|
view.bringSubviewToFront(hostView)
|
|
291
294
|
} else {
|
|
@@ -297,6 +300,7 @@ private final class TabController: UIViewController {
|
|
|
297
300
|
private func leave(_ tab: Tab) {
|
|
298
301
|
guard selectedIndex.flatMap({ tabs[$0] }) !== tab else { return }
|
|
299
302
|
tab.host.view.removeFromSuperview()
|
|
303
|
+
tab.host.view.transform = .identity
|
|
300
304
|
}
|
|
301
305
|
|
|
302
306
|
private func tearDown(_ tab: Tab) {
|
|
@@ -306,27 +310,8 @@ private final class TabController: UIViewController {
|
|
|
306
310
|
}
|
|
307
311
|
}
|
|
308
312
|
|
|
309
|
-
private final class TabMotion: ObservableObject {
|
|
310
|
-
@Published var visible = false
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/// The tab switch: 0.97 scale + fade over 200ms, both ways (Compose's tab enter / exit transitions).
|
|
314
|
-
private struct TabCard: View {
|
|
315
|
-
@ObservedObject var motion: TabMotion
|
|
316
|
-
let content: AnyView
|
|
317
|
-
|
|
318
|
-
var body: some View {
|
|
319
|
-
content
|
|
320
|
-
.opacity(motion.visible ? 1 : 0)
|
|
321
|
-
.scaleEffect(motion.visible ? 1 : 0.97)
|
|
322
|
-
.animation(.easeInOut(duration: 0.2), value: motion.visible)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
/// Bottom safe-area inset (home indicator).
|
|
327
313
|
private func safeAreaBottomInset() -> CGFloat {
|
|
328
|
-
|
|
314
|
+
UIApplication.shared.connectedScenes
|
|
329
315
|
.compactMap { ($0 as? UIWindowScene)?.keyWindow?.safeAreaInsets.bottom }
|
|
330
316
|
.first ?? 0
|
|
331
|
-
return min(bottomInset, 21)
|
|
332
317
|
}
|