From 65d33166c2be43ffd0ce16ff7487f1f61ba26d70 Mon Sep 17 00:00:00 2001 From: Dominik Garcia Date: Tue, 26 Nov 2024 11:16:50 +0100 Subject: [PATCH] fix(iOS): null checks in getTrueSheetView (#108) This PR fixes a crash in onDismiss caused by nil values during app reloads in release builds. Both bridge and the view can be null and this is now handled in getTrueSheetView --- ios/TrueSheetViewManager.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ios/TrueSheetViewManager.swift b/ios/TrueSheetViewManager.swift index 202c7ec..1e9e5ca 100644 --- a/ios/TrueSheetViewManager.swift +++ b/ios/TrueSheetViewManager.swift @@ -24,9 +24,11 @@ class TrueSheetViewManager: RCTViewManager { // MARK: - Private - private func getTrueSheetView(_ tag: NSNumber) -> TrueSheetView { + private func getTrueSheetView(_ tag: NSNumber) -> TrueSheetView? { + guard let uiManager = bridge?.uiManager else { return nil } + guard let viewForTag = uiManager.view(forReactTag: tag) else { return nil } // swiftlint:disable force_cast - return bridge.uiManager.view(forReactTag: tag) as! TrueSheetView + return viewForTag as! TrueSheetView // swiftlint:enable force_cast } @@ -35,12 +37,12 @@ class TrueSheetViewManager: RCTViewManager { @objc func present(_ tag: NSNumber, index: Int, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { let trueSheetView = getTrueSheetView(tag) - trueSheetView.present(at: index, promise: Promise(resolver: resolve, rejecter: reject)) + trueSheetView?.present(at: index, promise: Promise(resolver: resolve, rejecter: reject)) } @objc func dismiss(_ tag: NSNumber, resolve: @escaping RCTPromiseResolveBlock, reject: @escaping RCTPromiseRejectBlock) { let trueSheetView = getTrueSheetView(tag) - trueSheetView.dismiss(promise: Promise(resolver: resolve, rejecter: reject)) + trueSheetView?.dismiss(promise: Promise(resolver: resolve, rejecter: reject)) } }