From 2ae97ff8b3c0be75bdf16af83b095d3423678bb3 Mon Sep 17 00:00:00 2001 From: Dominic Go Date: Fri, 27 Sep 2024 20:31:32 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`ModalSheetPresent?= =?UTF-8?q?ationStateMachine.eventDelegates`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...eetPresentationStateEventsNotifiable.swift | 47 +++++++++++++++++++ .../ModalSheetPresentationStateMachine.swift | 19 ++++++++ 2 files changed, 66 insertions(+) create mode 100644 ios/Temp/ModalSheetPresentationStateEventsNotifiable.swift diff --git a/ios/Temp/ModalSheetPresentationStateEventsNotifiable.swift b/ios/Temp/ModalSheetPresentationStateEventsNotifiable.swift new file mode 100644 index 00000000..659b209b --- /dev/null +++ b/ios/Temp/ModalSheetPresentationStateEventsNotifiable.swift @@ -0,0 +1,47 @@ +// +// ModalSheetPresentationStateEventsNotifiable.swift +// react-native-ios-modal +// +// Created by Dominic Go on 9/27/24. +// + +import Foundation + +public protocol ModalSheetPresentationStateEventsNotifiable: AnyObject { + + func onModalSheetStateWillChange( + sender: ModalSheetPresentationStateMachine, + prevState: ModalSheetState?, + currentState: ModalSheetState, + nextState: ModalSheetState + ); + + func onModalSheetStateDidChange( + sender: ModalSheetPresentationStateMachine, + prevState: ModalSheetState?, + currentState: ModalSheetState + ); +}; + +// MARK: - ModalSheetPresentationStateEventsNotifiable+Default +// ----------------------------------------------------------- + +public extension ModalSheetPresentationStateEventsNotifiable { + + func onModalSheetStateWillChange( + sender: ModalSheetPresentationStateMachine, + prevState: ModalSheetState?, + currentState: ModalSheetState, + nextState: ModalSheetState + ) { + // no-op + }; + + func onModalSheetStateDidChange( + sender: ModalSheetPresentationStateMachine, + prevState: ModalSheetState?, + currentState: ModalSheetState + ) { + // no-op + }; +}; diff --git a/ios/Temp/ModalSheetPresentationStateMachine.swift b/ios/Temp/ModalSheetPresentationStateMachine.swift index 63c07ea7..52f8b545 100644 --- a/ios/Temp/ModalSheetPresentationStateMachine.swift +++ b/ios/Temp/ModalSheetPresentationStateMachine.swift @@ -17,6 +17,8 @@ public class ModalSheetPresentationStateMachine { public var didPresent = false; public var didDismissAfterPresented = false; + public var eventDelegates: + MulticastDelegate = .init(); // MARK: - Methods // --------------- @@ -39,6 +41,15 @@ public class ModalSheetPresentationStateMachine { ); }; #endif + + self.eventDelegates.invoke { + $0.onModalSheetStateWillChange( + sender: self, + prevState: prevState, + currentState: currentState, + nextState: nextState + ); + }; self.prevState = self.currentState; self.currentState = nextState; @@ -71,6 +82,14 @@ public class ModalSheetPresentationStateMachine { ); }; #endif + + self.eventDelegates.invoke { + $0.onModalSheetStateDidChange( + sender: self, + prevState: self.prevState, + currentState: self.currentState + ); + }; }; public func setState(nextState: ModalSheetState) {