@@ -24,11 +24,15 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
24
24
private var windowAnimation: Int = 0
25
25
26
26
// First child of the rootSheetView
27
- private val containerView: ViewGroup
28
- get() = rootSheetView.getChildAt(0 ) as ViewGroup
27
+ private val containerView: ViewGroup ?
28
+ get() = if (rootSheetView.childCount > 0 ) {
29
+ rootSheetView.getChildAt(0 ) as ? ViewGroup
30
+ } else {
31
+ null
32
+ }
29
33
30
- private val sheetContainerView: ViewGroup
31
- get() = rootSheetView.parent as ViewGroup
34
+ private val sheetContainerView: ViewGroup ?
35
+ get() = rootSheetView.parent?. let { it as ? ViewGroup }
32
36
33
37
/* *
34
38
* Specify whether the sheet background is dimmed.
@@ -70,20 +74,20 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
70
74
var backgroundColor: Int = Color .WHITE
71
75
72
76
// 1st child is the content view
73
- val contentView: ViewGroup
74
- get() = containerView.getChildAt(0 ) as ViewGroup
77
+ val contentView: ViewGroup ?
78
+ get() = containerView? .getChildAt(0 ) as ? ViewGroup
75
79
76
80
// 2nd child is the footer view
77
- val footerView: ViewGroup
78
- get() = containerView.getChildAt(1 ) as ViewGroup
81
+ val footerView: ViewGroup ?
82
+ get() = containerView? .getChildAt(1 ) as ? ViewGroup
79
83
80
84
var sizes: Array <Any > = arrayOf(" medium" , " large" )
81
85
82
86
init {
83
87
setContentView(rootSheetView)
84
88
85
- sheetContainerView.setBackgroundColor(backgroundColor)
86
- sheetContainerView.clipToOutline = true
89
+ sheetContainerView? .setBackgroundColor(backgroundColor)
90
+ sheetContainerView? .clipToOutline = true
87
91
88
92
// Setup window params to adjust layout based on Keyboard state
89
93
window?.apply {
@@ -131,7 +135,7 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
131
135
132
136
// Use current background color
133
137
background.paint.color = backgroundColor
134
- sheetContainerView.background = background
138
+ sheetContainerView? .background = background
135
139
}
136
140
137
141
/* *
@@ -196,8 +200,10 @@ class TrueSheetDialog(private val reactContext: ThemedReactContext, private val
196
200
}
197
201
198
202
fun positionFooter () {
199
- footerView.apply {
200
- y = (maxScreenHeight - sheetContainerView.top - footerHeight).toFloat()
203
+ footerView?.let { footer ->
204
+ sheetContainerView?.let { container ->
205
+ footer.y = (maxScreenHeight - container.top - footerHeight).toFloat()
206
+ }
201
207
}
202
208
}
203
209
0 commit comments