From ecd36e087822c3563a02f3cff4c336a88380611d Mon Sep 17 00:00:00 2001 From: Abe White Date: Wed, 30 Oct 2024 13:41:44 -0500 Subject: [PATCH] .toolbarBackground(.visible) should cause background to always be visible, even when no content is scrolled beneath --- Sources/SkipUI/SkipUI/Containers/Navigation.swift | 11 ++++++----- Sources/SkipUI/SkipUI/Containers/TabView.swift | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Sources/SkipUI/SkipUI/Containers/Navigation.swift b/Sources/SkipUI/SkipUI/Containers/Navigation.swift index 88407790..26d66a66 100644 --- a/Sources/SkipUI/SkipUI/Containers/Navigation.swift +++ b/Sources/SkipUI/SkipUI/Containers/Navigation.swift @@ -313,8 +313,9 @@ public struct NavigationStack : View where Root: View { topBarModifier = topBarModifier.background(topBarBackgroundBrush) } } + let alwaysShowScrolledBackground = topBarPreferences?.backgroundVisibility == Visibility.visible let topBarColors = TopAppBarDefaults.topAppBarColors( - containerColor: unscrolledTopBarBackgroundColor, + containerColor: alwaysShowScrolledBackground ? topBarBackgroundColor : unscrolledTopBarBackgroundColor, scrolledContainerColor: topBarBackgroundColor, titleContentColor: MaterialTheme.colorScheme.onSurface ) @@ -388,9 +389,9 @@ public struct NavigationStack : View where Root: View { return } - let canScrollForward = bottomBarPreferences?.scrollableState.canScrollForward == true + let showScrolledBackground = bottomBarPreferences?.backgroundVisibility == Visibility.visible || bottomBarPreferences?.scrollableState.canScrollForward == true let materialColorScheme: androidx.compose.material3.ColorScheme - if canScrollForward, let customColorScheme = bottomBarPreferences?.colorScheme?.asMaterialTheme() { + if showScrolledBackground, let customColorScheme = bottomBarPreferences?.colorScheme?.asMaterialTheme() { materialColorScheme = customColorScheme } else { materialColorScheme = MaterialTheme.colorScheme @@ -434,7 +435,7 @@ public struct NavigationStack : View where Root: View { bottomBarHeightPx.value = bounds.bottom - bounds.top } } - if canScrollForward, let bottomBarBackgroundForBrush { + if showScrolledBackground, let bottomBarBackgroundForBrush { if let bottomBarBackgroundBrush = bottomBarBackgroundForBrush.asBrush(opacity: 1.0, animationContext: nil) { bottomBarModifier = bottomBarModifier.background(bottomBarBackgroundBrush) } @@ -442,7 +443,7 @@ public struct NavigationStack : View where Root: View { // Pull the bottom bar below the keyboard let bottomPadding = with(density) { min(bottomBarHeightPx.value, Float(WindowInsets.ime.getBottom(density))).toDp() } PaddingLayout(padding: EdgeInsets(top: 0.0, leading: 0.0, bottom: Double(-bottomPadding.value), trailing: 0.0), context: context.content()) { context in - let containerColor = canScrollForward ? bottomBarBackgroundColor : unscrolledBottomBarBackgroundColor + let containerColor = showScrolledBackground ? bottomBarBackgroundColor : unscrolledBottomBarBackgroundColor let windowInsets = EnvironmentValues.shared._isEdgeToEdge == true ? BottomAppBarDefaults.windowInsets : WindowInsets(bottom: 0.dp) var options = Material3BottomAppBarOptions(modifier: context.modifier.then(bottomBarModifier), containerColor: containerColor, contentColor: MaterialTheme.colorScheme.contentColorFor(containerColor), contentPadding: PaddingValues.Absolute(left: 16.dp, right: 16.dp)) if let updateOptions = EnvironmentValues.shared._material3BottomAppBar { diff --git a/Sources/SkipUI/SkipUI/Containers/TabView.swift b/Sources/SkipUI/SkipUI/Containers/TabView.swift index 184bd8ff..3b6b7d57 100644 --- a/Sources/SkipUI/SkipUI/Containers/TabView.swift +++ b/Sources/SkipUI/SkipUI/Containers/TabView.swift @@ -129,9 +129,9 @@ public struct TabView : View { let tint = EnvironmentValues.shared._tint let hasColorScheme = reducedTabBarPreferences.colorScheme != nil let isSystemBackground = reducedTabBarPreferences.isSystemBackground == true - let canScrollForward = reducedTabBarPreferences.scrollableState?.canScrollForward == true + let showScrolledBackground = reducedTabBarPreferences.backgroundVisibility == Visibility.visible || reducedTabBarPreferences.scrollableState?.canScrollForward == true let materialColorScheme: androidx.compose.material3.ColorScheme - if canScrollForward, let customColorScheme = reducedTabBarPreferences.colorScheme?.asMaterialTheme() { + if showScrolledBackground, let customColorScheme = reducedTabBarPreferences.colorScheme?.asMaterialTheme() { materialColorScheme = customColorScheme } else { materialColorScheme = MaterialTheme.colorScheme @@ -173,7 +173,7 @@ public struct TabView : View { tabBarItemColors = NavigationBarItemDefaults.colors(indicatorColor: indicatorColor) } } - if canScrollForward, let tabBarBackgroundForBrush { + if showScrolledBackground, let tabBarBackgroundForBrush { if let tabBarBackgroundBrush = tabBarBackgroundForBrush.asBrush(opacity: 1.0, animationContext: nil) { tabBarModifier = tabBarModifier.background(tabBarBackgroundBrush) } @@ -184,7 +184,7 @@ public struct TabView : View { let bottomPadding = with(density) { min(bottomBarHeightPx.value, Float(WindowInsets.ime.getBottom(density))).toDp() } PaddingLayout(padding: EdgeInsets(top: 0.0, leading: 0.0, bottom: Double(-bottomPadding.value), trailing: 0.0), context: context.content()) { context in let tabItemsState = rememberUpdatedState(tabItems) - let containerColor = canScrollForward ? tabBarBackgroundColor : unscrolledTabBarBackgroundColor + let containerColor = showScrolledBackground ? tabBarBackgroundColor : unscrolledTabBarBackgroundColor let onItemClick: (Int) -> Void = { tabIndex in let route = String(describing: tabIndex) if let selection, let tagValue = tagValue(route: route, in: tabViews) {