From 1568f3aca087f605e4e017a9b366a76d3ab56cb0 Mon Sep 17 00:00:00 2001 From: Dominic Go <18517029+dominicstop@users.noreply.github.com> Date: Thu, 16 Mar 2023 09:21:37 +0800 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20Impl:=20`RNIModal`=20Proto?= =?UTF-8?q?cols?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Related to: TODO:2023-03-04-15-39-46 - Impl: RNIModalManager --- .../React Native/RNIModal/RNIModal.swift | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 ios/src_library/React Native/RNIModal/RNIModal.swift diff --git a/ios/src_library/React Native/RNIModal/RNIModal.swift b/ios/src_library/React Native/RNIModal/RNIModal.swift new file mode 100644 index 00000000..2245c659 --- /dev/null +++ b/ios/src_library/React Native/RNIModal/RNIModal.swift @@ -0,0 +1,96 @@ +// +// RNIModal.swift +// react-native-ios-modal +// +// Created by Dominic Go on 3/16/23. +// + +import Foundation + +/// A collection of protocols that the "adoptee" needs to implement in order to +/// be considered a "modal". +/// +public typealias RNIModal = + RNIModalIdentity + & RNIModalState + & RNIModalRequestable + & RNIModalFocusNotifiable + & RNIModalFocusNotifying; + + +/// Specifies that the "adoptee/delegate" that conforms to this protocol must +/// have the specified modal-related properties so that it can be uniquely +/// identified amongst different modal instances. +/// +/// The "implementor/delegator" updates these properties; The delegate +/// should treat the properties declared in this protocol as read-only. +/// +public protocol RNIModalIdentity: AnyObject { + + var modalIndex: Int? { set get }; + + var modalID: String? { set get }; +}; + +/// Specifies that the "adoptee/delegate" that conforms to this protocol must +/// have the specified modal-related properties for keeping track of state +/// +/// The "implementor/delegator" updates these properties; The delegate +/// should treat the properties declared in this protocol as read-only. +/// +public protocol RNIModalState: AnyObject { + + var isModalPresented: Bool { set get }; + + var isModalInFocus: Bool { set get }; + +}; + +/// The "implementer/delegator" notifies the "adoptee/delegate" of this protocol +/// of requests to perform "modal-related" actions. +/// +public protocol RNIModalRequestable: AnyObject { + + func requestModalToShow( + sender: RNIModal, + onRequestApprovedBlock: () -> Void, + onRequestDeniedBlock: (_ reason: String) -> Void + ); + + func requestModalToHide( + sender: RNIModal, + onRequestApprovedBlock: () -> Void, + onRequestDeniedBlock: (_ reason: String) -> Void + ); +}; + +/// The "implementer/delegator" notifies the "adoptee/delegate" of this protocol +/// of modal focus/blur related events. +/// +/// An interface for the "adoptee/delegate" of incoming modal "focus/blur" +/// related notifications. +/// +public protocol RNIModalFocusNotifiable { + + func onModalWillFocusNotification(sender modal: RNIModal); + + func onModalDidFocusNotification(sender modal: RNIModal); + + func onModalWillBlurNotification(sender modal: RNIModal); + + func onModalDidBlurNotification(sender modal: RNIModal); + +}; + +/// Specifies that the "adoptee/delegate" that conforms to this protocol must +/// notify a delegate of modal "focus/blur"-related events +/// +public protocol RNIModalFocusNotifying: AnyObject { + + /// Notify the "shared modal manager" if the current modal instance is going + /// to be shown or hidden. + /// + /// That focus notification will then be relayed to the other modal instances. + var modalFocusDelegate: RNIModalFocusNotifiable? { get set }; + +};