tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.76k stars 1.21k forks source link

iOS: add view.stopAnimation() parity #14144

Open m1ga opened 5 hours ago

m1ga commented 5 hours ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

On Android I've added https://github.com/tidev/titanium-sdk/pull/13743 to run view.stopAnimation(); in order to stop an animation (check the ticket for example code). It would be great to have that on iOS too.

I've found https://developer.apple.com/library/archive/qa/qa1673/_index.html and added this to TiUIView:

-(void)pauseLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
    layer.speed = 0.0;
    layer.timeOffset = pausedTime;
}

which works fine and will stop the animation at the point it currently is. But I wasn't able to start a new animation from the start again. Not a resume but just the normal view.animate() to start the animation from the start again (that's how Android works).

Any idea how to reset it? I've tried to set the speed back to 1 and the time to 0, also tried [self.layer removeAllAnimations]; but it didn't reset it.

Solution

Add a way to stop/pause the animation and when you call view.animate() again it should start again.

Alternatives

No response

Platforms

iOS

AbdullahFaqeir commented 4 hours ago

@m1ga can you assign this to me

m1ga commented 4 hours ago

Awesome! Check the code in https://github.com/tidev/titanium-sdk/pull/13743 on Android to see what it does (press animate and in the middle of the animation press cancel to make it stop at that point).