-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8d94f81
commit 596cce5
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// CAAnimation+Block.swift | ||
// react-native-ios-modal | ||
// | ||
// Created by Dominic Go on 5/1/23. | ||
// | ||
|
||
import Foundation | ||
|
||
|
||
public class CAAnimationBlockDelegate: NSObject, CAAnimationDelegate { | ||
|
||
public typealias StartBlock = (CAAnimation) -> (); | ||
public typealias EndBlock = (CAAnimation, Bool) -> (); | ||
|
||
var onStartBlock: StartBlock? | ||
var onEndBlock: EndBlock? | ||
|
||
public func animationDidStart(_ anim: CAAnimation) { | ||
self.onStartBlock?(anim); | ||
}; | ||
|
||
public func animationDidStop(_ anim: CAAnimation, finished flag: Bool) { | ||
self.onEndBlock?(anim, flag); | ||
}; | ||
}; | ||
|
||
public extension CAAnimation { | ||
|
||
private var multicastDelegate: CAAnimationMulticastDelegate { | ||
guard let delegate = self.delegate else { | ||
return CAAnimationMulticastDelegate(); | ||
}; | ||
|
||
guard let multicastDelegate = delegate as? CAAnimationMulticastDelegate else { | ||
let multicastDelegate = CAAnimationMulticastDelegate(); | ||
multicastDelegate.emitter.add(delegate); | ||
|
||
self.speed = 0; | ||
|
||
self.delegate = multicastDelegate; | ||
return multicastDelegate; | ||
}; | ||
|
||
return multicastDelegate; | ||
}; | ||
|
||
func startBlock(_ callback: @escaping CAAnimationBlockDelegate.StartBlock) { | ||
let blockDelegate = CAAnimationBlockDelegate(); | ||
self.multicastDelegate.emitter.add(blockDelegate); | ||
|
||
blockDelegate.onStartBlock = callback; | ||
}; | ||
|
||
func endBlock(_ callback: @escaping CAAnimationBlockDelegate.EndBlock) { | ||
let blockDelegate = CAAnimationBlockDelegate(); | ||
self.multicastDelegate.emitter.add(blockDelegate); | ||
|
||
blockDelegate.onEndBlock = callback; | ||
}; | ||
}; |