Skip to content

Commit

Permalink
Restore commonMain to AOSP state (small fixes)
Browse files Browse the repository at this point in the history
Partially fixes https://youtrack.jetbrains.com/issue/CMP-5740/Upstreaming.-compilation.-other-fixes

Restore to the last merged Jetpack Compose (1.8.0-alpha07) and Material3 (1.4.0-alpha04):
- restore imports
- restore file names
- formatting
- TODO/comments removed (if we still need them, we should only keep issues)
- remove unused code

The provided functionality is no longer needed as it is implemented in `clickable` (discovered in https://youtrack.jetbrains.com/issue/CMP-5750/Upstreaming.-feature.-foundation.-toggle-on-Space)

## Testing
- CI passes

## Release Notes
N/A
  • Loading branch information
igordmn committed Dec 20, 2024
1 parent 0c234a4 commit e431376
Show file tree
Hide file tree
Showing 55 changed files with 106 additions and 466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,6 @@ public class KeyframesSpec<T>(public val config: KeyframesSpecConfig<T>) :
if (!config.keyframes.contains(config.durationMillis)) {
timestamps.add(config.durationMillis)
}

timestamps.sort()

return VectorizedKeyframesSpec(
Expand Down Expand Up @@ -772,7 +771,6 @@ public class KeyframesWithSplineSpec<T>(
if (!keyframes.contains(config.durationMillis)) {
timestamps.add(config.durationMillis)
}

timestamps.sort()
return VectorizedMonoSplineKeyframesSpec(
timestamps = timestamps,
Expand Down
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.binarySearch
import androidx.compose.runtime.Immutable
import androidx.compose.ui.graphics.IntervalTree
import androidx.compose.ui.graphics.Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,6 @@ internal constructor(
if (!keyframes.containsKey(durationMillis)) {
times.add(durationMillis)
}

times.sort()
return@run times
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 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,6 +14,6 @@
* limitations under the License.
*/

package androidx.compose.animation.core.internal;
package androidx.compose.animation.core.internal

internal expect annotation class JvmDefaultWithCompatibility()
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2022 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import androidx.compose.ui.platform.InspectorInfo
fun Modifier.dragAndDropTarget(
shouldStartDragAndDrop: (startEvent: DragAndDropEvent) -> Boolean,
target: DragAndDropTarget,
): Modifier {
return this then DropTargetElement(
target = target,
shouldStartDragAndDrop = shouldStartDragAndDrop,
)
}
): Modifier =
this then
DropTargetElement(
target = target,
shouldStartDragAndDrop = shouldStartDragAndDrop,
)

private class DropTargetElement(
val shouldStartDragAndDrop: (event: DragAndDropEvent) -> Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2022 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 Down
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 Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2022 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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@
package androidx.compose.foundation.pager

import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.snapping.calculateDistanceToDesiredSnapPosition
import androidx.compose.foundation.lazy.layout.LazyLayoutNearestRangeState
import androidx.compose.foundation.lazy.layout.findIndexByKey
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.setValue
import kotlin.math.roundToLong
import androidx.compose.ui.unit.Density
import androidx.compose.ui.util.fastMaxBy
import kotlin.math.absoluteValue
import kotlin.math.roundToInt

/**
* Contains the current scroll position represented by the first visible page and the first visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import androidx.compose.foundation.text.input.internal.TextFieldDecoratorModifie
import androidx.compose.foundation.text.input.internal.TextFieldTextLayoutModifier
import androidx.compose.foundation.text.input.internal.TextLayoutState
import androidx.compose.foundation.text.input.internal.TransformedTextFieldState
import androidx.compose.foundation.text.input.internal.selection.TextFieldHandleState
import androidx.compose.foundation.text.input.internal.selection.TextFieldSelectionState
import androidx.compose.foundation.text.input.internal.selection.TextFieldSelectionState.InputType
import androidx.compose.foundation.text.selection.SelectionHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,53 +66,55 @@ internal fun Modifier.textFieldScrollable(
interactionSource: MutableInteractionSource? = null,
enabled: Boolean = true,
overscrollEffect: OverscrollEffect? = null
) = composed(
inspectorInfo =
debugInspectorInfo {
name = "textFieldScrollable"
properties["scrollerPosition"] = scrollerPosition
properties["interactionSource"] = interactionSource
properties["enabled"] = enabled
}
) {
// do not reverse direction only in case of RTL in horizontal orientation
val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl
val reverseDirection = scrollerPosition.orientation == Orientation.Vertical || !rtl
val scrollableState = rememberScrollableState { delta ->
val newOffset = scrollerPosition.offset + delta
val consumedDelta =
when {
newOffset > scrollerPosition.maximum ->
scrollerPosition.maximum - scrollerPosition.offset
newOffset < 0f -> -scrollerPosition.offset
else -> delta
) =
composed(
inspectorInfo =
debugInspectorInfo {
name = "textFieldScrollable"
properties["scrollerPosition"] = scrollerPosition
properties["interactionSource"] = interactionSource
properties["enabled"] = enabled
}
scrollerPosition.offset += consumedDelta
consumedDelta
}
// TODO: b/255557085 remove when / if rememberScrollableState exposes lambda parameters for
// setting these
val wrappedScrollableState =
remember(scrollableState, scrollerPosition) {
object : ScrollableState by scrollableState {
override val canScrollForward by derivedStateOf {
scrollerPosition.offset < scrollerPosition.maximum
) {
// do not reverse direction only in case of RTL in horizontal orientation
val rtl = LocalLayoutDirection.current == LayoutDirection.Rtl
val reverseDirection = scrollerPosition.orientation == Orientation.Vertical || !rtl
val scrollableState = rememberScrollableState { delta ->
val newOffset = scrollerPosition.offset + delta
val consumedDelta =
when {
newOffset > scrollerPosition.maximum ->
scrollerPosition.maximum - scrollerPosition.offset
newOffset < 0f -> -scrollerPosition.offset
else -> delta
}
override val canScrollBackward by derivedStateOf {
scrollerPosition.offset > 0f
scrollerPosition.offset += consumedDelta
consumedDelta
}
// TODO: b/255557085 remove when / if rememberScrollableState exposes lambda parameters for
// setting these
val wrappedScrollableState =
remember(scrollableState, scrollerPosition) {
object : ScrollableState by scrollableState {
override val canScrollForward by derivedStateOf {
scrollerPosition.offset < scrollerPosition.maximum
}
override val canScrollBackward by derivedStateOf {
scrollerPosition.offset > 0f
}
}
}
}
val scroll = Modifier.scrollable(
orientation = scrollerPosition.orientation,
reverseDirection = reverseDirection,
overscrollEffect = overscrollEffect,
state = wrappedScrollableState,
interactionSource = interactionSource,
enabled = enabled && scrollerPosition.maximum != 0f
)
scroll
}
val scroll =
Modifier.scrollable(
orientation = scrollerPosition.orientation,
reverseDirection = reverseDirection,
overscrollEffect = overscrollEffect,
state = wrappedScrollableState,
interactionSource = interactionSource,
enabled = enabled && scrollerPosition.maximum != 0f
)
scroll
}

// Layout
// Expect/actual is needed due to a different implementation in uikit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@ package androidx.compose.foundation.text

import androidx.compose.ui.input.pointer.PointerIcon

// TODO Replace to PointerIcon.Text. No need for expect/actual
internal expect val textPointerIcon: PointerIcon

// TODO Add appropriate property to PointerIcon interface instead of bypassing abstraction layer.
// https://youtrack.jetbrains.com/issue/CMP-7145/Properly-adopt-stylus-handwriting-hover-icon
internal expect val handwritingPointerIcon: PointerIcon
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.intl.Locale
import androidx.compose.ui.text.substring
import androidx.compose.ui.text.toUpperCase
import kotlin.jvm.JvmName

/**
* A function that is ran after every change made to a [TextFieldState] by user input and can change
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ internal expect fun CharSequence.codePointAt(index: Int): Int

internal expect fun charCount(codePoint: Int): Int

// TODO: It's not used from common, consider to remove
internal expect fun CharSequence.codePointBefore(index: Int): Int
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@ internal class CursorAnimationState(val animate: Boolean) {
val job = animationJob.getAndSet(null)
job?.cancel()
}
}
}
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 Down
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 Down Expand Up @@ -63,8 +63,8 @@ import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.Velocity
import androidx.compose.ui.unit.dp
import kotlin.math.abs
import kotlin.jvm.JvmName
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min
import kotlinx.coroutines.launch
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ internal value class Strings private constructor(@Suppress("unused") private val
val SliderRangeStart = Strings(5)
val SliderRangeEnd = Strings(6)
val SnackbarPaneTitle = Strings(7)
// When adding values here, make sure to also add them in material/build.gradle,
// updateTranslations task (stringByResourceName parameter), and re-run the task
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Android Open Source Project
* Copyright 2021 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 Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit e431376

Please sign in to comment.