From bb47def33747190deb0768c479f404d6a0236472 Mon Sep 17 00:00:00 2001 From: Alisa Mylnikova Date: Fri, 17 Apr 2020 15:55:40 +0700 Subject: [PATCH] Fix some examples --- .../CombinationAnimationGenerator.swift | 7 ++- Source/views/MacawView.swift | 52 +++++++------------ 2 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift b/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift index 9a6f92eb..6815bcb0 100644 --- a/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift +++ b/Source/animation/types/animation_generators/CombinationAnimationGenerator.swift @@ -115,13 +115,16 @@ extension AnimationProducer { // MARK: - Combine animation func addCombineAnimation(_ combineAnimation: Animation, _ context: AnimationContext) { guard let combine = combineAnimation as? CombineAnimation, + let _ = combine.nodeRenderer, let node = combine.node else { return } var animations = combine.animations - let childAnimations = createChildAnimations(combine) as! [BasicAnimation] - animations.append(contentsOf: childAnimations) + if let _ = combine.node?.bounds, let _ = combine.toNodes.group().bounds { + let childAnimations = createChildAnimations(combine) as! [BasicAnimation] + animations.append(contentsOf: childAnimations) + } // Reversing if combine.autoreverses { diff --git a/Source/views/MacawView.swift b/Source/views/MacawView.swift index f7a02dd2..2dddec6d 100644 --- a/Source/views/MacawView.swift +++ b/Source/views/MacawView.swift @@ -74,9 +74,8 @@ open class MacawView: MView { @objc public init?(node: Node, coder aDecoder: NSCoder) { super.init(coder: aDecoder) - if let drawingView = DrawingView(node: node, coder: aDecoder) { - self.drawingView = drawingView - } + self.node = node + self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView) zoom.initialize(view: self, onChange: onZoomChange) } @@ -84,14 +83,13 @@ open class MacawView: MView { public convenience init(node: Node, frame: CGRect) { self.init(frame: frame) - self.drawingView = DrawingView(node: node, frame: frame) + self.node = node + self.renderer = RenderUtils.createNodeRenderer(node, view: drawingView) } public override init(frame: CGRect) { super.init(frame: frame) - self.drawingView = DrawingView(frame: frame) - zoom.initialize(view: self, onChange: onZoomChange) } @@ -107,21 +105,27 @@ open class MacawView: MView { initializeView() } + open override func layoutSubviews() { + super.layoutSubviews() + + drawingView.frame = self.bounds + } + func initializeView() { if !self.subviews.contains(drawingView) { - self.backgroundColor = .white - self.clipsToBounds = true + if self.backgroundColor == nil { + self.backgroundColor = .white + } + drawingView.removeFromSuperview() self.addSubview(drawingView) - drawingView.backgroundColor = .white - drawingView.isUserInteractionEnabled = false + drawingView.backgroundColor = .clear drawingView.initializeView() - drawingView.translatesAutoresizingMaskIntoConstraints = false - drawingView.trailingAnchor.constraint(equalTo: self.trailingAnchor).isActive = true - drawingView.leadingAnchor.constraint(equalTo: self.leadingAnchor).isActive = true - drawingView.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true - drawingView.topAnchor.constraint(equalTo: self.topAnchor).isActive = true + #if os(iOS) + self.clipsToBounds = true + drawingView.isUserInteractionEnabled = false + #endif } let tapRecognizer = MTapGestureRecognizer(target: drawingView, action: #selector(DrawingView.handleTap(recognizer:))) @@ -277,24 +281,8 @@ internal class DrawingView: MView, MGestureRecognizerDelegate { self.context = RenderContext(view: self) } - @objc public convenience required init?(coder aDecoder: NSCoder) { - self.init(node: Group(), coder: aDecoder) - } - - @objc public init?(node: Node, coder aDecoder: NSCoder) { + @objc public required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - - self.node = node - self.renderer = RenderUtils.createNodeRenderer(node, view: self) - backgroundColor = .white - } - - public convenience init(node: Node, frame: CGRect) { - self.init(frame: frame) - - self.node = node - self.renderer = RenderUtils.createNodeRenderer(node, view: self) - backgroundColor = .white } public override init(frame: CGRect) {