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

Adding @State to trigger indications of swipe #13

Closed
Dave181295 opened this issue Mar 24, 2023 · 2 comments
Closed

Adding @State to trigger indications of swipe #13

Dave181295 opened this issue Mar 24, 2023 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@Dave181295
Copy link

Dave181295 commented Mar 24, 2023

Thanks for the lib, it would be Nice to trigger a UI element for the swipe behavior of any rows by passing a bool state ,
like the EditButton from the original List, this will help as the user for now doesn't know if he can swipe any cell.

@c-villain
Copy link
Owner

c-villain commented May 14, 2023

Hi, @Dave181295 ! Thx for your suggestion for improvement!
Actually, you may use smth like this:

import SwiftUI

public extension View {
    @ViewBuilder
    func swipeHint(_ isActive: Bool = false, hintOffset: CGFloat) -> some View {
        if isActive {
            modifier(SwipeHintModifier(hintOffset: hintOffset))
        } else {
            self
        }
    }
}

public struct SwipeHintModifier: ViewModifier {
    let hintOffset: CGFloat
    @State private var offset: CGFloat = 0
    
    public func body(content: Content) -> some View {
        content
            .offset(x: -offset)
            .onAppear {
                    withAnimation(.easeInOut.delay(0.3)) {
                        offset = hintOffset
                    }
                    withAnimation(.easeInOut.delay(1.3)) {
                        offset = 0
                    }
            }
    }
}

and add this modifier to our content, for example, like this way:

ForEach(range, ...) {
    YourCell()
        ...
        .addFullSwipeAction(
            menu: .slided,
            swipeColor: .red,
            state: $state) {
                Leading {
                    ...
                }
                Trailing {
                    ...
                }
            }
        .swipeHint(cell == range.first, hintOffset: 120.0) // for trailing
        .swipeHint(cell == range[1] , hintOffset: -120.0) // for leading
    ...
}

@c-villain
Copy link
Owner

added in 0.3.5

@c-villain c-villain self-assigned this Sep 9, 2024
@c-villain c-villain added the enhancement New feature or request label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants