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

Improve macOS implementation and minor improvement to the shared components. #52

Merged
merged 3 commits into from
Aug 28, 2017

Conversation

zenangst
Copy link
Contributor

Set wantsLayer to true before trying to add an animation

On macOS, layers are optional, so with the current implementation we
assume that it is always there which is a wrong assumption. To fix this
issue, we now set wantsLayer to true before adding the animation.

Setting the value of this property to true turns the view into a
layer-backed view—that is, the view uses a CALayer object to manage its
rendered content. Creating a layer-backed view implicitly causes the
entire view hierarchy under that view to become layer-backed. Thus, the
view and all of its subviews (including subviews of subviews) become
layer-backed. The default value of this property is false.

Use transition closure instead of setting the image
Setting the image again can cause the view to blink as it will render
the image on screen because the layer needs updating. By piggy backing
on transitionClosure, it will animate from one image to another, but
only if the old image exists. If the image view has no image, it will
simply assign the image to self as the previous implementation did.

Opt-out from setting the image again if the window is resizing.

On macOS, layers are optional, so with the current implementation we
assume that it is always there which is a wrong assumption. To fix this
issue, we now set `wantsLayer` to `true` before adding the animation.

```
Setting the value of this property to true turns the view into a
layer-backed view—that is, the view uses a CALayer object to manage its
rendered content. Creating a layer-backed view implicitly causes the
entire view hierarchy under that view to become layer-backed. Thus, the
view and all of its subviews (including subviews of subviews) become
layer-backed. The default value of this property is false.
```
Setting the image again can cause the view to blink as it will render
the image on screen because the layer needs updating. By piggy backing
on `transitionClosure`, it will animate from one image to another, but
only if the old image exists. If the image view has no image, it will
simply assign the image to self as the previous implementation did.
@zenangst zenangst changed the title Improve macOs implementation and minor improvement to the shared components. Improve macOS implementation and minor improvement to the shared components. Aug 28, 2017
@@ -7,7 +7,7 @@ public extension Configuration {
}

public static var transitionClosure: ((NSImageView, NSImage) -> Void) = { imageView, newImage in
guard let oldImage = imageView.image else {
guard let oldImage = imageView.image, imageView.window?.inLiveResize == false else {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is inLiveResize 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@onmyway133 if the window is being actively resized.

A Boolean value indicating whether the view is being rendered as part of a live resizing operation.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@zenangst zenangst merged commit 8952aff into master Aug 28, 2017
@zenangst zenangst deleted the improve/mac-os-implementation branch August 28, 2017 12:34
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.

2 participants