diff --git a/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.m b/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.m index be17f02d..d785f8a9 100644 --- a/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.m +++ b/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.m @@ -20,8 +20,9 @@ @interface RCT_EXTERN_MODULE(RNIModalViewModule, RCTEventEmitter) reject : (RCTPromiseRejectBlock *)reject); RCT_EXTERN_METHOD(dismissAllModals: (BOOL)animated - callback: (RCTResponseSenderBlock)callback -); + // promise blocks ------------------------ + resolve: (RCTPromiseResolveBlock *)resolve + reject : (RCTPromiseRejectBlock *)reject); // MARK: - View-Related Functions // ------------------------------ diff --git a/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.swift b/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.swift index a15b290b..2a2efdf7 100644 --- a/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.swift +++ b/ios/src_library/React Native/RNIModalViewModule/RNIModalViewModule.swift @@ -122,17 +122,34 @@ class RNIModalViewModule: RCTEventEmitter { }; }; - // TODO: `TODO:2023-05-12-14-40-46` @objc func dismissAllModals( _ animated: Bool, - callback: @escaping RCTResponseSenderBlock + // promise blocks ------------------------ + resolve: @escaping RCTPromiseResolveBlock, + reject : @escaping RCTPromiseRejectBlock ) { DispatchQueue.main.async { - let success: Void? = UIWindow.key? - .rootViewController? - .dismiss(animated: animated, completion: nil); + let windows = RNIUtilities.getWindows(); + let rootViewControllers = windows.map { $0.rootViewController }; - callback([success != nil]); + guard rootViewControllers.isEmpty else { + let error = RNIModalError( + code: .runtimeError, + message: "Could not get root view controllers" + ); + + error.invokePromiseRejectBlock(reject); + return; + }; + + rootViewControllers.enumerated().forEach { + let isLast = $0.offset == rootViewControllers.count - 1; + + $0.element?.dismiss(animated: animated) { + guard isLast else { return }; + resolve([:]); + }; + }; }; }; diff --git a/src/module/ModalViewModule.ts b/src/module/ModalViewModule.ts index 1d84a033..376b0c17 100644 --- a/src/module/ModalViewModule.ts +++ b/src/module/ModalViewModule.ts @@ -1,26 +1,11 @@ import { RNIModalViewModule } from '../native_modules/RNIModalViewModule'; -import * as Helpers from '../functions/helpers'; export class ModalViewModule { static async setModalVisibilityByID(modalID: string) { await RNIModalViewModule.setModalVisibilityByID(modalID); } - static dismissAllModals(animated = true) { - const promise = new Promise((resolve, reject) => { - try { - RNIModalViewModule.dismissAllModals(animated, (success) => { - (success ? resolve : reject)(); - }); - - // prettier-ignore - } catch (error) { - console.log('RNIModalViewModule, dismissAllModals error:'); - console.log(error); - reject(); - } - }); - - return Helpers.promiseWithTimeout(1000, promise); + static async dismissAllModals(animated = true) { + await RNIModalViewModule.dismissAllModals(animated); } } diff --git a/src/native_modules/RNIModalViewModule.ts b/src/native_modules/RNIModalViewModule.ts index ba969bc9..fc5c5fff 100644 --- a/src/native_modules/RNIModalViewModule.ts +++ b/src/native_modules/RNIModalViewModule.ts @@ -15,8 +15,7 @@ interface RNIModalViewModule { // prettier-ignore dismissAllModals( animated: boolean, - callback: (success: boolean) => void - ): void; + ): Promise; // View-Related Functions // ----------------------