Skip to content
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

Don't use Compose leaked internal AtomicReference #649

Merged
merged 4 commits into from
Jan 9, 2024
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
1 change: 0 additions & 1 deletion appyx-navigation/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ kotlin {

implementation(libs.androidx.activity.compose)
implementation(libs.androidx.lifecycle.java8)

}
}
val desktopMain by getting {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bumble.appyx.navigation.platform

import androidx.compose.runtime.AtomicReference
import kotlin.concurrent.AtomicReference

interface Cancellable {
/**
Expand Down Expand Up @@ -39,7 +39,7 @@ abstract class OnBackPressedCallback(
* added to.
*/
fun remove() {
for (cancellable in cancellablesReference.get()) {
for (cancellable in cancellablesReference.value) {
cancellable.cancel()
}
}
Expand All @@ -49,10 +49,10 @@ abstract class OnBackPressedCallback(
*/
abstract fun handleOnBackPressed()
fun addCancellable(cancellable: Cancellable) {
cancellablesReference.set(cancellablesReference.get() + cancellable)
cancellablesReference.getAndSet(cancellablesReference.value + cancellable)
}

fun removeCancellable(cancellable: Cancellable) {
cancellablesReference.set(cancellablesReference.get() - cancellable)
cancellablesReference.getAndSet(cancellablesReference.value - cancellable)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bumble.appyx.navigation.platform

import androidx.compose.runtime.AtomicReference

interface Cancellable {
/**
* Cancel the subscription. This call should be idempotent, making it safe to
Expand Down Expand Up @@ -31,15 +29,14 @@ abstract class OnBackPressedCallback(
*
* @return Whether this callback should be considered enabled.
*/
private val cancellablesReference: AtomicReference<List<Cancellable>> =
AtomicReference(emptyList())
private val cancellables: MutableList<Cancellable> = mutableListOf()

/**
* Removes this callback from any [OnBackPressedDispatcher] it is currently
* added to.
*/
fun remove() {
for (cancellable in cancellablesReference.get()) {
for (cancellable in cancellables) {
cancellable.cancel()
}
}
Expand All @@ -49,10 +46,14 @@ abstract class OnBackPressedCallback(
*/
abstract fun handleOnBackPressed()
fun addCancellable(cancellable: Cancellable) {
cancellablesReference.set(cancellablesReference.get() + cancellable)
run {
cancellables.add(cancellable)
}
}

fun removeCancellable(cancellable: Cancellable) {
cancellablesReference.set(cancellablesReference.get() - cancellable)
run {
cancellables.remove(cancellable)
}
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ kotlin.mpp.stability.nowarn=true
kotlin.mpp.enableCInteropCommonization=true
library.version=2.0.0-alpha09
org.gradle.caching=true
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.jetbrains.compose.experimental.jscanvas.enabled=true
org.jetbrains.compose.experimental.uikit.enabled=true