From efc00cfbe25ac7e1a88dee9ebd4f1bbb5c62b278 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Mon, 7 Oct 2024 19:16:28 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20Animation=20Logic?= =?UTF-8?q?=20Scaffolding=20for=20`RNIModalSheetBottomAttachedOverlayContr?= =?UTF-8?q?oller`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...SheetBottomAttachedOverlayController.swift | 60 +++++++++++++++---- .../RNIModalSheetViewController.swift | 38 ++++++++++++ ios/Temp/EntranceAnimationTransitioning.swift | 17 ++++++ ios/Temp/ExitAnimationTransitioning.swift | 17 ++++++ 4 files changed, 119 insertions(+), 13 deletions(-) create mode 100644 ios/Temp/EntranceAnimationTransitioning.swift create mode 100644 ios/Temp/ExitAnimationTransitioning.swift diff --git a/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift b/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift index 541dc98..9a79376 100644 --- a/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift +++ b/ios/RNIModalSheetView/RNIModalSheetBottomAttachedOverlayController.swift @@ -68,23 +68,57 @@ extension RNIContentViewController: RNIViewLifecycle { } }; +extension RNIModalSheetBottomAttachedOverlayController: EntranceAnimationTransitioning { + public func createEntranceAnimationBlocks() -> ( + start: () -> Void, + end: () -> Void + ) { + let initialTransform = Transform3D( + translateY: 100 + ); + + let finalTransform = Transform3D( + translateY: 0 + ); + + return ( + start: { + //self.view.alpha = 0; + self.view.layer.transform = initialTransform.transform; + }, + end: { + //self.view.alpha = 1; + self.view.layer.transform = finalTransform.transform; + } + ); + }; +}; +extension RNIModalSheetBottomAttachedOverlayController: ExitAnimationTransitioning { -public class DummyContentController: UIViewController { - public override func viewDidLoad() { - self.view.backgroundColor = .blue; + public func createExitAnimationBlocks() -> ( + start: () -> Void, + end: () -> Void + ) { - let size = self.view.bounds.size; + let initialTransform = Transform3D( + translateY: 0 + ); - self.view.translatesAutoresizingMaskIntoConstraints = false; - NSLayoutConstraint.activate([ - self.view.heightAnchor.constraint(equalToConstant: 100), - ]); - }; + let finalTransform = Transform3D( + translateY: 100 + ); - public override func viewWillLayoutSubviews() { - let size = self.view.bounds.size; - print(size); - } + return ( + start: { + //self.view.alpha = 0; + self.view.layer.transform = initialTransform.transform; + }, + end: { + //self.view.alpha = 1; + self.view.layer.transform = finalTransform.transform; + } + ); + }; }; diff --git a/ios/RNIModalSheetView/RNIModalSheetViewController.swift b/ios/RNIModalSheetView/RNIModalSheetViewController.swift index 477c136..dc9f31a 100644 --- a/ios/RNIModalSheetView/RNIModalSheetViewController.swift +++ b/ios/RNIModalSheetView/RNIModalSheetViewController.swift @@ -54,8 +54,15 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie public override func viewIsAppearing(_ animated: Bool) { self.setupBottomOverlayIfNeeded(); + super.viewIsAppearing(animated); + self.setupEntranceAnimation(); }; + public override func viewWillDisappear(_ animated: Bool) { + super.viewWillDisappear(animated); + self.setupExitAnimation(); + } + // MARK: Methods // -------------- @@ -123,6 +130,37 @@ open class RNIModalSheetViewController: ModalSheetViewControllerLifecycleNotifie self.addChild(bottomOverlayController); bottomOverlayController.didMove(toParent: parent); }; + + func setupEntranceAnimation(){ + guard let transitionCoordinator = self.transitionCoordinator else { + return; + }; + + + if let bottomOverlayController = self.bottomOverlayController { + let animationBlocks = bottomOverlayController.createEntranceAnimationBlocks(); + + animationBlocks.start(); + transitionCoordinator.animate { context in + animationBlocks.end(); + }; + }; + }; + + func setupExitAnimation(){ + guard let transitionCoordinator = self.transitionCoordinator else { + return; + }; + + if let bottomOverlayController = self.bottomOverlayController { + let animationBlocks = bottomOverlayController.createExitAnimationBlocks(); + + animationBlocks.start(); + transitionCoordinator.animate { context in + animationBlocks.end(); + }; + }; + }; }; extension RNIModalSheetViewController: RNIViewLifecycle { diff --git a/ios/Temp/EntranceAnimationTransitioning.swift b/ios/Temp/EntranceAnimationTransitioning.swift new file mode 100644 index 0000000..b144378 --- /dev/null +++ b/ios/Temp/EntranceAnimationTransitioning.swift @@ -0,0 +1,17 @@ +// +// EntranceAnimationTransitioning.swift +// react-native-ios-modal +// +// Created by Dominic Go on 10/7/24. +// + +import Foundation + + +public protocol EntranceAnimationTransitioning { + + func createEntranceAnimationBlocks() -> ( + start: () -> Void, + end: () -> Void + ); +}; diff --git a/ios/Temp/ExitAnimationTransitioning.swift b/ios/Temp/ExitAnimationTransitioning.swift new file mode 100644 index 0000000..c5815b3 --- /dev/null +++ b/ios/Temp/ExitAnimationTransitioning.swift @@ -0,0 +1,17 @@ +// +// ExitAnimationTransitioning.swift +// react-native-ios-modal +// +// Created by Dominic Go on 10/7/24. +// + +import Foundation + + +public protocol ExitAnimationTransitioning { + + func createExitAnimationBlocks() -> ( + start: () -> Void, + end: () -> Void + ); +};