Skip to content

Commit

Permalink
fix(iOS): null checks in getTrueSheetView (#108)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dmnkgrc authored Nov 26, 2024
1 parent 7467c74 commit 65d3316
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ios/TrueSheetViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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))
}
}

0 comments on commit 65d3316

Please sign in to comment.