-
Notifications
You must be signed in to change notification settings - Fork 333
feat: adds region tag for CanonicalLayoutSamples #791
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright 2026 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. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.example.compose.snippets.adaptivelayouts | ||
|
|
||
| import androidx.compose.foundation.lazy.grid.GridCells | ||
| import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
| import androidx.compose.foundation.lazy.grid.items | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi | ||
| import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold | ||
| import androidx.compose.material3.adaptive.layout.SupportingPaneScaffold | ||
| import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator | ||
| import androidx.compose.material3.adaptive.navigation.rememberSupportingPaneScaffoldNavigator | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.unit.dp | ||
|
|
||
|
|
||
| // [START android_compose_canonical_layouts_sample_my_feed] | ||
| @Composable | ||
| fun MyFeed(names: List<String>) { | ||
| LazyVerticalGrid( | ||
| // GridCells.Adaptive automatically adapts column count based on available width | ||
| columns = GridCells.Adaptive(minSize = 180.dp), | ||
| ) { | ||
| items(names) { name -> | ||
| Text(name) | ||
| } | ||
| } | ||
| } | ||
| // [END android_compose_canonical_layouts_sample_my_feed] | ||
|
|
||
|
|
||
| @OptIn(ExperimentalMaterial3AdaptiveApi::class) | ||
| // [START android_compose_canonical_layouts_list_detail_pane_scaffold] | ||
| @Composable | ||
| fun MyListDetailPaneScaffold() { | ||
| val navigator = rememberListDetailPaneScaffoldNavigator() | ||
| ListDetailPaneScaffold( | ||
| directive = navigator.scaffoldDirective, | ||
| value = navigator.scaffoldValue, | ||
| listPane = { | ||
| // Listing Pane | ||
| }, | ||
| detailPane = { | ||
| // Details Pane | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: this sample doesn't include a navigate to handler nor a close/dismiss button w/ event handler. |
||
| } | ||
| ) | ||
| } | ||
| // [END android_compose_canonical_layouts_list_detail_pane_scaffold] | ||
|
|
||
| @OptIn(ExperimentalMaterial3AdaptiveApi::class) | ||
| // [START android_compose_canonical_layouts_supporting_pane_scaffold] | ||
| @Composable | ||
| fun MySupportingPaneScaffold() { | ||
| // Creates and remembers a navigator to control pane visibility and navigation | ||
| val navigator = rememberSupportingPaneScaffoldNavigator() | ||
| SupportingPaneScaffold( | ||
| // Directive and value help control pane visibility based on screen size and state | ||
| directive = navigator.scaffoldDirective, | ||
| value = navigator.scaffoldValue, | ||
| mainPane = { | ||
| // Main Pane for the primary content | ||
| }, | ||
| supportingPane = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar to previous: show how to navigate to this pane and how to dismiss it. Question: why use |
||
| //Supporting Pane for supplementary content | ||
| } | ||
| ) | ||
| } | ||
| // [END android_compose_canonical_layouts_supporting_pane_scaffold] | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: move the start of the region tag up one line. The
@OptInannotation is required to use the adaptive APIs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here and below.