Skip to content

Commit 98e9b1d

Browse files
committed
Reset frame time when Composable's lifecycle is resumed
This prevents the delta from the previous frame time til now being so large that we render an inordinate amount of particles, slowing down or even crashing the app by running out of memory. A very similar issue as fixed in: #289
1 parent 2c14013 commit 98e9b1d

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ core-ktx = "1.7.0"
44
appcompat = "1.4.0"
55
constraintlayout = "2.1.3"
66
activity-compose = "1.4.0"
7-
androidx-lifecycle = "1.4.0"
7+
androidx-lifecycle = "2.8.7"
88
espresso = "3.5.1"
99
tracing = "1.1.0"
1010
material = "1.4.0"
@@ -26,6 +26,7 @@ androidx-tracing = { group = "androidx.tracing", name = "tracing", version.ref =
2626
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "appcompat" }
2727
androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activity-compose" }
2828
androidx-lifecycle-runtime = { group = "androidx.lifecycle", name = "lifecycle-runtime", version.ref = "androidx-lifecycle" }
29+
androidx-lifecycle-runtime-compose = { group = "androidx.lifecycle", name = "lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
2930
androidx-lifecycle-livedata-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
3031
android-material = { group = "com.google.android.material", name = "material", version.ref = "material" }
3132
test-mockito = { group = "org.mockito", name = "mockito-core", version.ref = "mockito" }

konfetti/compose/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ dependencies {
6262

6363
implementation(libs.compose.foundation)
6464
implementation(libs.compose.ui)
65+
implementation(libs.androidx.lifecycle.runtime.compose)
6566

6667
testImplementation(libs.test.junit)
6768
androidTestImplementation(libs.test.junit.ext)

konfetti/compose/src/main/java/nl/dionsegijn/konfetti/compose/KonfettiView.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import androidx.compose.ui.Modifier
1212
import androidx.compose.ui.geometry.Offset
1313
import androidx.compose.ui.graphics.drawscope.withTransform
1414
import androidx.compose.ui.layout.onGloballyPositioned
15+
import androidx.lifecycle.Lifecycle
16+
import androidx.lifecycle.compose.LifecycleEventEffect
1517
import nl.dionsegijn.konfetti.core.Particle
1618
import nl.dionsegijn.konfetti.core.Party
1719
import nl.dionsegijn.konfetti.core.PartySystem
@@ -49,6 +51,9 @@ fun KonfettiView(
4951
*/
5052
val imageStore = remember { ImageStore() }
5153

54+
LifecycleEventEffect(event = Lifecycle.Event.ON_RESUME) {
55+
frameTime.value = 0L
56+
}
5257
LaunchedEffect(Unit) {
5358
partySystems =
5459
parties.map {

0 commit comments

Comments
 (0)