-
Notifications
You must be signed in to change notification settings - Fork 87
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 ability to receive UITableViewDelegate & UIScrollViewDelegate messages from UITableView #119
Conversation
…ve UITableViewDelegate & UIScrollViewDelegate messages from the UITableView. Forward didSelectRow and accessoryButtonTappedForRowWith messages to tableViewDelegate property. Bump version from 2.2.0 to 2.3.0
@@ -1,6 +1,6 @@ | |||
Pod::Spec.new do |spec| | |||
spec.name = 'Static' | |||
spec.version = '2.2.0' | |||
spec.version = '2.3.0' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this a breaking change? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, bro. I don't know what Venmo uses for CocoaPods, but I assumed Semantic Versioning: https://semver.org/
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahhh, you right you right.
@@ -275,12 +293,16 @@ extension DataSource: UITableViewDelegate { | |||
if let row = row(at: indexPath) { | |||
row.selection?() | |||
} | |||
|
|||
tableViewDelegate?.tableView?(tableView, didSelectRowAt: indexPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this needed if we have the forwarding target?.. wouldn't it send this there anyway?.. I may be misunderstanding forwardingTarget...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since DataSource
implements this method, it gets the message sent to it, and thus it doesn't go to the forwardingTarget.
Messages only get forwarded to the forwardingTarget if this object doesn't implement.
This is great! If merged I would be able to delete a lot of hacks and even my custom Static branch |
Oh heck yeah! This looks great, awesome usage of selector forwarding. It might be a bit of overhead to ensure that each method we implement needs to call down to Sent with GitHawk |
I’m using to forward scrollViewDidScroll and it seems fine. But I’m a little worried too. Any thoughts on how to measure the impact? Sent with GitHawk |
@txaiwieser He was referring to the cognitive impact of remembering / deciding whether or not to forward the I wouldn't worry about performance implications. This is an old API, available since iOS 2.0. If you put some logs in the forwardTarget functions you will see that they don't get called often. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work. 💯
Even better would be to add a blurb about this to the README (since those are kind of our docs), but I won't block the PR since we can add that after the fact anyway!
Thanks a ton for doing this, @jaredegan!
Would anyone else like to take a look over this? I'm good with merging it in, since it seems fairly low risk and gives us a fairly sought after feature, but I'd be great to get some more eyes on it! |
} | ||
|
||
// MARK: - UITableViewDelegate example functions | ||
public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see this item being useful...
But didSelect is covered as part of Static closure handling, and scrollViewWillBeginDragging can be observed with a observer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functions here are not comprehensive regarding what methods will get forwarded, they are just meant to demonstrate this functionality. They all get forwarded, including any potential future UIScrollViewDelegate
functions. The only ones that do not are the ones that Static handles completely where it doesn't make sense to forward.
I don't think all UIScrollViewDelegate
methods can be handled with observers. Developers are more familiar with UIScrollViewDelegate
& UITableViewDelegate
methods than they are with observing those same changes. This is why Static has at least 3 tickets around requesting this functionality. If the code only forwarded the calls that can't be done with observers, that would obviously create more confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
understood
Hey guys, when can we have a release with this PR? So we could stop using "master" on carthage |
@txaiwieser Ask and ye shall receive: https://github.com/venmo/Static/releases/tag/v2.3.0 Sorry we didn't do this sooner! |
@eliperkins Thanks!!! :D |
Using Static for your table view solutions previously caused some limitations for certain use cases. Since the
DataSource
object is both thedataSource
&delegate
of theUITableView
instance, users of the Static library were unable to receive theUITableViewDelegate
methods they might need to do things like reacting to scrolling, header displays or any further actions.This change introduces a new
weak
property onDataSource
:tableViewDelegate
. This needs to be set during init, due to the execution timing offorwardingTarget
&respondsToSelector
. Using those two methods, the unimplementedUITableViewDelegate
methods can get forwarded to the delegate that the user specifies, unlocking this missing functionality, mentioned in #97, #78, #72.Two already implemented
UITableViewDelegate
functions will also forward the message to thetableViewDelegate
property (if it implements those methods). The other remaining function's behavior is already fully exposed by Static, so it didn't need to be changed.Other notes about this change/PR:
ViewController
class modified to include example of this functionality.