diff --git a/Sources/SkipUI/SkipUI/Containers/LazyVGrid.swift b/Sources/SkipUI/SkipUI/Containers/LazyVGrid.swift index 1e4e2fbe..25c4dcfa 100644 --- a/Sources/SkipUI/SkipUI/Containers/LazyVGrid.swift +++ b/Sources/SkipUI/SkipUI/Containers/LazyVGrid.swift @@ -76,11 +76,15 @@ public struct LazyVGrid: View, Renderable { let renderables = content.EvaluateLazyItems(level: 0, context: context) let itemCollector = remember { mutableStateOf(LazyItemCollector()) } ComposeContainer(axis: .vertical, scrollAxes: scrollAxes, modifier: context.modifier, fillWidth: true) { modifier in - IgnoresSafeAreaLayout(expandInto: [], checkEdges: [.bottom], modifier: modifier, logTag: "LazyVGrid") { _, safeAreaEdges in + let gridState = rememberLazyGridState(initialFirstVisibleItemIndex = isSearchable ? 1 : 0) + let flingBehavior = scrollTargetBehavior is ViewAlignedScrollTargetBehavior ? rememberSnapFlingBehavior(gridState, SnapPosition.Start) : ScrollableDefaults.flingBehavior() + let coroutineScope = rememberCoroutineScope() + if scrollAxes.contains(Axis.Set.vertical) { + PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: gridState, for: [ToolbarPlacement.bottomBar])) + PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: gridState)) + } + IgnoresSafeAreaLayout(expandInto: [], checkEdges: [.bottom], modifier: modifier, logTag: "LazyVGrid") { _, _ in // Integrate with our scroll-to-top and ScrollViewReader - let gridState = rememberLazyGridState(initialFirstVisibleItemIndex = isSearchable ? 1 : 0) - let flingBehavior = scrollTargetBehavior is ViewAlignedScrollTargetBehavior ? rememberSnapFlingBehavior(gridState, SnapPosition.Start) : ScrollableDefaults.flingBehavior() - let coroutineScope = rememberCoroutineScope() PreferenceValues.shared.contribute(context: context, key: ScrollToTopPreferenceKey.self, value: ScrollToTopAction(key: gridState) { coroutineScope.launch { gridState.animateScrollToItem(0) @@ -98,10 +102,6 @@ public struct LazyVGrid: View, Renderable { } } PreferenceValues.shared.contribute(context: context, key: ScrollToIDPreferenceKey.self, value: scrollToID) - if safeAreaEdges.contains(Edge.Set.bottom) { - PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: gridState, for: [ToolbarPlacement.bottomBar])) - PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: gridState)) - } // Observe scroll position changes and contribute them via preferences let scrollPositionState = remember { mutableStateOf(nil) } diff --git a/Sources/SkipUI/SkipUI/Containers/LazyVStack.swift b/Sources/SkipUI/SkipUI/Containers/LazyVStack.swift index 8d751dd8..5e15c40a 100644 --- a/Sources/SkipUI/SkipUI/Containers/LazyVStack.swift +++ b/Sources/SkipUI/SkipUI/Containers/LazyVStack.swift @@ -69,11 +69,15 @@ public struct LazyVStack : View, Renderable { let renderables = content.EvaluateLazyItems(level: 0, context: context) let itemCollector = remember { mutableStateOf(LazyItemCollector()) } ComposeContainer(axis: .vertical, scrollAxes: scrollAxes, modifier: context.modifier, fillWidth: true) { modifier in - IgnoresSafeAreaLayout(expandInto: [], checkEdges: [.bottom], modifier: modifier, logTag: "LazyVStack") { _, safeAreaEdges in + let listState = rememberLazyListState(initialFirstVisibleItemIndex = isSearchable ? 1 : 0) + let flingBehavior = scrollTargetBehavior is ViewAlignedScrollTargetBehavior ? rememberSnapFlingBehavior(listState, SnapPosition.Start) : ScrollableDefaults.flingBehavior() + let coroutineScope = rememberCoroutineScope() + if scrollAxes.contains(Axis.Set.vertical) { + PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: listState, for: [ToolbarPlacement.bottomBar])) + PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: listState)) + } + IgnoresSafeAreaLayout(expandInto: [], checkEdges: [.bottom], modifier: modifier, logTag: "LazyVStack") { _, _ in // Integrate with our scroll-to-top and ScrollViewReader - let listState = rememberLazyListState(initialFirstVisibleItemIndex = isSearchable ? 1 : 0) - let flingBehavior = scrollTargetBehavior is ViewAlignedScrollTargetBehavior ? rememberSnapFlingBehavior(listState, SnapPosition.Start) : ScrollableDefaults.flingBehavior() - let coroutineScope = rememberCoroutineScope() PreferenceValues.shared.contribute(context: context, key: ScrollToTopPreferenceKey.self, value: ScrollToTopAction(key: listState) { coroutineScope.launch { listState.animateScrollToItem(0) @@ -91,10 +95,6 @@ public struct LazyVStack : View, Renderable { } } PreferenceValues.shared.contribute(context: context, key: ScrollToIDPreferenceKey.self, value: scrollToID) - if safeAreaEdges.contains(Edge.Set.bottom) { - PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: listState, for: [ToolbarPlacement.bottomBar])) - PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: listState)) - } // Observe scroll position changes and contribute them via preferences let scrollPositionState = remember { mutableStateOf(nil) } diff --git a/Sources/SkipUI/SkipUI/Containers/ScrollView.swift b/Sources/SkipUI/SkipUI/Containers/ScrollView.swift index 93004915..eca06680 100644 --- a/Sources/SkipUI/SkipUI/Containers/ScrollView.swift +++ b/Sources/SkipUI/SkipUI/Containers/ScrollView.swift @@ -80,14 +80,14 @@ public struct ScrollView : View, Renderable { let contentContext = context.content() ComposeContainer(scrollAxes: effectiveScrollAxes, modifier: context.modifier, fillWidth: axes.contains(.horizontal), fillHeight: axes.contains(.vertical)) { modifier in + if wantsVerticalScroll && !isScrollDisabled { + PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: scrollState, for: [ToolbarPlacement.bottomBar])) + PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: scrollState)) + } IgnoresSafeAreaLayout(expandInto: [], checkEdges: [.bottom], modifier: modifier, logTag: "ScrollView") { _, safeAreaEdges in var containerModifier: Modifier = Modifier if wantsVerticalScroll { containerModifier = containerModifier.fillMaxHeight() - if !isScrollDisabled && safeAreaEdges.contains(Edge.Set.bottom) { - PreferenceValues.shared.contribute(context: context, key: ToolbarPreferenceKey.self, value: ToolbarPreferences(scrollableState: scrollState, for: [ToolbarPlacement.bottomBar])) - PreferenceValues.shared.contribute(context: context, key: TabBarPreferenceKey.self, value: ToolbarBarPreferences(scrollableState: scrollState)) - } } if wantsHorizontalScroll { containerModifier = containerModifier.fillMaxWidth()