Skip to content

Commit f661dfe

Browse files
committed
Refactor: Update Compose snippets and dependencies
This commit includes the following changes: - Updated various Compose snippets to align with recent API changes: - Replaced `Mdc3Theme` with standard Material 3 Theming. - Removed `LocalUseFallbackRippleImplementation` as its not available in latest versions. - Replaced `Divider` with `HorizontalDivider`. - Updated `ClickableText` to use `Text` with a `clickable` modifier. - Removed `ContextualFlowLayoutExample` as `ContextualFlowRow` is deprecated. - Updated `pullToRefreshIndicator` to `pullToRefresh`. - Removed `caretSize` from `TooltipBox` as it is no longer available. - Replaced `TabRow` with `PrimaryTabRow`. - Updated Gradle wrapper to version 9.1.0. - Updated various library versions in `libs.versions.toml`, including `androidx-xr` libraries. - Corrected import for `hiltViewModel`.
1 parent d20c564 commit f661dfe

File tree

13 files changed

+34
-134
lines changed

13 files changed

+34
-134
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/components/AppBar.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fun CenterAlignedTopAppBarExample() {
218218

219219
topBar = {
220220
CenterAlignedTopAppBar(
221-
colors = TopAppBarDefaults.centerAlignedTopAppBarColors(
221+
colors = TopAppBarDefaults.topAppBarColors(
222222
containerColor = MaterialTheme.colorScheme.primaryContainer,
223223
titleContentColor = MaterialTheme.colorScheme.primary,
224224
),
@@ -431,6 +431,7 @@ fun AppBarSelectionActions(
431431
}
432432
}
433433
},
434+
modifier = modifier
434435
)
435436
}
436437
// [END android_compose_components_appbarselectionactions]
@@ -454,6 +455,7 @@ private fun AppBarMultiSelectionExample(
454455
var selectedItems by rememberSaveable { mutableStateOf(setOf<Int>()) }
455456

456457
Scaffold(
458+
modifier = modifier,
457459
topBar = { AppBarSelectionActions(selectedItems) }
458460
) { innerPadding ->
459461
LazyColumn(contentPadding = innerPadding) {
@@ -517,7 +519,8 @@ fun LazyListMultiSelection(
517519
) {
518520
var selectedItems by rememberSaveable { mutableStateOf(setOf<Int>()) }
519521

520-
LazyColumn(contentPadding = contentPadding) {
522+
LazyColumn(modifier = modifier,
523+
contentPadding = contentPadding) {
521524
itemsIndexed(listItems) { _, index ->
522525
val selected = selectedItems.contains(index)
523526
ListItemSelectable(

compose/snippets/src/main/java/com/example/compose/snippets/components/DatePickers.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ import androidx.compose.ui.input.pointer.pointerInput
5757
import androidx.compose.ui.tooling.preview.Preview
5858
import androidx.compose.ui.unit.dp
5959
import androidx.compose.ui.window.Popup
60-
import com.example.compose.snippets.touchinput.userinteractions.MyAppTheme
60+
import com.example.compose.snippets.ui.theme.SnippetsTheme
6161
import java.text.SimpleDateFormat
6262
import java.util.Date
6363
import java.util.Locale
6464

6565
@Preview
6666
@Composable
6767
private fun DatePickerPreview() {
68-
MyAppTheme {
68+
SnippetsTheme {
6969
DatePickerExamples()
7070
}
7171
}

compose/snippets/src/main/java/com/example/compose/snippets/components/PullToRefreshBox.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults
3636
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator
3737
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.PositionalThreshold
3838
import androidx.compose.material3.pulltorefresh.PullToRefreshState
39-
import androidx.compose.material3.pulltorefresh.pullToRefreshIndicator
39+
import androidx.compose.material3.pulltorefresh.pullToRefresh
4040
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
4141
import androidx.compose.runtime.Composable
4242
import androidx.compose.runtime.getValue
@@ -187,11 +187,13 @@ fun MyCustomIndicator(
187187
modifier: Modifier = Modifier,
188188
) {
189189
Box(
190-
modifier = modifier.pullToRefreshIndicator(
190+
modifier = modifier.pullToRefresh(
191191
state = state,
192192
isRefreshing = isRefreshing,
193-
containerColor = PullToRefreshDefaults.containerColor,
194-
threshold = PositionalThreshold
193+
threshold = PositionalThreshold,
194+
onRefresh = {
195+
196+
}
195197
),
196198
contentAlignment = Alignment.Center
197199
) {

compose/snippets/src/main/java/com/example/compose/snippets/components/Tooltips.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ fun AdvancedRichTooltipExample(
166166
}
167167
}
168168
},
169-
caretSize = DpSize(32.dp, 16.dp)
170169
) {
171170
Text(richTooltipText)
172171
}

compose/snippets/src/main/java/com/example/compose/snippets/designsystems/Mdc3ThemeSnippets.kt

Lines changed: 0 additions & 38 deletions
This file was deleted.

compose/snippets/src/main/java/com/example/compose/snippets/interop/MigrationCommonScenariosSnippets.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
5858
import androidx.compose.ui.platform.ComposeView
5959
import androidx.compose.ui.unit.dp
6060
import androidx.fragment.app.Fragment
61-
import androidx.hilt.navigation.compose.hiltViewModel
61+
import androidx.hilt.lifecycle.viewmodel.compose.hiltViewModel
6262
import androidx.lifecycle.ViewModel
6363
import androidx.navigation.NavHostController
6464
import androidx.navigation.compose.NavHost

compose/snippets/src/main/java/com/example/compose/snippets/layouts/FlowLayoutSnippets.kt

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ import androidx.compose.foundation.background
2121
import androidx.compose.foundation.border
2222
import androidx.compose.foundation.layout.Arrangement
2323
import androidx.compose.foundation.layout.Box
24-
import androidx.compose.foundation.layout.ContextualFlowRow
25-
import androidx.compose.foundation.layout.ContextualFlowRowOverflow
26-
import androidx.compose.foundation.layout.ContextualFlowRowOverflowScope
2724
import androidx.compose.foundation.layout.ExperimentalLayoutApi
2825
import androidx.compose.foundation.layout.FlowColumn
2926
import androidx.compose.foundation.layout.FlowRow
@@ -33,22 +30,13 @@ import androidx.compose.foundation.layout.fillMaxSize
3330
import androidx.compose.foundation.layout.fillMaxWidth
3431
import androidx.compose.foundation.layout.height
3532
import androidx.compose.foundation.layout.padding
36-
import androidx.compose.foundation.layout.safeDrawingPadding
3733
import androidx.compose.foundation.layout.size
3834
import androidx.compose.foundation.layout.width
39-
import androidx.compose.foundation.layout.wrapContentHeight
40-
import androidx.compose.foundation.rememberScrollState
4135
import androidx.compose.foundation.shape.RoundedCornerShape
42-
import androidx.compose.foundation.verticalScroll
4336
import androidx.compose.material.ExperimentalMaterialApi
4437
import androidx.compose.material3.FilterChip
4538
import androidx.compose.material3.Text
4639
import androidx.compose.runtime.Composable
47-
import androidx.compose.runtime.getValue
48-
import androidx.compose.runtime.mutableIntStateOf
49-
import androidx.compose.runtime.remember
50-
import androidx.compose.runtime.setValue
51-
import androidx.compose.ui.Alignment
5240
import androidx.compose.ui.Modifier
5341
import androidx.compose.ui.draw.clip
5442
import androidx.compose.ui.graphics.Color
@@ -465,48 +453,6 @@ fun FlowLayout_FractionalSizing() {
465453
// [END android_compose_flow_layout_fractional_sizing]
466454
}
467455

468-
@OptIn(ExperimentalLayoutApi::class)
469-
@Preview
470-
@Composable
471-
fun ContextualFlowLayoutExample() {
472-
// [START android_compose_layouts_contextual_flow]
473-
val totalCount = 40
474-
var maxLines by remember {
475-
mutableIntStateOf(2)
476-
}
477-
478-
val moreOrCollapseIndicator = @Composable { scope: ContextualFlowRowOverflowScope ->
479-
val remainingItems = totalCount - scope.shownItemCount
480-
ChipItem(if (remainingItems == 0) "Less" else "+$remainingItems", onClick = {
481-
if (remainingItems == 0) {
482-
maxLines = 2
483-
} else {
484-
maxLines += 5
485-
}
486-
})
487-
}
488-
ContextualFlowRow(
489-
modifier = Modifier
490-
.safeDrawingPadding()
491-
.fillMaxWidth(1f)
492-
.padding(16.dp)
493-
.wrapContentHeight(align = Alignment.Top)
494-
.verticalScroll(rememberScrollState()),
495-
verticalArrangement = Arrangement.spacedBy(4.dp),
496-
horizontalArrangement = Arrangement.spacedBy(8.dp),
497-
maxLines = maxLines,
498-
overflow = ContextualFlowRowOverflow.expandOrCollapseIndicator(
499-
minRowsToShowCollapse = 4,
500-
expandIndicator = moreOrCollapseIndicator,
501-
collapseIndicator = moreOrCollapseIndicator
502-
),
503-
itemCount = totalCount
504-
) { index ->
505-
ChipItem("Item $index")
506-
}
507-
// [END android_compose_layouts_contextual_flow]
508-
}
509-
510456
@OptIn(ExperimentalLayoutApi::class)
511457
@Preview
512458
@Composable

compose/snippets/src/main/java/com/example/compose/snippets/layouts/PagerSnippets.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ import androidx.compose.foundation.shape.RoundedCornerShape
5050
import androidx.compose.material3.Button
5151
import androidx.compose.material3.Card
5252
import androidx.compose.material3.MaterialTheme
53+
import androidx.compose.material3.PrimaryTabRow
5354
import androidx.compose.material3.Tab
54-
import androidx.compose.material3.TabRow
5555
import androidx.compose.material3.Text
5656
import androidx.compose.runtime.Composable
5757
import androidx.compose.runtime.LaunchedEffect
@@ -239,7 +239,7 @@ fun PagerWithTabsExample() {
239239
pages.size
240240
})
241241

242-
TabRow(
242+
PrimaryTabRow(
243243
// Our selected tab is our current page
244244
selectedTabIndex = pagerState.currentPage,
245245
) {

compose/snippets/src/main/java/com/example/compose/snippets/resources/ResourcesSnippets.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import androidx.compose.foundation.layout.padding
2626
import androidx.compose.material.icons.Icons
2727
import androidx.compose.material.icons.rounded.Menu
2828
import androidx.compose.material3.Divider
29+
import androidx.compose.material3.HorizontalDivider
2930
import androidx.compose.material3.Icon
3031
import androidx.compose.material3.MaterialTheme
3132
import androidx.compose.material3.Text
@@ -109,7 +110,7 @@ fun Colors() {
109110
// <color name="purple_200">#FFBB86FC</color>
110111

111112
// In your Compose code
112-
Divider(color = colorResource(R.color.purple_200))
113+
HorizontalDivider(color = colorResource(R.color.purple_200))
113114
// [END android_compose_resources_colors]
114115
}
115116

compose/snippets/src/main/java/com/example/compose/snippets/state/StateHoistingSnippets.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
package com.example.compose.snippets.state
2020

21+
import android.R.id.message
22+
import androidx.compose.foundation.clickable
2123
import androidx.compose.foundation.lazy.LazyColumn
2224
import androidx.compose.foundation.lazy.LazyListState
2325
import androidx.compose.foundation.lazy.items
@@ -34,7 +36,13 @@ import androidx.compose.runtime.rememberCoroutineScope
3436
import androidx.compose.runtime.saveable.rememberSaveable
3537
import androidx.compose.runtime.setValue
3638
import androidx.compose.runtime.snapshotFlow
39+
import androidx.compose.ui.Modifier
3740
import androidx.compose.ui.text.AnnotatedString
41+
import androidx.compose.ui.text.LinkAnnotation
42+
import androidx.compose.ui.text.SpanStyle
43+
import androidx.compose.ui.text.TextLinkStyles
44+
import androidx.compose.ui.text.buildAnnotatedString
45+
import androidx.compose.ui.text.withLink
3846
import androidx.lifecycle.ViewModel
3947
import androidx.lifecycle.compose.collectAsStateWithLifecycle
4048
import androidx.lifecycle.viewModelScope
@@ -60,9 +68,11 @@ private object StateHoistingSnippets1 {
6068
) {
6169
var showDetails by rememberSaveable { mutableStateOf(false) } // Define the UI element expanded state
6270

63-
ClickableText(
71+
Text(
6472
text = AnnotatedString(message.content),
65-
onClick = { showDetails = !showDetails } // Apply simple UI logic
73+
modifier = Modifier.clickable {
74+
showDetails = !showDetails // Apply UI logic
75+
}
6676
)
6777

6878
if (showDetails) {

0 commit comments

Comments
 (0)