rendering only if layout and konfetti view exists - to avoid null reference errors

pull/1972/head
Gokul K 2 years ago committed by Alinson S. Xavier
parent b09306e793
commit 1280e798d2
Signed by: isoron
GPG Key ID: 0DA8E4B9E1109DCA

@ -115,10 +115,12 @@ fun ViewGroup.buildKonfettiView(): View {
}
fun showConfetti(view: View) {
val viewId = R.id.konfettttiView
val viewId = R.id.konfetttiView
val linearLayout = view.findViewById<LinearLayout>(R.id.konfettiLayout)
val kv = view.findViewById<KonfettiView>(viewId)
if (linearLayout != null) {
linearLayout.bringToFront()
}
val party = Party(
speed = 0f,
maxSpeed = 32f,
@ -128,7 +130,9 @@ fun showConfetti(view: View) {
position = Position.Relative(0.5, 0.3),
emitter = Emitter(duration = 300, TimeUnit.MILLISECONDS).max(300)
)
if (kv != null) {
kv.start(party)
}
}
fun View.showMessage(msg: String) {

@ -24,6 +24,6 @@
<nl.dionsegijn.konfetti.xml.KonfettiView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/konfettttiView"/>
android:id="@+id/konfetttiView"/>
</LinearLayout>

Loading…
Cancel
Save