Juanpe / SkeletonView

☠️ An elegant way to show users that something is happening and also prepare them to which contents they are awaiting
MIT License
12.51k stars 1.1k forks source link

crossDissolve animation not working #510

Open xygkevin opened 1 year ago

xygkevin commented 1 year ago

Description

Describe your issue here.

What type of issue is this? (place an x in one of the [ ])

Requirements (place an x in each of the [ ])


Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

SkeletonView Environment:

SkeletonView version:1.30.2 Xcode version:13.4.1 **Swift version:swift5

Steps to reproduce:

Please replace this with the steps to reproduce the behavior.

view.showSkeleton(transition: .crossDissolve(0.25)) view.hideSkeleton(transition: .crossDissolve(0.25))

All show or hide cross dissolve animation are not working, the same problem with the demo project

both

Expected result:

Please replace this with what you expected to happen.

Actual result:

Please replace this with of what happened instead.

Attachments:

Logs, screenshots, sample project, funny gif, etc.

ardavydov commented 1 year ago

Confirm, it doesn't work even in the demo project

Serg-Pogrebnyak commented 9 months ago

same on my end

Serg-Pogrebnyak commented 9 months ago

@ardavydov and @xygkevin Here is the fix for hiding: in CALayer extension find next function: func setOpacity(from: Int, to: Int, duration: TimeInterval, completion: (() -> Void)?) and change it code on the next:

DispatchQueue.main.async { [weak self] in
    guard let strongSelf = self else { return }
    CATransaction.begin ()
    let animation = CABasicAnimation (keyPath: #keyPath (CALayer.opacity))
    animation.fromValue = from
    animation.toValue = to
    animation.duration = duration
    animation.timingFunction = CAMediaTimingFunction (name:
    CAMediaTimingFunctionName.easeInEaseOut)
    animation.fillMode = .forwards
    animation.isRemovedOnCompletion = false
    CATransaction.setCompletionBlock(completion)
    strongSelf.add(animation, forKey: "setOpacityAnimation")
    CATransaction.commit ()
}