diff --git a/examples/widgetsgallery/android/build.gradle.kts b/examples/widgetsgallery/android/build.gradle.kts index 20040c60e6..f752a9ce13 100644 --- a/examples/widgetsgallery/android/build.gradle.kts +++ b/examples/widgetsgallery/android/build.gradle.kts @@ -22,4 +22,11 @@ android { dependencies { implementation(project(":common")) + implementation("androidx.activity:activity-compose:1.3.0-alpha02") { + exclude(group = "androidx.compose.animation") + exclude(group = "androidx.compose.foundation") + exclude(group = "androidx.compose.material") + exclude(group = "androidx.compose.runtime") + exclude(group = "androidx.compose.ui") + } } \ No newline at end of file diff --git a/examples/widgetsgallery/android/src/main/java/org/jetbrains/compose/demo/widgets/MainActivity.kt b/examples/widgetsgallery/android/src/main/java/org/jetbrains/compose/demo/widgets/MainActivity.kt index e2e221a68e..7f1ad35382 100644 --- a/examples/widgetsgallery/android/src/main/java/org/jetbrains/compose/demo/widgets/MainActivity.kt +++ b/examples/widgetsgallery/android/src/main/java/org/jetbrains/compose/demo/widgets/MainActivity.kt @@ -1,8 +1,8 @@ package org.jetbrains.compose.demo.widgets import android.os.Bundle +import androidx.activity.compose.setContent import androidx.appcompat.app.AppCompatActivity -import androidx.compose.ui.platform.setContent import org.jetbrains.compose.demo.widgets.ui.MainView class MainActivity : AppCompatActivity() { diff --git a/examples/widgetsgallery/build.gradle.kts b/examples/widgetsgallery/build.gradle.kts index d3ed392005..1e6a3e0e53 100644 --- a/examples/widgetsgallery/build.gradle.kts +++ b/examples/widgetsgallery/build.gradle.kts @@ -9,10 +9,10 @@ buildscript { dependencies { // __LATEST_COMPOSE_RELEASE_VERSION__ - classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build146") + classpath("org.jetbrains.compose:compose-gradle-plugin:0.3.0-build154") classpath("com.android.tools.build:gradle:4.0.1") // __KOTLIN_COMPOSE_VERSION__ - classpath(kotlin("gradle-plugin", version = "1.4.21-2")) + classpath(kotlin("gradle-plugin", version = "1.4.30")) } } diff --git a/examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt b/examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt index 16967b720e..7ea8c3f46a 100644 --- a/examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt +++ b/examples/widgetsgallery/common/src/androidMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Resources.kt @@ -3,18 +3,20 @@ package org.jetbrains.compose.demo.widgets.platform import androidx.compose.runtime.Composable import androidx.compose.ui.graphics.ImageBitmap import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.imageResource +import androidx.compose.ui.res.vectorResource import org.jetbrains.compose.demo.widgets.R @Composable actual fun imageResource(res: String): ImageBitmap { val id = drawableId(res) - return androidx.compose.ui.res.imageResource(id) + return ImageBitmap.imageResource(id) } @Composable actual fun vectorResource(res: String): ImageVector { val id = drawableId(res) - return androidx.compose.ui.res.vectorResource(id) + return ImageVector.vectorResource(id) } // TODO: improve resource loading diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt index dbca876576..9b6105ff17 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/MainView.kt @@ -1,21 +1,22 @@ package org.jetbrains.compose.demo.widgets.ui -import androidx.compose.animation.animate import androidx.compose.animation.core.Spring import androidx.compose.animation.core.SpringSpec +import androidx.compose.animation.core.animateDpAsState import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* -import androidx.compose.foundation.lazy.LazyColumnFor +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items import androidx.compose.foundation.lazy.rememberLazyListState -import androidx.compose.material.AmbientContentColor +import androidx.compose.foundation.text.selection.DisableSelection +import androidx.compose.material.LocalContentColor import androidx.compose.material.Text import androidx.compose.runtime.* import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clipToBounds -import androidx.compose.ui.platform.AmbientDensity -import androidx.compose.ui.selection.DisableSelection +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.TextUnit @@ -46,10 +47,10 @@ fun WidgetsPanel() { val animatedSize = if (panelState.splitter.isResizing) { if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize } else { - animate( + animateDpAsState( if (panelState.isExpanded) panelState.expandedSize else panelState.collapsedSize, SpringSpec(stiffness = Spring.StiffnessLow) - ) + ).value } VerticalSplittable( @@ -82,24 +83,26 @@ fun WidgetsPanel() { @Composable private fun WidgetsListView(widgetsTypeState: MutableState) { Box { - with(AmbientDensity.current) { + with(LocalDensity.current) { val scrollState = rememberLazyListState() val fontSize = 14.sp val lineHeight = fontSize.toDp() * 1.5f - val items = WidgetsType.sortedValues - LazyColumnFor( - items, + val sortedItems = WidgetsType.sortedValues + LazyColumn( modifier = Modifier.fillMaxSize().withoutWidthConstraints(), - state = scrollState, - itemContent = { WidgetsListItemViewImpl(it, widgetsTypeState, fontSize, lineHeight) } - ) + state = scrollState + ) { + items(sortedItems) { + WidgetsListItemViewImpl(it, widgetsTypeState, fontSize, lineHeight) + } + } VerticalScrollbar( Modifier.align(Alignment.CenterEnd), scrollState, - items.size, + sortedItems.size, lineHeight ) } @@ -124,7 +127,7 @@ private fun WidgetsListItemViewImpl( .padding(start = 16.dp) ) { var inFocus by remember { mutableStateOf(false) } - val textColor = AmbientContentColor.current.let { + val textColor = LocalContentColor.current.let { when { isCurrent -> it inFocus -> it.copy(alpha = 0.6f) diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt index 45de67c6cf..c624bff519 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/WidgetView.kt @@ -1,7 +1,8 @@ package org.jetbrains.compose.demo.widgets.ui -import androidx.compose.foundation.ScrollableColumn import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.runtime.Composable import androidx.compose.runtime.MutableState import androidx.compose.ui.Modifier @@ -12,20 +13,18 @@ fun WidgetsView( widgetsTypeState: MutableState, modifier: Modifier ) { - ScrollableColumn(modifier = modifier) { - Column { - @Suppress("UNUSED_VARIABLE") - val exhaustive = when (widgetsTypeState.value) { - WidgetsType.APP_BARS -> AppBars() - WidgetsType.BUTTONS -> Buttons() - WidgetsType.CHIPS -> Chips() - WidgetsType.LOADERS -> Loaders() - WidgetsType.SNACK_BARS -> SnackBars() - WidgetsType.TEXT_VIEWS -> TextViews() - WidgetsType.TEXT_INPUTS -> TextInputs() - WidgetsType.TOGGLES -> Toggles() - WidgetsType.UI_CARDS -> UICards() - } + Column(modifier = modifier.verticalScroll(state = rememberScrollState())) { + @Suppress("UNUSED_VARIABLE") + val exhaustive = when (widgetsTypeState.value) { + WidgetsType.APP_BARS -> AppBars() + WidgetsType.BUTTONS -> Buttons() + WidgetsType.CHIPS -> Chips() + WidgetsType.LOADERS -> Loaders() + WidgetsType.SNACK_BARS -> SnackBars() + WidgetsType.TEXT_VIEWS -> TextViews() + WidgetsType.TEXT_INPUTS -> TextInputs() + WidgetsType.TOGGLES -> Toggles() + WidgetsType.UI_CARDS -> UICards() } } } diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt index fb0325769e..500c9ffc22 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/AppBars.kt @@ -81,7 +81,7 @@ private fun TopAppBarsDemo() { imageResource(Res.drawable.p6), contentDescription = "", modifier = Modifier.padding(vertical = 4.dp, horizontal = 8.dp) - .preferredSize(32.dp).clip(CircleShape) + .requiredSize(32.dp).clip(CircleShape) ) }, actions = { diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt index 526ae03c8b..9916f3a356 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Chips.kt @@ -87,7 +87,7 @@ private fun CustomImageChip( Image( imageResource(imageId), contentDescription = null, - modifier = Modifier.padding(8.dp).preferredSize(20.dp).clip(CircleShape) + modifier = Modifier.padding(8.dp).requiredSize(20.dp).clip(CircleShape) ) Text( text = text, diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Toggles.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Toggles.kt index 4797a15dc7..f709db7a9b 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Toggles.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/Toggles.kt @@ -67,7 +67,7 @@ fun Toggles() { Slider(value = sliderState2, modifier = Modifier.fillMaxWidth().padding(8.dp), valueRange = 0f..100f, steps = 5, - thumbColor = MaterialTheme.colors.secondary, + colors = SliderDefaults.colors(thumbColor = MaterialTheme.colors.secondary), onValueChange = { newValue -> sliderState2 = newValue } diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt index cdfc20cb12..81b7a55d2c 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/screens/UICards.kt @@ -15,6 +15,7 @@ import org.jetbrains.compose.demo.widgets.platform.Res import org.jetbrains.compose.demo.widgets.platform.imageResource import org.jetbrains.compose.demo.widgets.theme.typography +@OptIn(ExperimentalMaterialApi::class) @Composable fun UICards() { val item = remember { DemoDataProvider.item } @@ -54,7 +55,7 @@ fun UICards() { Image( imageResource(Res.drawable.p3), contentDescription = null, - modifier = Modifier.preferredSize(60.dp) + modifier = Modifier.requiredSize(60.dp) ) Text(text = item.title, modifier = Modifier.padding(16.dp)) } diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/ResizablePanel.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/ResizablePanel.kt index 826c1638f7..a0aeeb49ef 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/ResizablePanel.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/ResizablePanel.kt @@ -1,13 +1,11 @@ package org.jetbrains.compose.demo.widgets.ui.utils -import androidx.compose.animation.animate -import androidx.compose.animation.core.Spring -import androidx.compose.animation.core.SpringSpec +import androidx.compose.animation.core.* import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* -import androidx.compose.material.AmbientContentColor import androidx.compose.material.Icon +import androidx.compose.material.LocalContentColor import androidx.compose.material.Text import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.ArrowBack @@ -38,7 +36,10 @@ fun ResizablePanel( title: String, content: @Composable () -> Unit, ) { - val alpha = animate(if (state.isExpanded) 1f else 0f, SpringSpec(stiffness = Spring.StiffnessLow),) + val alpha = animateFloatAsState( + if (state.isExpanded) 1f else 0f, + SpringSpec(stiffness = Spring.StiffnessLow), + ).value Box(modifier) { Column { @@ -56,7 +57,7 @@ fun ResizablePanel( Icon( if (state.isExpanded) Icons.Default.ArrowBack else Icons.Default.ArrowForward, contentDescription = if (state.isExpanded) "Collapse" else "Expand", - tint = AmbientContentColor.current, + tint = LocalContentColor.current, modifier = Modifier .size(24.dp) .padding(end = 8.dp) diff --git a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/VerticalSplittable.kt b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/VerticalSplittable.kt index 90a97e4ec7..450fa865ea 100644 --- a/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/VerticalSplittable.kt +++ b/examples/widgetsgallery/common/src/commonMain/kotlin/org/jetbrains/compose/demo/widgets/ui/utils/VerticalSplittable.kt @@ -2,6 +2,8 @@ package org.jetbrains.compose.demo.widgets.ui.utils import androidx.compose.foundation.background import androidx.compose.foundation.gestures.draggable +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.gestures.rememberDraggableState import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.width @@ -10,9 +12,9 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.gesture.scrollorientationlocking.Orientation import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.Layout +import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.unit.Constraints import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -32,7 +34,7 @@ fun VerticalSplittable( ) = Layout({ children() VerticalSplitter(splitterState, onResize) -}, modifier, measureBlock = { measurables, constraints -> +}, modifier, measurePolicy = { measurables, constraints -> require(measurables.size == 3) val firstPlaceable = measurables[0].measure(constraints.copy(minWidth = 0)) @@ -61,6 +63,7 @@ fun VerticalSplitter( onResize: (delta: Dp) -> Unit, color: Color = Color.DarkGray ) = Box { + val density = LocalDensity.current Box( Modifier .width(8.dp) @@ -68,13 +71,16 @@ fun VerticalSplitter( .run { if (splitterState.isResizeEnabled) { this.draggable( - Orientation.Horizontal, + state = rememberDraggableState { + with(density) { + onResize(it.toDp()) + } + }, + orientation = Orientation.Horizontal, startDragImmediately = true, onDragStarted = { splitterState.isResizing = true }, onDragStopped = { splitterState.isResizing = false } - ) { - onResize(it.toDp()) - }.cursorForHorizontalResize() + ).cursorForHorizontalResize() } else { this } diff --git a/examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt b/examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt index 21f9b94dbd..bb64680993 100644 --- a/examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt +++ b/examples/widgetsgallery/common/src/desktopMain/kotlin/org/jetbrains/compose/demo/widgets/platform/Mouse.kt @@ -1,6 +1,6 @@ package org.jetbrains.compose.demo.widgets.platform -import androidx.compose.desktop.AppWindowAmbient +import androidx.compose.desktop.LocalAppWindow import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -21,9 +21,9 @@ actual fun Modifier.cursorForHorizontalResize(): Modifier = composed { var isHover by remember { mutableStateOf(false) } if (isHover) { - AppWindowAmbient.current!!.window.cursor = Cursor(Cursor.E_RESIZE_CURSOR) + LocalAppWindow.current.window.cursor = Cursor(Cursor.E_RESIZE_CURSOR) } else { - AppWindowAmbient.current!!.window.cursor = Cursor.getDefaultCursor() + LocalAppWindow.current.window.cursor = Cursor.getDefaultCursor() } pointerMoveFilter( diff --git a/examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt b/examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt index 9c382b78be..df9f411116 100644 --- a/examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt +++ b/examples/widgetsgallery/desktop/src/jvmMain/kotlin/org/jetbrains/compose/demo/widgets/main.kt @@ -1,14 +1,12 @@ package org.jetbrains.compose.demo.widgets import androidx.compose.desktop.Window -import androidx.compose.foundation.layout.ExperimentalLayout import androidx.compose.ui.unit.IntSize import org.jetbrains.compose.demo.widgets.ui.MainView import java.awt.Dimension import java.awt.Toolkit import javax.swing.SwingUtilities.invokeLater -@OptIn(ExperimentalLayout::class) fun main() { invokeLater { Window(