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

Add willShow notification to Drop presentation #24

Closed
wants to merge 2 commits into from

Conversation

ky1vstar
Copy link
Contributor

Hi! This PR adds optional willShow parameter to Drops.show(_:) method to notify user that Drop is about to appear. I.e. it can be used to provide haptic feedback like it is done in SPIndicator, but since Drops are automatically enqueued, now it's impossible to say when you should send such feedback.

@omaralbeik
Copy link
Owner

Nice one, I was actually thinking of adding this to the Drops class instead, what do you think?

public final class Drops {
    public typealias DropHandler = (Drop) -> Void

    public static var willShowDrop: DropHandler? {
        get { return shared.willShowDrop }
        set { shared.willShowDrop = newValue }
    }

    public static var didShowDrop: DropHandler? {
        get { return Drops.shared.didShowDrop }
        set { shared.didShowDrop = newValue }
    }

    public static var willDismissDrop: DropHandler? {
        get { return shared.willDismissDrop }
        set { shared.willDismissDrop = newValue }
    }

    public static var didDismissDrop: DropHandler? {
        get { return shared.didDismissDrop }
        set { shared.didDismissDrop = newValue }
    }

    // MARK: - Instance

    public var willShowDrop: DropHandler?
    public var didShowDrop: DropHandler?
    public var willDismissDrop: DropHandler?
    public var didDismissDrop: DropHandler?
}

Usage examples:

Show haptic feedback before showing:

Drops.willShowDrop = { _ in
    // Show haptic feedback
}

Show an infinite counter :)

Drops.didDismissDrop = { drop in
    let number = Int(drop.title) ?? 0
    Drops.show(.init(title: "\(number + 1)"))
}

@omaralbeik omaralbeik added the enhancement New feature or request label Sep 11, 2021
This was referenced Oct 13, 2021
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

Successfully merging this pull request may close these issues.

None yet

2 participants