Skip to content

fix: add android viewgroup null check #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
private var windowAnimation: Int = 0

// First child of the rootSheetView
private val containerView: ViewGroup
get() = rootSheetView.getChildAt(0) as ViewGroup
private val containerView: ViewGroup?
get() = if (rootSheetView.childCount > 0) {
rootSheetView.getChildAt(0) as? ViewGroup
} else {
null
}

private val sheetContainerView: ViewGroup
get() = rootSheetView.parent as ViewGroup
private val sheetContainerView: ViewGroup?
get() = rootSheetView.parent?.let { it as? ViewGroup }

/**
* Specify whether the sheet background is dimmed.
Expand Down Expand Up @@ -70,20 +74,20 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
var backgroundColor: Int = Color.WHITE

// 1st child is the content view
val contentView: ViewGroup
get() = containerView.getChildAt(0) as ViewGroup
val contentView: ViewGroup?
get() = containerView?.getChildAt(0) as? ViewGroup

// 2nd child is the footer view
val footerView: ViewGroup
get() = containerView.getChildAt(1) as ViewGroup
val footerView: ViewGroup?
get() = containerView?.getChildAt(1) as? ViewGroup

var sizes: Array<Any> = arrayOf("medium", "large")

init {
setContentView(rootSheetView)

sheetContainerView.setBackgroundColor(backgroundColor)
sheetContainerView.clipToOutline = true
sheetContainerView?.setBackgroundColor(backgroundColor)
sheetContainerView?.clipToOutline = true

// Setup window params to adjust layout based on Keyboard state
window?.apply {
Expand Down Expand Up @@ -131,7 +135,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val

// Use current background color
background.paint.color = backgroundColor
sheetContainerView.background = background
sheetContainerView?.background = background
}

/**
Expand Down Expand Up @@ -196,8 +200,10 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
}

fun positionFooter() {
footerView.apply {
y = (maxScreenHeight - sheetContainerView.top - footerHeight).toFloat()
footerView?.let { footer ->
sheetContainerView?.let { container ->
footer.y = (maxScreenHeight - container.top - footerHeight).toFloat()
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ class TrueSheetView(context: Context) :

// Initialize content
UiThreadUtil.runOnUiThread {
setContentHeight(sheetDialog.contentView.height)
setFooterHeight(sheetDialog.footerView.height)
sheetDialog.contentView?.height?.let { setContentHeight(it) }
sheetDialog.footerView?.height?.let { setFooterHeight(it) }

if (initialIndex >= 0) {
currentSizeIndex = initialIndex
Expand Down
Loading