Skip to content

Commit

Permalink
⭐️ Impl: Animation Logic Scaffolding for `RNIModalSheetBottomAttached…
Browse files Browse the repository at this point in the history
…OverlayController`
  • Loading branch information
dominicstop committed Oct 7, 2024
1 parent 944874a commit efc00cf
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
};
};
38 changes: 38 additions & 0 deletions ios/RNIModalSheetView/RNIModalSheetViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
// --------------

Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 17 additions & 0 deletions ios/Temp/EntranceAnimationTransitioning.swift
Original file line number Diff line number Diff line change
@@ -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
);
};
17 changes: 17 additions & 0 deletions ios/Temp/ExitAnimationTransitioning.swift
Original file line number Diff line number Diff line change
@@ -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
);
};

0 comments on commit efc00cf

Please sign in to comment.