Closed sasquatchgit closed 5 years ago
@k3street Thanks, but I already went through this in Readme.md. And I am looking for an example on how to get 'cardClicked' callback and fire my custom event on click.
I wasn’t trying to be a jerk, the base class has a cardtapped function that is accessible when you instantiate the class and a long press tap gesture recognizer.
Get Outlook for iOShttps://aka.ms/o0ukef
From: Saurabh notifications@github.com
Sent: Tuesday, February 5, 2019 9:28 PM
To: intuit/CardParts
Cc: Kimate Richards; Mention
Subject: Re: [intuit/CardParts] How do I get cardClicked
callback? (#110)
@k3streethttps://github.com/k3street Thanks, but I already went through this in Readme.md. And I am looking for an example on how to get 'cardClicked' callback and fire my custom event on click.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/intuit/CardParts/issues/110#issuecomment-460905515, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABCNzluGu9usN70gLwOx7ft58DV1S9Fhks5vKmfigaJpZM4acSaf.
Hey @k3street , sorry if it came that way. I was trying to say that I am noob, and even after reading the readme, I wasn't able to figure how to use it. I would be really thankful if someone could put an example on how to achieve it. And thanks for taking your time and trying to help me.
Should I override the function to use it?
Thank you @k3street for trying to explain, much appreciated!
@sasquatchgit If you take a look at Clickable Cards documentation you can see how we achieve that! So in your CardViewController you just simply need to add:
self.cardTapped(forState: .empty) {
print("Card was tapped in .empty state!")
}
self.cardTapped(forState: .hasData) {
print("Card was tapped in .hasData state!")
}
// The default state for setupCardParts([]) is .none
self.cardTapped {
print("Card was tapped in .none state")
}
and then those handlers will be called! Please feel free to reopen if that does not answer your question.
Clickable Cards You have the ability to add a tap action for each state of any given card. If a part of the card is clicked, the given action will be fired:
self.cardTapped(forState: .empty) { print("Card was tapped in .empty state!") }
self.cardTapped(forState: .hasData) { print("Card was tapped in .hasData state!") }
// The default state for setupCardParts([]) is .none self.cardTapped { print("Card was tapped in .none state") } Note: It is always a good idea to weakify self in a closure:
{[weak self] in
} Listeners CardParts also supports a listener that allows you to listen to visibility changes in the cards that you have created. In your CardPartsViewController you may implement the CardVisibilityDelegate to gain insight into the visibility of your card within the CardsViewController you have created. This optional delegate can be implemented as follows:
public class YourCardPartsViewController: CardPartsViewController, CardVisibilityDelegate { ...
} Delegates Any view controller which is a subclass of CardPartsViewController supports gesture delegate for long press on the view. Just need to conform your controller to CardPartsLongPressGestureRecognizerDelegate protocol.
When the view is long pressed didLongPress(_:) will be called where you can custom handle the gesture. Example: Zoom in and Zoom out on gesture state begin/ended.
You can set the minimumPressDuration for your press to register as gesture began. The value is in seconds. default is set to 1 second.
Example:
extension MYOwnCardPartController: CardPartsLongGestureRecognizerDelegate { func didLongPress(_ gesture: UILongPressGestureRecognizer) { guard let v = gesture.view else { return }
}