exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 554 forks source link

Crash for iOS 13 #649

Open topDev15 opened 4 years ago

topDev15 commented 4 years ago

class NodeRenderer {

weak var view: MView?

fileprivate let onNodeChange: () -> Void fileprivate let disposables = GroupDisposable() fileprivate var active = false weak var animationCache: AnimationCache?

init(node: Node, view: MView?, animationCache: AnimationCache?) { self.view = view self.animationCache = animationCache

onNodeChange = { [unowned node, weak view] in
    guard let isAnimating = animationCache?.isAnimating(node) else {
        return
    }

    if isAnimating {
        return
    }

        DispatchQueue.main.async {
        print("setNeedsDisplay=6")
            view?.setNeedsDisplay()
        }
}

addObservers()

} view?.setNeedsDisplay() needs to be wrapped with DispatchQueue.main.async {}. If not, we have crash for iOS 13. But after we wrap it, it is very slow when changing color of shape. I found the reason. When changing color of shape, this framework is doing rerendering for whole group using group rendering. Now it needs to be called for main thread as you can see above. But the speed is very slow because of calling main thread much time. How can we fix this issue? Please let me know if you have any thought.