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 CustomAnimationConvertible #12

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ParkGwangBeom
Copy link

@ParkGwangBeom ParkGwangBeom commented Oct 29, 2018

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.

ani

@ParkGwangBeom ParkGwangBeom changed the title Feature/animatable Add CustomAnimationConvertible Oct 29, 2018
@ParkGwangBeom
Copy link
Author

@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! :)

Copy link
Owner

@marlimox marlimox left a 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 😊

/**
* An object that animates when the Row is inserted and deleted from the AloeStackView.
*/
public class AnimationCoordinator {
Copy link
Owner

@marlimox marlimox Nov 11, 2018

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.

Copy link
Author

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!

Copy link
Owner

@marlimox marlimox Nov 12, 2018

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!

Copy link
Author

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.

Copy link
Owner

@marlimox marlimox Nov 13, 2018

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!

Copy link
Author

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. 👍

@ParkGwangBeom
Copy link
Author

@marlimox Thank you for your detailed review. We have edited except for the last review.
The fix for CustomAnimating protocol would like to hear more from you!
Thank you.

Copy link
Owner

@marlimox marlimox left a 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.")
Copy link
Owner

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
Copy link
Owner

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 }
Copy link
Owner

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) {
Copy link
Owner

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()
Copy link
Owner

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()
Copy link
Owner

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()
Copy link
Owner

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)
Copy link
Owner

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()
Copy link
Owner

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.
Copy link
Owner

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.

@ParkGwangBeom
Copy link
Author

@marlimox We reflected your review.
I would like to talk more about the function of CustomAnimating. :)

@ParkGwangBeom
Copy link
Author

@marlimox
Hi. The company was busy for a while, so I could not get additional PR.
I will post additional PR soon.
Thank you.

@marlimox
Copy link
Owner

No problem @ParkGwangBeom! Whenever you get the time 😄

@gbrhaz
Copy link

gbrhaz commented Jan 29, 2019

@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?

@ParkGwangBeom
Copy link
Author

@marlimox @gbrhaz
Sorry. The busy project schedule is over. I will finish the remaining pr during next week. :)

@ParkGwangBeom
Copy link
Author

@marlimox Rebases were performed, and additional reviews were reflected. :)

@ParkGwangBeom
Copy link
Author

@apang42 Hello, When will this pull request become a merge?

@apang42
Copy link
Collaborator

apang42 commented Jul 18, 2019

Hey @ParkGwangBeom so sorry for the delay on this issue, we'll address this as soon as we can!

@ParkGwangBeom
Copy link
Author

@apang42 I resolved the conflict.

@ParkGwangBeom
Copy link
Author

@apang42 @marlimox @aloestackview-admin
When will this pull request be merged?

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.

5 participants