Skip to content

Commit

Permalink
💫 Update: setModalVisibilityByID
Browse files Browse the repository at this point in the history
Summary: Add `visibility` param. to `RNIModalViewModule.setModalVisibilityByID`.
  • Loading branch information
dominicstop committed May 13, 2023
1 parent 5282bfb commit 69da2f8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @interface RCT_EXTERN_MODULE(RNIModalViewModule, RCTEventEmitter)
// ----------------------------

RCT_EXTERN_METHOD(setModalVisibilityByID: (NSString)modalID
visibility: (BOOL)visibility
// promise blocks -----------------------
resolve: (RCTPromiseResolveBlock *)resolve
reject : (RCTPromiseRejectBlock *)reject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,25 @@ class RNIModalViewModule: RCTEventEmitter {

@objc func setModalVisibilityByID(
_ modalID: NSString,
visibility: Bool,
// promise blocks ------------------------
resolve: @escaping RCTPromiseResolveBlock,
reject : @escaping RCTPromiseRejectBlock
) {
DispatchQueue.main.async {
let listPresentedVC = RNIUtilities.getPresentedViewControllers();

let debugData: Dictionary<String, Any> = [
"modalID": modalID,
"visibility": visibility,
];

do {
guard listPresentedVC.count > 0 else {
throw RNIModalError(
code: .runtimeError,
message: "The list of presented view controllers is empty",
debugData: [
"modalID": modalID
]
debugData: debugData
);
};

Expand All @@ -90,13 +94,15 @@ class RNIModalViewModule: RCTEventEmitter {
throw RNIModalError(
code: .runtimeError,
message: errorMessage,
debugData: [
"modalID": modalID
]
debugData: debugData
);
};

try targetModalView.dismissModal {
let modalAction = visibility
? targetModalView.presentModal
: targetModalView.dismissModal;

try modalAction {
// modal dismissed
resolve([:]);
};
Expand All @@ -112,11 +118,12 @@ class RNIModalViewModule: RCTEventEmitter {
error.invokePromiseRejectBlock(reject);

} catch {
let errorWrapper = RNIModalError(
var errorWrapper = RNIModalError(
code: .unknownError,
error: error
);

errorWrapper.addDebugData(debugData);
errorWrapper.invokePromiseRejectBlock(reject);
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/module/ModalViewModule.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { RNIModalViewModule } from '../native_modules/RNIModalViewModule';

export class ModalViewModule {
static async setModalVisibilityByID(modalID: string) {
await RNIModalViewModule.setModalVisibilityByID(modalID);
static async setModalVisibilityByID(modalID: string, visibility: boolean) {
await RNIModalViewModule.setModalVisibilityByID(modalID, visibility);
}

static async dismissAllModals(animated = true) {
Expand Down
1 change: 1 addition & 0 deletions src/native_modules/RNIModalViewModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface RNIModalViewModule {
// prettier-ignore
setModalVisibilityByID(
modalID: string,
visibility: boolean,
): Promise<void>;

// prettier-ignore
Expand Down

0 comments on commit 69da2f8

Please sign in to comment.