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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to react to notification tap via new CRNotificationDelegate #26

Merged
merged 3 commits into from Sep 21, 2019

Conversation

sansha
Copy link
Contributor

@sansha sansha commented Jul 28, 2019

I think this is a neat little functionality expanding the cool & simple to use CRNotification! :)
It also does not change the API so it is backwards compatible, only if needed, a delegate can be set. It is also very simple to comply with the delegate.

If you want a more fancy feature, one could also include the text (or other information) of the notification in the delegate call.

As this is my first pull request on GitHub, please take a look and let me know if I need to improve something or if you don't like the feature 馃槃

@dkcas11
Copy link
Owner

dkcas11 commented Jul 28, 2019

Hey, thanks for the PR!

I like the idea, and I guess the intention is that you want to execute the same piece of code in the completion handler, without duplicating the code - is that the case? If so, there is nothing stopping you from simply passing in a function instead of writing the same block each time. One could simply just pass in the same function as the one executed in the delegate.

Usually the purpose of the delegate is to handle some sort of value(s) passed to the function. Maybe the type, title and message could be passed along, so you can reach on the type of notification shown, whether it being a success, failure or something else.

Is that something you could add? 馃檪

@@ -164,6 +164,15 @@ public class CRNotificationView: UIView, CRNotification {
})
}

@objc internal func dismissNotificationOnTap() {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its fine to just reuse the current method dismissNotification and simply call the delegate, followed by the normal procedure. Otherwise you will have two different implementations of the dismiss functionality and one might not hide correctly 馃檪

Swift will just call the function on the delegate if it's there. There is no need to guard it.
Simply just write onClickDelegate?.onNotitificationTap() 馃檪

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I wrote below, I'd like to handle tapping on the notification differently than just sliding it away. Maybe it should be renamed to dismissNotification and tapNotification? or expandNotification even though this might suggest some more functionality.

Thank you for the Swift tip, you are right!

@@ -39,7 +39,7 @@ public class CRNotificationView: UIView, CRNotification {
}()

private var completion: () -> () = {}

public var onClickDelegate: CRNotificationDelegate?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this could just be called delegate? Then other behaviour might be added in the future, such as a swipe, manual hiding or even buttons below the text. As such we are no longer limited by the name. I was thinking to add two small reaction buttons at the bottom. Then that button can be forwarded here, too 馃檪

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, calling it delegate sounds good!

@sansha
Copy link
Contributor Author

sansha commented Sep 11, 2019

Hey, thank you for the quick reply!
I'm really sorry that I forgot about this PR, that's why it took so long to respond.
Anyway, the idea was that you can tap on a notification to get more info, so we can present the user a non obstructing notification that she received a badge, and if she wants, she can tap on it to get more details (a full screen badge view for example).
Therefore it was not possible to implement this during the completion handler, as I only want to show more information when the user taps on it, not when the timer hides it or it is swiped away.

add parameters to delegate
rename delegate
remove guard statement
@dkcas11
Copy link
Owner

dkcas11 commented Sep 21, 2019

Sorry for the delay on the review, I've been a little busy. Looks good! 馃檪

@dkcas11
Copy link
Owner

dkcas11 commented Sep 21, 2019

If there is nothing more you'd like to do on this PR I will merge it 馃憤

@sansha
Copy link
Contributor Author

sansha commented Sep 21, 2019

Thank you! :)
No you can merge it.

@dkcas11 dkcas11 merged commit f562c1d into dkcas11:master Sep 21, 2019
@dkcas11
Copy link
Owner

dkcas11 commented Sep 21, 2019

Its now in master as 1.2.1. Thanks for the contribution 馃殌 馃檪

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

Successfully merging this pull request may close these issues.

None yet

2 participants