-
Notifications
You must be signed in to change notification settings - Fork 170
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 CustomAnimationConvertible #12
base: master
Are you sure you want to change the base?
Conversation
@marlimox Take care. Please take a look at this pr. If you do not like the approach to new features, please give me another comment! :) |
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.
Hi @ParkGwangBeom, I am so sorry for the very slow review of this PR! I apologize 😔 I have been busy traveling, but I have finally had a moment to review it. It looks great, thank you for this contribution!
I agree that this will be useful functionality to have and it shouldn’t complicate the implemention of AloeStackView too much. I have some comments that I hope might simplify the implementation further. Please take a look when you get the chance and let me know what you think.
Thanks again for your great contributions to AloeStackView! You have contributed some really great work 😊
Example/AloeStackViewExample/ViewControllers/MainViewController.swift
Outdated
Show resolved
Hide resolved
Sources/AloeStackView/Protocols/CustomAnimationConvertible.swift
Outdated
Show resolved
Hide resolved
/** | ||
* An object that animates when the Row is inserted and deleted from the AloeStackView. | ||
*/ | ||
public class AnimationCoordinator { |
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 would like to simplify this implementation by potentially changing how this works. Rather than passing an AnimationCoordinator
into the row view, what if instead the custom animating protocol had methods such as:
func animateInsert()
func animateRemove()
These methods would be called from inside the animation block when the row insertion or removal happens. The view can make any changes it wants inside these methods and the changes will be animated.
Additionally, we could add some methods to the custom animating protocol to allow for the initial state to be configured before the animation, and to perform actions after the animation completes, for example:
func willAnimateInsert()
func didAnimateInsert()
func willAnimateRemove()
func didAnimateRemove()
You could then implement custom animations by doing something like:
func willAnimateInsert() {
transform = CGAffineTransform(translationX: -100, y: 0)
}
func animateInsert() {
transform = .identity
}
I think this could be a lot simpler and clearer. Let me know what you think of this approach.
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.
Thank you for your feedback.
I also implemented it early on through the above approach.
If you implement it in the above way, there will be an advantage that the function name makes meaning clear.
But there are too many functions inside the protocol.
So to simplify this, I thought about the viewWillTransition function which is the api of UIVIewController.
Please tell me your thoughts on my opinion.
Thank you!
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.
Yes you’re right, it does create too many functions in the protocol.
My plan to address that was to add a protocol extension with empty definitions for every function. That way views only need to implement the specific functions they care about and don’t need to implement every function.
For example:
extension CustomAnimating {
func willAnimateInsert() { }
func animateInsert() { }
func didAnimateInsert() { }
...
}
I think this will give the best of both worlds. It also has the advantage that we can add more custom animation methods in the future, for example we can add methods for customizing show and hide animations, without having one big animation method in every view.
I also updated the names of their methods in my previous comments to better match the UIKit will/did naming convention.
Let me know what you think!
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.
Listening to you, I think it makes sense! 👍
protocol CustomAnimating {
func insertAnimationWillBegin()
func animateInsert()
func insertAnimationDidEnd(_ completed: Bool)
...
}
What do you think about naming such a thing?
I want to hear your thoughts.
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.
Yes, great suggestion! I like it much better 😄
Perhaps it might be easier to understand if we put the protocol methods in this order:
protocol CustomAnimating {
/// ...
func animateInsert()
/// ...
func insertAnimationWillBegin()
/// ...
func insertAnimationDidEnd(_ finished: Bool)
...
}
That way people will see the most important method in the protocol first (the one they need to implement to perform the custom animation).
Also, perhaps the argument to insertAnimationDidEnd
should be named finished
rather than completed
so that it matches the name UIKit uses in animate(withDuration:animations:completion:)
(the completion
callback takes an argument named finished
).
Let me know your thoughts!
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 agree with your thoughts. 👍
@marlimox Thank you for your detailed review. We have edited except for the last review. |
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.
Looks good. I’ve added a few more comments, please take a look.
label.numberOfLines = 0 | ||
label.text = "This simple app shows some ways you can use AloeStackView to lay out a screen in your app." | ||
stackView.addRow(label) | ||
let descriptionRow = TitleCaptionRow(title: "This simple app shows some ways you can use AloeStackView to lay out a screen in your app.") |
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.
👌
Thanks for fixing this up!
|
||
// MARK: Private | ||
|
||
private let title: String |
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.
You shouldn’t need to store these, just set the text properties on the labels directly.
} | ||
|
||
private func setUpCaptionLabel() { | ||
guard let captionText = captionText else { return } |
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.
guard captionLabel.text != nil else { return }
|
||
// MARK: Lifecycle | ||
|
||
public init(title: String, captionText: String? = nil) { |
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.
Naming: titleText
self.title = title | ||
self.captionText = captionText | ||
super.init(frame: .zero) | ||
setUpSelf() |
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.
Call this from setUpViews
.
@@ -41,16 +41,15 @@ public class MainViewController: AloeStackViewController { | |||
setUpDescriptionRow() | |||
setUpSwitchRow() | |||
setUpHiddenRows() | |||
setUpCustomAnimatingDescRow() |
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.
Naming: setUpCustomAnimatingDescriptionRow
.
@@ -41,16 +41,15 @@ public class MainViewController: AloeStackViewController { | |||
setUpDescriptionRow() | |||
setUpSwitchRow() | |||
setUpHiddenRows() | |||
setUpCustomAnimatingDescRow() | |||
setUpHiddenAnimatableRow() |
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.
Naming: setUpCustomAnimatingRow
.
stackView.addRow(animatableRow) | ||
stackView.setTapHandler(forRow: animatableRow) { [weak self] _ in | ||
guard let `self` = self else { return } | ||
let isHidden = self.stackView.isRowHidden(self.animatableHiddenLabel) |
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.
Style: indent back two spaces.
} | ||
} | ||
|
||
private let animatableHiddenLabel = CustomAnimatingLabel() |
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.
Naming: customAnimatingLabel
.
@@ -0,0 +1,27 @@ | |||
// Created by gwangbeom on 10/29/18. |
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.
Rename this file to CustomAnimating.swift
.
@marlimox We reflected your review. |
@marlimox |
No problem @ParkGwangBeom! Whenever you get the time 😄 |
@ParkGwangBeom @marlimox Insert animations are also a requirement for me - what's the current status of this PR? Is there anything I/we/anyone else can do that can help it along? |
559c184
to
783700a
Compare
@marlimox Rebases were performed, and additional reviews were reflected. :) |
@apang42 Hello, When will this pull request become a merge? |
Hey @ParkGwangBeom so sorry for the delay on this issue, we'll address this as soon as we can! |
f9277bd
to
d910c99
Compare
@apang42 I resolved the conflict. |
@apang42 @marlimox @aloestackview-admin |
Hi. I added the animation feature that I mentioned in the issue. (#10)
The gif below is a simple example.
If you use the newly added Animation feature, you will be able to customize the animation to be more extensible on its own line.
tell me your opinions.
Thank you.