AllowSwipeToTrigger() does not work on newly added cells after fetching data
ayelvs opened this issue · 4 comments
I'm implementing infinite pagination scrolling, where I have to fetch new data and draws the new cells in a ScrollView (in a LazyVStack). For some reason, the allowSwipetoTrigger modifier doesn't apply to new cells being added to the list.
Anyone has any insight why that might be the case? Thanks!
Weird. Maybe something to do with VariadicView
Temporarily solution, hope this helps.
ISSUE:
AllowSwipeToTriggerKey not working as expected when using LazyVStack + ScrollView,
swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge always false after fetch new data.
SOLUTION:
Manually set swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge in SwipeView.
// 1.replace `@State var swipeToTriggerLeadingEdge/swipeToTriggerTrailingEdge` with:
public struct SwipeOptions {
var swipeToTriggerLeadingEdge = false
var swipeToTriggerTrailingEdge = false
}
public extension SwipeView {
func swipeToTrigger(leading: Bool, trailing: Bool) -> SwipeView {
var view = self
view.options.swipeToTriggerLeadingEdge = leading
view.options.swipeToTriggerTrailingEdge = trailing
return view
}
}
// 2.manually enable/disable
SwipeView {
} leadingActions: { context in
} trailingActions: { context in
}
.swipeToTrigger(leading: , trailing: )
Having the same problem, in a ScrollView-LazyVStack-ForEach construction.
I tried to get @EProgressPro's solution to work, but it somehow broke other functionality for me.
Since my usecase is fairly simple, just having one SwipeAction for each direction, is just changed the default to true:
@State var swipeToTriggerLeadingEdge = true
@State var swipeToTriggerTrailingEdge = true
Indeed happening here as well - something is causing the preference key to reset back to the default (probably some identity change). Wasn't able to figure it out as well but it's easily reproducible :(