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

Restore commonMain to AOSP state (exceptions) #1758

Draft
wants to merge 2 commits into
base: jb-main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package androidx.compose.animation.core

import androidx.compose.animation.core.internal.PlatformOptimizedCancellationException
import androidx.compose.runtime.Stable
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -59,8 +58,7 @@ internal enum class MutatePriority {
* lookups to build the exception message and stack trace collection. Remove if these are changed in
* kotlinx.coroutines.
*/
private class MutationInterruptedException :
PlatformOptimizedCancellationException("Mutation interrupted")
internal expect class MutationInterruptedException() : CancellationException

/**
* Mutual exclusion for UI state mutation over time.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
* limitations under the License.
*/

package androidx.compose.material.internal
package androidx.compose.animation.core

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message)
internal actual class MutationInterruptedException : CancellationException("Mutation interrupted")
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
* limitations under the License.
*/

package androidx.compose.material.internal
package androidx.compose.animation.core

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message) {

internal actual class MutationInterruptedException : CancellationException("Mutation interrupted") {
override fun fillInStackTrace(): Throwable {
// Avoid null.clone() on Android <= 6.0 when accessing stackTrace
stackTrace = emptyArray()
return this
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package androidx.compose.foundation

import kotlinx.coroutines.CancellationException

internal expect class AtomicReference<V>(value: V) {
fun get(): V

Expand All @@ -35,11 +33,3 @@ internal expect class AtomicLong(value: Long) {

fun getAndIncrement(): Long
}

/**
* Represents a platform-optimized cancellation exception.
* This allows us to configure exceptions separately on JVM and other platforms.
*/
internal expect abstract class PlatformOptimizedCancellationException(
message: String? = null
) : CancellationException
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ enum class MutatePriority {
* lookups to build the exception message and stack trace collection. Remove if these are changed in
* kotlinx.coroutines.
*/
private class MutationInterruptedException :
PlatformOptimizedCancellationException("Mutation interrupted")
internal expect class MutationInterruptedException() : CancellationException

/**
* Mutual exclusion for UI state mutation over time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import androidx.compose.foundation.OverscrollEffect
import androidx.compose.foundation.gestures.DragEvent.DragDelta
import androidx.compose.foundation.gestures.snapping.SnapLayoutInfoProvider
import androidx.compose.foundation.gestures.snapping.snapFlingBehavior
import androidx.compose.foundation.PlatformOptimizedCancellationException
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.internal.checkPrecondition
import androidx.compose.foundation.internal.requirePrecondition
Expand Down Expand Up @@ -1538,7 +1537,7 @@ private fun Float.coerceToTarget(target: Float): Float {
return if (target > 0) coerceAtMost(target) else coerceAtLeast(target)
}

private class AnchoredDragFinishedSignal : PlatformOptimizedCancellationException()
internal expect class AnchoredDragFinishedSignal() : CancellationException

private suspend fun <I> restartable(inputs: () -> I, block: suspend (I) -> Unit) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.foundation.FocusedBoundsObserverNode
import androidx.compose.foundation.LocalOverscrollFactory
import androidx.compose.foundation.MutatePriority
import androidx.compose.foundation.OverscrollEffect
import androidx.compose.foundation.PlatformOptimizedCancellationException
import androidx.compose.foundation.gestures.Orientation.Horizontal
import androidx.compose.foundation.gestures.Orientation.Vertical
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down Expand Up @@ -1044,6 +1043,4 @@ private suspend fun ScrollingLogic.semanticsScrollBy(offset: Offset): Offset {
return previousValue.toOffset()
}

internal class FlingCancellationException() : PlatformOptimizedCancellationException(
message = "The fling animation was cancelled"
)
internal expect class FlingCancellationException() : CancellationException
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ private class DefaultPagerNestedScrollConnection(
source: NestedScrollSource
): Offset {
if (source == NestedScrollSource.SideEffect && available.mainAxis() != 0f) {
throw CancellationException("End of scrollable area reached")
throw CancellationException("Scroll cancelled")
}
return Offset.Zero
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,10 +14,8 @@
* limitations under the License.
*/

package androidx.compose.animation.core.internal
package androidx.compose.foundation

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message)
internal actual class MutationInterruptedException : CancellationException(message = null)
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@
* limitations under the License.
*/

package androidx.compose.material.internal
package androidx.compose.foundation.gestures

import kotlinx.coroutines.CancellationException

/**
* Represents a platform-optimized cancellation exception.
* This allows us to configure exceptions separately on JVM and other platforms.
*/
internal expect abstract class PlatformOptimizedCancellationException(
message: String? = null
) : CancellationException
internal actual class AnchoredDragFinishedSignal : CancellationException(message = null)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.foundation.gestures

import kotlinx.coroutines.CancellationException

internal actual class FlingCancellationException :
CancellationException("The fling animation was cancelled")
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 The Android Open Source Project
* Copyright 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -18,14 +18,10 @@ package androidx.compose.foundation

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message) {

internal actual class MutationInterruptedException : CancellationException() {
override fun fillInStackTrace(): Throwable {
// Avoid null.clone() on Android <= 6.0 when accessing stackTrace
stackTrace = emptyArray()
return this
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,14 @@
* limitations under the License.
*/

package androidx.compose.material3.internal
package androidx.compose.foundation.gestures

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message) {

internal actual class AnchoredDragFinishedSignal : CancellationException() {
override fun fillInStackTrace(): Throwable {
// Avoid null.clone() on Android <= 6.0 when accessing stackTrace
stackTrace = emptyArray()
return this
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.animation.core.generateDecayAnimationSpec
import androidx.compose.animation.rememberSplineBasedDecay
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import kotlinx.coroutines.CancellationException

internal actual fun platformDefaultFlingBehavior(): ScrollableDefaultFlingBehavior =
DefaultFlingBehavior(
Expand All @@ -34,3 +35,12 @@ internal actual fun rememberPlatformDefaultFlingBehavior(): FlingBehavior {
DefaultFlingBehavior(flingSpec)
}
}

internal actual class FlingCancellationException :
CancellationException("The fling animation was cancelled") {
override fun fillInStackTrace(): Throwable {
// Avoid null.clone() on Android <= 6.0 when accessing stackTrace
stackTrace = emptyArray()
return this
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.draggable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.offset
import androidx.compose.material.internal.PlatformOptimizedCancellationException
import androidx.compose.runtime.Stable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -714,7 +713,7 @@ internal object AnchoredDraggableDefaults {
val AnimationSpec = SpringSpec<Float>()
}

private class AnchoredDragFinishedSignal : PlatformOptimizedCancellationException()
internal expect class AnchoredDragFinishedSignal() : CancellationException

private suspend fun <I> restartable(inputs: () -> I, block: suspend (I) -> Unit) {
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package androidx.compose.material

import kotlinx.coroutines.CancellationException

internal actual class AnchoredDragFinishedSignal : CancellationException(message = null)

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2024 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,18 +14,14 @@
* limitations under the License.
*/

package androidx.compose.animation.core.internal
package androidx.compose.material

import kotlinx.coroutines.CancellationException

internal actual abstract class PlatformOptimizedCancellationException actual constructor(
message: String?
) : CancellationException(message) {

internal actual class AnchoredDragFinishedSignal : CancellationException() {
override fun fillInStackTrace(): Throwable {
// Avoid null.clone() on Android <= 6.0 when accessing stackTrace
stackTrace = emptyArray()
return this
}

}
Loading
Loading