Skip to content

Commit

Permalink
fix(ios): add null guard (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
lodev09 authored Jul 1, 2024
1 parent 329026d commit bcd0b17
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@ class TrueSheetView(context: Context) :
// Initialize content
UiThreadUtil.runOnUiThread {
// 1st child is the content view
val contentView = it.getChildAt(0) as ViewGroup
setContentHeight(contentView.height)
val contentView = it.getChildAt(0) as ViewGroup?
setContentHeight(contentView?.height ?: 0)

// 2nd child is the footer view
val footerView = it.getChildAt(1) as ViewGroup
val footerView = it.getChildAt(1) as ViewGroup?
sheetDialog.footerView = footerView
setFooterHeight(footerView.height)
setFooterHeight(footerView?.height ?: 0)

if (initialIndex >= 0) {
currentSizeIndex = initialIndex
Expand Down
9 changes: 7 additions & 2 deletions ios/TrueSheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {

private var rctScrollView: RCTScrollView?

private var uiManager: RCTUIManager? {
guard let uiManager = bridge?.uiManager else { return nil }
return uiManager
}

// MARK: - Setup

init(with bridge: RCTBridge) {
Expand Down Expand Up @@ -143,7 +148,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
guard let containerView else { return }

let size = CGSize(width: width, height: containerView.bounds.height)
bridge?.uiManager.setSize(size, for: containerView)
uiManager?.setSize(size, for: containerView)
}

func viewControllerWillAppear() {
Expand Down Expand Up @@ -297,7 +302,7 @@ class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {

@objc
func setScrollableHandle(_ tag: NSNumber?) {
let view = bridge?.uiManager.view(forReactTag: tag) as? RCTScrollView
let view = uiManager?.view(forReactTag: tag) as? RCTScrollView
rctScrollView = view
}

Expand Down

0 comments on commit bcd0b17

Please sign in to comment.