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

Update material3-adaptive to 1.0.0-alpha03 #178

Closed
wants to merge 1 commit into from
Closed
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 @@ -27,13 +27,15 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Card
import androidx.compose.material3.ListItem
import androidx.compose.material3.Text
import androidx.compose.material3.adaptive.AnimatedPane
import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.ListDetailPaneScaffold
import androidx.compose.material3.adaptive.ListDetailPaneScaffoldRole
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldState
import androidx.compose.material3.adaptive.rememberListDetailPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
Expand All @@ -46,16 +48,18 @@ import androidx.compose.ui.unit.sp
@Composable
fun SampleListDetailPaneScaffoldParts() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02]
val state = rememberListDetailPaneScaffoldState()
val navigator = rememberListDetailPaneScaffoldNavigator()
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02]

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part01]
var selectedItem: MyItem? by rememberSaveable { mutableStateOf(null) }
var selectedItem: MyItem? by rememberSaveable(stateSaver = MyItem.Saver) {
mutableStateOf(null)
}
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part01]

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part03]
ListDetailPaneScaffold(
scaffoldState = state,
scaffoldState = navigator.scaffoldState,
// [START_EXCLUDE]
listPane = {},
detailPane = {},
Expand All @@ -65,16 +69,18 @@ fun SampleListDetailPaneScaffoldParts() {

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part04]
ListDetailPaneScaffold(
scaffoldState = state,
scaffoldState = navigator.scaffoldState,
listPane = {
MyList(
onItemClick = { id ->
// Set current item
selectedItem = id
// Switch focus to detail pane
state.navigateTo(ListDetailPaneScaffoldRole.Detail)
}
)
AnimatedPane(Modifier) {
MyList(
onItemClick = { id ->
// Set current item
selectedItem = id
// Switch focus to detail pane
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
}
)
}
},
// [START_EXCLUDE]
detailPane = {},
Expand All @@ -84,14 +90,16 @@ fun SampleListDetailPaneScaffoldParts() {

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part05]
ListDetailPaneScaffold(
scaffoldState = state,
scaffoldState = navigator.scaffoldState,
listPane =
// [START_EXCLUDE]
{},
// [END_EXCLUDE]
detailPane = {
selectedItem?.let { item ->
MyDetails(item)
AnimatedPane(Modifier) {
selectedItem?.let { item ->
MyDetails(item)
}
}
},
)
Expand All @@ -104,27 +112,33 @@ fun SampleListDetailPaneScaffoldParts() {
fun SampleListDetailPaneScaffoldFull() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
// Create the ListDetailPaneScaffoldState
val state = rememberListDetailPaneScaffoldState()
val navigator = rememberListDetailPaneScaffoldNavigator()

// Currently selected item
var selectedItem: MyItem? by rememberSaveable { mutableStateOf(null) }
var selectedItem: MyItem? by rememberSaveable(stateSaver = MyItem.Saver) {
mutableStateOf(null)
}

ListDetailPaneScaffold(
scaffoldState = state,
scaffoldState = navigator.scaffoldState,
listPane = {
MyList(
onItemClick = { id ->
// Set current item
selectedItem = id
// Display the detail pane
state.navigateTo(ListDetailPaneScaffoldRole.Detail)
},
)
AnimatedPane(Modifier) {
MyList(
onItemClick = { id ->
// Set current item
selectedItem = id
// Display the detail pane
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail)
},
)
}
},
detailPane = {
// Show the detail pane content if selected item is available
selectedItem?.let { item ->
MyDetails(item)
AnimatedPane(Modifier) {
// Show the detail pane content if selected item is available
selectedItem?.let { item ->
MyDetails(item)
}
}
},
)
Expand Down Expand Up @@ -178,7 +192,14 @@ fun MyDetails(item: MyItem) {
}
}

class MyItem(val id: Int)
class MyItem(val id: Int) {
companion object {
val Saver: Saver<MyItem?, Int> = Saver(
{ it?.id },
::MyItem,
)
}
}

val shortStrings = listOf(
"Android",
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ kotlin = "1.9.20"
ksp = "1.8.0-1.0.9"
maps-compose = "3.1.1"
material = "1.11.0-beta01"
material3-adaptive = "1.0.0-alpha01"
material3-adaptive = "1.0.0-alpha03"
material3-adaptive-navigation-suite = "1.0.0-alpha02"
# @keep
minSdk = "21"
recyclerview = "1.3.2"
Expand All @@ -56,7 +57,7 @@ androidx-compose-material = { module = "androidx.compose.material:material" }
androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
androidx-compose-material3-adaptive = { module = "androidx.compose.material3:material3-adaptive", version.ref = "material3-adaptive" }
androidx-compose-material3-adaptive-navigation-suite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite", version.ref = "material3-adaptive" }
androidx-compose-material3-adaptive-navigation-suite = { module = "androidx.compose.material3:material3-adaptive-navigation-suite", version.ref = "material3-adaptive-navigation-suite" }
androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" }
Expand Down
Loading