Skip to content

Commit

Permalink
⭐️ Impl: Add RNIModalViewControllerWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicstop committed Apr 12, 2023
1 parent c23dc7d commit a6c17d0
Showing 1 changed file with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
//
// RNIModalViewControllerWrapper.swift
// react-native-ios-modal
//
// Created by Dominic Go on 4/13/23.
//

import Foundation

/// Wraps a `UIViewController` so it can be used w/ `RNIModalManager`
///
public class RNIModalViewControllerWrapper:
RNIIdentifiable, RNIModalPresentationNotifying, RNIModalState,
RNIModalPresentation {

// MARK: - Properties - RNIIdentifiable
// ------------------------------------

public static var synthesizedIdPrefix: String = "modal-wrapper-";

// MARK: - Properties - RNIModalPresentationNotifying
// --------------------------------------------------

public var modalPresentationNotificationDelegate: RNIModalPresentationNotifiable!

// MARK: - Properties - RNIModalState
// ----------------------------------

public var modalIndexPrev: Int!
public var modalIndex: Int!

public lazy var modalPresentationState = RNIModalPresentationStateMachine();

public var modalFocusState = RNIModalFocusStateMachine();

// MARK: - Properties - RNIModalPresentation
// -----------------------------------------

/// The modal that is being presented, or to be presented (i.e.
/// `UIViewController.presentedViewController`).
///
public weak var modalViewController: UIViewController?;

/// The view controller that presented the modal (i.e.
/// `modalViewController` or `UIViewController.presentingViewController`)
///
public weak var presentingViewController: UIViewController?;

public var window: UIWindow? {
self.presentingViewController?.view.window
};

// MARK: -
// ------------------


public init(){
RNIModalManagerShared.register(modal: self);
};
};

// MARK: - RNIModalRequestable
// ---------------------------

extension RNIModalViewControllerWrapper: RNIModalRequestable {

public func requestModalToShow(
sender: any RNIModal,
onRequestApprovedBlock: () -> Void,
onRequestDeniedBlock: (String) -> Void
) {
// TBA - no-op
};

public func requestModalToHide(
sender: any RNIModal,
onRequestApprovedBlock: () -> Void,
onRequestDeniedBlock: (String) -> Void
) {
// TBA - no-op
};
};

// MARK: - RNIModalFocusNotifiable
// -------------------------------

extension RNIModalViewControllerWrapper: RNIModalFocusNotifiable {
public func onModalWillFocusNotification(sender: any RNIModal) {
// no-op
}

public func onModalDidFocusNotification(sender: any RNIModal) {
// no-op
}

public func onModalWillBlurNotification(sender: any RNIModal) {
// no-op
}

public func onModalDidBlurNotification(sender: any RNIModal) {
// no-op
}
};


0 comments on commit a6c17d0

Please sign in to comment.