From 0675588aec905fb2d9b1c3f8b6d727e2a10446f0 Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 25 Feb 2025 19:55:31 +0200 Subject: [PATCH 1/4] fix: added null check on Android ViewGroup --- .../main/java/com/lodev09/truesheet/TrueSheetDialog.kt | 10 +++++----- .../main/java/com/lodev09/truesheet/TrueSheetView.kt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt index cf3e99a..b42aa3d 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt @@ -70,12 +70,12 @@ 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 = arrayOf("medium", "large") @@ -196,7 +196,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val } fun positionFooter() { - footerView.apply { + footerView?.apply { y = (maxScreenHeight - sheetContainerView.top - footerHeight).toFloat() } } diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt index 90d4023..5627a42 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetView.kt @@ -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 From fe0f4c85b3d583121bc28d05f5a29089e097f60b Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 25 Feb 2025 20:09:46 +0200 Subject: [PATCH 2/4] chore: improved null check on Android ViewGroup --- .../com/lodev09/truesheet/TrueSheetDialog.kt | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt index b42aa3d..9fe433f 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt @@ -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. @@ -71,19 +75,19 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val // 1st child is the content view val contentView: ViewGroup? - get() = containerView.getChildAt(0) as? ViewGroup + get() = containerView?.getChildAt(0) as? ViewGroup // 2nd child is the footer view val footerView: ViewGroup? - get() = containerView.getChildAt(1) as? ViewGroup + get() = containerView?.getChildAt(1) as? ViewGroup var sizes: Array = 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 { @@ -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 } /** @@ -196,11 +200,14 @@ 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() + } } } + /** * Set the state based for the given size index. */ From 6517df14a6f56ef68f7c06e43c177f179358970a Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 25 Feb 2025 20:23:30 +0200 Subject: [PATCH 3/4] chore: minor formatting/linting --- android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt index 9fe433f..f528265 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt @@ -24,7 +24,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val private var windowAnimation: Int = 0 // First child of the rootSheetView - private val containerView: ViewGroup? + private val containerView: ViewGroup? get() = if (rootSheetView.childCount > 0) { rootSheetView.getChildAt(0) as? ViewGroup } else { @@ -207,7 +207,6 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val } } - /** * Set the state based for the given size index. */ From 934832b09d42df0854d7fbd71865277410a7f770 Mon Sep 17 00:00:00 2001 From: Efstathios Ntonas Date: Tue, 25 Feb 2025 20:26:18 +0200 Subject: [PATCH 4/4] chore: minor formatting/linting --- .../java/com/lodev09/truesheet/TrueSheetDialog.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt index f528265..f17a6cd 100644 --- a/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt +++ b/android/src/main/java/com/lodev09/truesheet/TrueSheetDialog.kt @@ -24,15 +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() = if (rootSheetView.childCount > 0) { - rootSheetView.getChildAt(0) as? ViewGroup - } else { - null - } + private val containerView: ViewGroup? + get() = if (rootSheetView.childCount > 0) { + rootSheetView.getChildAt(0) as? ViewGroup + } else { + null + } private val sheetContainerView: ViewGroup? - get() = rootSheetView.parent?.let { it as? ViewGroup } + get() = rootSheetView.parent?.let { it as? ViewGroup } /** * Specify whether the sheet background is dimmed.