From ae7c8cf4fea59bd63eb9106fa0522136b213954b Mon Sep 17 00:00:00 2001 From: Rob Orgiu Date: Thu, 5 Dec 2024 15:05:24 +0100 Subject: [PATCH 1/2] Update List-Detail to latest M3 alpha --- .../list-detail-compose/app/build.gradle | 26 +++++++-------- .../listdetailcompose/ui/ListDetailSample.kt | 32 ++++++++++++++----- .../list-detail-compose/build.gradle | 6 ++-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/CanonicalLayouts/list-detail-compose/app/build.gradle b/CanonicalLayouts/list-detail-compose/app/build.gradle index 8d1f5bb71..b47f01b7c 100644 --- a/CanonicalLayouts/list-detail-compose/app/build.gradle +++ b/CanonicalLayouts/list-detail-compose/app/build.gradle @@ -16,7 +16,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' - id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" + id("org.jetbrains.kotlin.plugin.compose") version "2.0.20" } android { @@ -66,22 +66,22 @@ composeCompiler { } dependencies { - def composeBom = platform('androidx.compose:compose-bom:2024.09.00') + def composeBom = platform('androidx.compose:compose-bom:2024.11.00') implementation(composeBom) implementation "com.google.accompanist:accompanist-adaptive:0.32.0" - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.5' - implementation 'androidx.activity:activity-compose:1.9.2' - implementation "androidx.compose.foundation:foundation:1.7.0" - implementation "androidx.compose.ui:ui:1.7.0" + implementation 'androidx.core:core-ktx:1.15.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7' + implementation 'androidx.activity:activity-compose:1.9.3' + implementation "androidx.compose.foundation:foundation:1.7.5" + implementation "androidx.compose.ui:ui:1.7.5" implementation "androidx.compose.ui:ui-tooling-preview" implementation "androidx.window:window:1.3.0" - implementation 'androidx.compose.material3:material3:1.3.0' - implementation 'androidx.compose.material3.adaptive:adaptive:1.1.0-alpha02' - implementation 'androidx.compose.material3.adaptive:adaptive-layout:1.1.0-alpha02' - implementation 'androidx.compose.material3.adaptive:adaptive-navigation:1.1.0-alpha02' - implementation "androidx.compose.material3:material3-window-size-class:1.3.0" - implementation "androidx.compose.animation:animation:1.7.0" + implementation 'androidx.compose.material3:material3:1.4.0-alpha04' + implementation 'androidx.compose.material3.adaptive:adaptive:1.1.0-alpha07' + implementation 'androidx.compose.material3.adaptive:adaptive-layout:1.1.0-alpha07' + implementation 'androidx.compose.material3.adaptive:adaptive-navigation:1.1.0-alpha07' + implementation "androidx.compose.material3:material3-window-size-class:1.3.1" + implementation "androidx.compose.animation:animation:1.7.5" testImplementation 'junit:junit:4.13.2' } diff --git a/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetailSample.kt b/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetailSample.kt index 3e55a7252..7285b7511 100644 --- a/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetailSample.kt +++ b/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetailSample.kt @@ -29,6 +29,7 @@ import androidx.compose.animation.SharedTransitionScope import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues @@ -43,29 +44,30 @@ import androidx.compose.foundation.selection.selectableGroup import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults +import androidx.compose.material3.LocalMinimumInteractiveComponentSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import androidx.compose.material3.VerticalDragHandle import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi -import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo import androidx.compose.material3.adaptive.layout.AnimatedPane import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole import androidx.compose.material3.adaptive.layout.PaneAdaptedValue -import androidx.compose.material3.adaptive.layout.PaneExpansionDragHandle import androidx.compose.material3.adaptive.layout.rememberPaneExpansionState import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp -import androidx.window.core.layout.WindowWidthSizeClass import com.example.listdetailcompose.R +import kotlinx.coroutines.launch // Create some simple sample data private val loremIpsum = """ @@ -96,11 +98,14 @@ private data class DefinedWord( fun ListDetailSample() { var selectedWordIndex: Int? by rememberSaveable { mutableStateOf(null) } val navigator = rememberListDetailPaneScaffoldNavigator() + val scope = rememberCoroutineScope() val isListAndDetailVisible = navigator.scaffoldValue[ListDetailPaneScaffoldRole.Detail] == PaneAdaptedValue.Expanded && navigator.scaffoldValue[ListDetailPaneScaffoldRole.List] == PaneAdaptedValue.Expanded BackHandler(enabled = navigator.canNavigateBack()) { - navigator.navigateBack() + scope.launch { + navigator.navigateBack() + } } SharedTransitionLayout { @@ -122,7 +127,9 @@ fun ListDetailSample() { }, onIndexClick = { index -> selectedWordIndex = index - navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) + scope.launch { + navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) + } }, isListAndDetailVisible = isListAndDetailVisible, isListVisible = !isDetailVisible, @@ -147,7 +154,16 @@ fun ListDetailSample() { }, paneExpansionState = rememberPaneExpansionState(navigator.scaffoldValue), paneExpansionDragHandle = { state -> - PaneExpansionDragHandle(state, Color.Red) + val interactionSource = + remember { MutableInteractionSource() } + VerticalDragHandle( + modifier = + Modifier.paneExpansionDraggable( + state, + LocalMinimumInteractiveComponentSize.current, + interactionSource + ), interactionSource = interactionSource + ) } ) } @@ -312,7 +328,7 @@ private fun DetailContent( state, animatedVisibilityScope = animatedVisibilityScope ) - } + } } else { Modifier } diff --git a/CanonicalLayouts/list-detail-compose/build.gradle b/CanonicalLayouts/list-detail-compose/build.gradle index c54adb6cb..b03e2f384 100644 --- a/CanonicalLayouts/list-detail-compose/build.gradle +++ b/CanonicalLayouts/list-detail-compose/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ plugins { - id 'com.android.application' version '8.6.0' apply false - id 'com.android.library' version '8.6.0' apply false - id 'org.jetbrains.kotlin.android' version '2.0.0' apply false + id 'com.android.application' version '8.7.3' apply false + id 'com.android.library' version '8.7.3' apply false + id 'org.jetbrains.kotlin.android' version '2.0.20' apply false } diff --git a/CanonicalLayouts/list-detail-compose/gradle/wrapper/gradle-wrapper.properties b/CanonicalLayouts/list-detail-compose/gradle/wrapper/gradle-wrapper.properties index f9f3c8cbd..839d03c2d 100644 --- a/CanonicalLayouts/list-detail-compose/gradle/wrapper/gradle-wrapper.properties +++ b/CanonicalLayouts/list-detail-compose/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed May 25 14:11:15 UTC 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From eeb3e9a3e543ebe12d6af9307f00d2a35d3a5682 Mon Sep 17 00:00:00 2001 From: Rob Orgiu Date: Thu, 5 Dec 2024 15:20:19 +0100 Subject: [PATCH 2/2] Update Supporting Pane to latest Material 3 alpha --- .../supporting-pane-compose/app/build.gradle | 20 ++++++------ .../ui/SupportingPaneSample.kt | 32 +++++++++++++++---- .../supporting-pane-compose/build.gradle | 6 ++-- .../gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 40 insertions(+), 20 deletions(-) diff --git a/CanonicalLayouts/supporting-pane-compose/app/build.gradle b/CanonicalLayouts/supporting-pane-compose/app/build.gradle index 743b34eca..9eaa7ded1 100644 --- a/CanonicalLayouts/supporting-pane-compose/app/build.gradle +++ b/CanonicalLayouts/supporting-pane-compose/app/build.gradle @@ -17,7 +17,7 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' - id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" + id("org.jetbrains.kotlin.plugin.compose") version "2.0.20" } @@ -68,19 +68,19 @@ composeCompiler { } dependencies { - def composeBom = platform('androidx.compose:compose-bom:2024.09.00') + def composeBom = platform('androidx.compose:compose-bom:2024.11.00') implementation(composeBom) - implementation 'androidx.core:core-ktx:1.13.1' - implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.5' - implementation 'androidx.activity:activity-compose:1.9.2' + implementation 'androidx.core:core-ktx:1.15.0' + implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.8.7' + implementation 'androidx.activity:activity-compose:1.9.3' implementation "androidx.compose.ui:ui" implementation "androidx.compose.ui:ui-tooling-preview" implementation "androidx.window:window:1.3.0" - implementation 'androidx.compose.material3:material3:1.3.0' - implementation 'androidx.compose.material3.adaptive:adaptive:1.1.0-alpha02' - implementation 'androidx.compose.material3.adaptive:adaptive-layout:1.1.0-alpha02' - implementation 'androidx.compose.material3.adaptive:adaptive-navigation:1.1.0-alpha02' - implementation "androidx.compose.material3:material3-window-size-class:1.3.0" + implementation 'androidx.compose.material3:material3:1.4.0-alpha04' + implementation 'androidx.compose.material3.adaptive:adaptive:1.1.0-alpha07' + implementation 'androidx.compose.material3.adaptive:adaptive-layout:1.1.0-alpha07' + implementation 'androidx.compose.material3.adaptive:adaptive-navigation:1.1.0-alpha07' + implementation "androidx.compose.material3:material3-window-size-class:1.3.1" testImplementation 'junit:junit:4.13.2' } \ No newline at end of file diff --git a/CanonicalLayouts/supporting-pane-compose/app/src/main/java/com/example/supportingpanecompose/ui/SupportingPaneSample.kt b/CanonicalLayouts/supporting-pane-compose/app/src/main/java/com/example/supportingpanecompose/ui/SupportingPaneSample.kt index 18fa78ce1..a0748589f 100644 --- a/CanonicalLayouts/supporting-pane-compose/app/src/main/java/com/example/supportingpanecompose/ui/SupportingPaneSample.kt +++ b/CanonicalLayouts/supporting-pane-compose/app/src/main/java/com/example/supportingpanecompose/ui/SupportingPaneSample.kt @@ -18,6 +18,7 @@ package com.example.supportingpanecompose.ui import androidx.activity.compose.BackHandler import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -25,11 +26,12 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items +import androidx.compose.material3.LocalMinimumInteractiveComponentSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text +import androidx.compose.material3.VerticalDragHandle import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi import androidx.compose.material3.adaptive.layout.AnimatedPane -import androidx.compose.material3.adaptive.layout.PaneExpansionDragHandle import androidx.compose.material3.adaptive.layout.SupportingPaneScaffold import androidx.compose.material3.adaptive.layout.SupportingPaneScaffoldRole import androidx.compose.material3.adaptive.layout.rememberPaneExpansionState @@ -37,14 +39,16 @@ import androidx.compose.material3.adaptive.navigation.rememberSupportingPaneScaf import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import com.example.supportingpanecompose.R +import kotlinx.coroutines.launch // Create some simple sample data private val data = mapOf( @@ -61,9 +65,12 @@ private val data = mapOf( fun SupportingPaneSample() { var selectedTopic: String by rememberSaveable { mutableStateOf(data.keys.first()) } val navigator = rememberSupportingPaneScaffoldNavigator() + val scope = rememberCoroutineScope() BackHandler(enabled = navigator.canNavigateBack()) { - navigator.navigateBack() + scope.launch { + navigator.navigateBack() + } } SupportingPaneScaffold( @@ -92,7 +99,9 @@ fun SupportingPaneSample() { .clickable { selectedTopic = relatedTopic if (navigator.canNavigateBack()) { - navigator.navigateBack() + scope.launch { + navigator.navigateBack() + } } } ) { @@ -120,7 +129,9 @@ fun SupportingPaneSample() { .fillMaxWidth() .padding(all = 8.dp) .clickable { - navigator.navigateTo(SupportingPaneScaffoldRole.Supporting) + scope.launch { + navigator.navigateTo(SupportingPaneScaffoldRole.Supporting) + } }, contentAlignment = Alignment.Center ) { @@ -134,6 +145,15 @@ fun SupportingPaneSample() { }, paneExpansionState = rememberPaneExpansionState(navigator.scaffoldValue), paneExpansionDragHandle = { state -> - PaneExpansionDragHandle(state, Color.Red) + val interactionSource = + remember { MutableInteractionSource() } + VerticalDragHandle( + modifier = + Modifier.paneExpansionDraggable( + state, + LocalMinimumInteractiveComponentSize.current, + interactionSource + ), interactionSource = interactionSource + ) }) } diff --git a/CanonicalLayouts/supporting-pane-compose/build.gradle b/CanonicalLayouts/supporting-pane-compose/build.gradle index c54adb6cb..b03e2f384 100644 --- a/CanonicalLayouts/supporting-pane-compose/build.gradle +++ b/CanonicalLayouts/supporting-pane-compose/build.gradle @@ -14,7 +14,7 @@ * limitations under the License. */ plugins { - id 'com.android.application' version '8.6.0' apply false - id 'com.android.library' version '8.6.0' apply false - id 'org.jetbrains.kotlin.android' version '2.0.0' apply false + id 'com.android.application' version '8.7.3' apply false + id 'com.android.library' version '8.7.3' apply false + id 'org.jetbrains.kotlin.android' version '2.0.20' apply false } diff --git a/CanonicalLayouts/supporting-pane-compose/gradle/wrapper/gradle-wrapper.properties b/CanonicalLayouts/supporting-pane-compose/gradle/wrapper/gradle-wrapper.properties index f9f3c8cbd..839d03c2d 100644 --- a/CanonicalLayouts/supporting-pane-compose/gradle/wrapper/gradle-wrapper.properties +++ b/CanonicalLayouts/supporting-pane-compose/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed May 25 14:11:15 UTC 2022 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME