Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllowSwipeToTrigger() does not work on newly added cells after fetching data #12

Open
ayelvs opened this issue Jul 30, 2023 · 4 comments

Comments

@ayelvs
Copy link

ayelvs commented Jul 30, 2023

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!

@aheze
Copy link
Owner

aheze commented Dec 19, 2023

Weird. Maybe something to do with VariadicView

@EProgressPro
Copy link

EProgressPro commented Dec 25, 2023

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: )

@itslewin
Copy link

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 

krisanthony added a commit to krisanthony/SwipeActions that referenced this issue Apr 2, 2024
@freak4pc
Copy link

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 :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants