Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Sources/SkipUI/SkipUI/Containers/LazyVGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<ScrollPositionState?>(nil) }
Expand Down
16 changes: 8 additions & 8 deletions Sources/SkipUI/SkipUI/Containers/LazyVStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<ScrollPositionState?>(nil) }
Expand Down
8 changes: 4 additions & 4 deletions Sources/SkipUI/SkipUI/Containers/ScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down