diff --git a/Sources/UIComponent/Animators/WrapperAnimator.swift b/Sources/UIComponent/Animators/WrapperAnimator.swift index fd04b3ae..1a2e5839 100644 --- a/Sources/UIComponent/Animators/WrapperAnimator.swift +++ b/Sources/UIComponent/Animators/WrapperAnimator.swift @@ -4,41 +4,39 @@ import UIKit public class WrapperAnimator: Animator { public var content: Animator? - public var passthrough: Bool = false + public var passthroughUpdate: Bool = false public var insertBlock: ((ComponentDisplayableView, UIView, CGRect) -> Void)? public var updateBlock: ((ComponentDisplayableView, UIView, CGRect) -> Void)? public var deleteBlock: ((ComponentDisplayableView, UIView, () -> Void) -> Void)? + public override func shift(componentView: ComponentDisplayableView, delta: CGPoint, view: UIView) { + (content ?? componentView.animator).shift(componentView: componentView, delta: delta, view: view) + } + public override func update(componentView: ComponentDisplayableView, view: UIView, frame: CGRect) { if let updateBlock { updateBlock(componentView, view, frame) - if passthrough, let content = content { - content.update(componentView: componentView, view: view, frame: frame) + if passthroughUpdate { + (content ?? componentView.animator).update(componentView: componentView, view: view, frame: frame) } - } else if let content { - content.update(componentView: componentView, view: view, frame: frame) } else { - componentView.animator.update(componentView: componentView, view: view, frame: frame) + (content ?? componentView.animator).update(componentView: componentView, view: view, frame: frame) } } public override func insert(componentView: ComponentDisplayableView, view: UIView, frame: CGRect) { if let insertBlock { insertBlock(componentView, view, frame) - } else if let content { - content.insert(componentView: componentView, view: view, frame: frame) } else { - componentView.animator.insert(componentView: componentView, view: view, frame: frame) + (content ?? componentView.animator).insert(componentView: componentView, view: view, frame: frame) } } public override func delete(componentView: ComponentDisplayableView, view: UIView, completion: @escaping () -> Void) { if let deleteBlock { deleteBlock(componentView, view, completion) - } else if let content { - content.delete(componentView: componentView, view: view, completion: completion) } else { - componentView.animator.delete(componentView: componentView, view: view, completion: completion) + (content ?? componentView.animator).delete(componentView: componentView, view: view, completion: completion) } } } diff --git a/Sources/UIComponent/Core/ComponentView/ComponentEngine.swift b/Sources/UIComponent/Core/ComponentView/ComponentEngine.swift index 4b790abb..ac942f66 100644 --- a/Sources/UIComponent/Core/ComponentView/ComponentEngine.swift +++ b/Sources/UIComponent/Core/ComponentView/ComponentEngine.swift @@ -259,7 +259,7 @@ public class ComponentEngine { if updateViews { // view was on screen before reload, need to update the view. viewData.renderNode._updateView(view) - (viewData.animator ?? animator).shift(componentView: componentView, delta: contentOffsetDelta, view: view) + animator.shift(componentView: componentView, delta: contentOffsetDelta, view: view) } } else { view = viewData.renderNode._makeView() as! UIView diff --git a/Sources/UIComponent/Core/Model/ViewComponent/ViewComponent+Modifiers.swift b/Sources/UIComponent/Core/Model/ViewComponent/ViewComponent+Modifiers.swift index b66380a2..fe49bdfd 100644 --- a/Sources/UIComponent/Core/Model/ViewComponent/ViewComponent+Modifiers.swift +++ b/Sources/UIComponent/Core/Model/ViewComponent/ViewComponent+Modifiers.swift @@ -67,16 +67,6 @@ extension ViewComponent { $0.animateUpdate(passthrough: passthrough, updateBlock) } } - public func animateInsert(passthrough: Bool = false, _ insertBlock: @escaping ((ComponentDisplayableView, UIView, CGRect) -> Void)) -> ViewAnimatorWrapperComponent { - ViewModifierComponent(content: self) { - $0.animateInsert(passthrough: passthrough, insertBlock) - } - } - public func animateDelete(passthrough: Bool = false, _ deleteBlock: @escaping ((ComponentDisplayableView, UIView, () -> Void) -> Void)) -> ViewAnimatorWrapperComponent { - ViewModifierComponent(content: self) { - $0.animateDelete(passthrough: passthrough, deleteBlock) - } - } } extension ViewComponent { diff --git a/Sources/UIComponent/Core/Model/ViewRenderNode/ViewRenderNodeModifiers.swift b/Sources/UIComponent/Core/Model/ViewRenderNode/ViewRenderNodeModifiers.swift index 98a164eb..39edbae9 100644 --- a/Sources/UIComponent/Core/Model/ViewRenderNode/ViewRenderNodeModifiers.swift +++ b/Sources/UIComponent/Core/Model/ViewRenderNode/ViewRenderNodeModifiers.swift @@ -93,14 +93,14 @@ extension ViewRenderNode { public struct ViewAnimatorWrapperRenderNode: ViewRenderNodeWrapper { public let content: Content - var passthrough: Bool + var passthroughUpdate: Bool var insertBlock: ((ComponentDisplayableView, UIView, CGRect) -> Void)? var updateBlock: ((ComponentDisplayableView, UIView, CGRect) -> Void)? var deleteBlock: ((ComponentDisplayableView, UIView, () -> Void) -> Void)? public var animator: Animator? { let wrapper = WrapperAnimator() wrapper.content = content.animator - wrapper.passthrough = passthrough + wrapper.passthroughUpdate = passthroughUpdate wrapper.insertBlock = insertBlock wrapper.deleteBlock = deleteBlock wrapper.updateBlock = updateBlock @@ -110,12 +110,6 @@ public struct ViewAnimatorWrapperRenderNode: ViewRender extension ViewRenderNode { func animateUpdate(passthrough: Bool = false, _ updateBlock: @escaping ((ComponentDisplayableView, UIView, CGRect) -> Void)) -> ViewAnimatorWrapperRenderNode { - ViewAnimatorWrapperRenderNode(content: self, passthrough: passthrough, updateBlock: updateBlock) - } - func animateInsert(passthrough: Bool = false, _ insertBlock: @escaping ((ComponentDisplayableView, UIView, CGRect) -> Void)) -> ViewAnimatorWrapperRenderNode { - ViewAnimatorWrapperRenderNode(content: self, passthrough: passthrough, insertBlock: insertBlock) - } - func animateDelete(passthrough: Bool = false, _ deleteBlock: @escaping ((ComponentDisplayableView, UIView, () -> Void) -> Void)) -> ViewAnimatorWrapperRenderNode { - ViewAnimatorWrapperRenderNode(content: self, passthrough: passthrough, deleteBlock: deleteBlock) + ViewAnimatorWrapperRenderNode(content: self, passthroughUpdate: passthrough, updateBlock: updateBlock) } }