Skip to content

Commit

Permalink
⭐️ Impl: RNIModal Protocols
Browse files Browse the repository at this point in the history
Related to: TODO:2023-03-04-15-39-46 - Impl: RNIModalManager
  • Loading branch information
dominicstop committed Mar 16, 2023
1 parent 26ef01b commit 1568f3a
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions ios/src_library/React Native/RNIModal/RNIModal.swift
Original file line number Diff line number Diff line change
@@ -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 };

};

0 comments on commit 1568f3a

Please sign in to comment.