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

🤖 Sync main to latest #417

Merged
merged 31 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
31b4de2
Added two snippets for showcasing how to do Masking and Clipping in C…
riggaroo Oct 2, 2024
d1e297b
🤖 Update Dependencies (#366)
compose-devrel-github-bot Oct 3, 2024
0c9024b
Add Material Carousel (#363)
riggaroo Oct 3, 2024
68fef6e
Basic menu examples (#371)
jakeroseman Oct 11, 2024
fbfd07d
Filter chip dropdown menu (#375)
JolandaVerhoef Oct 11, 2024
f67b849
Add example of date picker textfield opening picker dialog on click (…
JolandaVerhoef Oct 11, 2024
a0b94c0
Add auto advance pager snippets (#377)
jakeroseman Oct 11, 2024
591dfa5
Tooltip component examples (#373)
jakeroseman Oct 11, 2024
4baf477
Add pull to refresh snippets (#378)
JolandaVerhoef Oct 11, 2024
5545f37
Remove LaunchedEffect workaround (#379)
jakeroseman Oct 14, 2024
90b8500
Navigation drawer examples (#380)
jakeroseman Oct 14, 2024
e9116f5
Snippets for keyboard input (#368)
chikoski Oct 16, 2024
2af26d9
Snippet for animated sorted list with add/remove buttons. (#381)
jakeroseman Oct 16, 2024
514653c
Add basic segmented button examples (#383)
jakeroseman Oct 24, 2024
5ccd4a8
Adding views snippets module with Generated Preview samples (#384)
secondsun Oct 28, 2024
195bd61
Adding top bar multi selection examples (#387)
jakeroseman Oct 29, 2024
d081491
Include AppScaffold in navigation Snippet (#385)
kul3r4 Oct 31, 2024
81c1a2a
Animate image size on scroll (#390)
jakeroseman Nov 5, 2024
1da22a0
Add basic HTML text styling example (#389)
jakeroseman Nov 5, 2024
f595a0d
🤖 Update Dependencies (#391)
compose-devrel-github-bot Nov 6, 2024
f4e4987
add in predictive back snippets for NavHost and predictive back handl…
trambui09 Nov 21, 2024
515b08e
Add region tags to auto advance pager examples (#398)
jakeroseman Nov 27, 2024
fb654a9
Init Wear Tiles snippets (#400)
ithinkihaveacat Nov 27, 2024
c699e70
Create misc module, add broadcast receiver snippets (#397)
JolandaVerhoef Nov 28, 2024
6f61cb5
Add live search with FilterTextView example (#402)
jakeroseman Dec 4, 2024
0d07b08
Add single option radio button example (#401)
jakeroseman Dec 4, 2024
c79a414
update to use type safe routes (#399)
trambui09 Dec 6, 2024
273d399
Migrated relevant MotionCompose snippets into snippets (#411)
riggaroo Dec 9, 2024
82573fd
Moving location permissions snippets to repo (#413)
jakeroseman Dec 9, 2024
6dc5a0a
Use VerticalDivider in IntrinsicSnippets (#369)
DavidMendozaMartinez Dec 10, 2024
eaeca60
Merge remote-tracking branch 'origin/main' into latest
compose-devrel-github-bot Dec 10, 2024
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
Prev Previous commit
Next Next commit
Add Material Carousel (#363)
* Add Carousel

* Apply Spotless

* add to components

* Apply Spotless

* Clean up landing screens, using Scaffold and list items.

* Apply Spotless

* Review comments

---------

Co-authored-by: riggaroo <riggaroo@users.noreply.github.com>
  • Loading branch information
riggaroo and riggaroo authored Oct 3, 2024
commit 0c9024be7705d86edca458dc84f3e47e59996a4a
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.example.compose.snippets.components.AppBarExamples
import com.example.compose.snippets.components.BadgeExamples
import com.example.compose.snippets.components.ButtonExamples
import com.example.compose.snippets.components.CardExamples
import com.example.compose.snippets.components.CarouselExamples
import com.example.compose.snippets.components.CheckboxExamples
import com.example.compose.snippets.components.ChipExamples
import com.example.compose.snippets.components.ComponentsScreen
Expand Down Expand Up @@ -109,6 +110,7 @@ class SnippetsActivity : ComponentActivity() {
TopComponentsDestination.PartialBottomSheet -> PartialBottomSheet()
TopComponentsDestination.TimePickerExamples -> TimePickerExamples()
TopComponentsDestination.DatePickerExamples -> DatePickerExamples()
TopComponentsDestination.CarouselExamples -> CarouselExamples()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Copyright 2024 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.components

import androidx.annotation.DrawableRes
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.carousel.HorizontalMultiBrowseCarousel
import androidx.compose.material3.carousel.HorizontalUncontainedCarousel
import androidx.compose.material3.carousel.rememberCarouselState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.compose.snippets.R

@OptIn(ExperimentalMaterial3Api::class)
@Preview
// [START android_compose_carousel_multi_browse_basic]
@Composable
fun CarouselExample_MultiBrowse() {
data class CarouselItem(
val id: Int,
@DrawableRes val imageResId: Int,
val contentDescription: String
)

val items = remember {
listOf(
CarouselItem(0, R.drawable.cupcake, "cupcake"),
CarouselItem(1, R.drawable.donut, "donut"),
CarouselItem(2, R.drawable.eclair, "eclair"),
CarouselItem(3, R.drawable.froyo, "froyo"),
CarouselItem(4, R.drawable.gingerbread, "gingerbread"),
)
}

HorizontalMultiBrowseCarousel(
state = rememberCarouselState { items.count() },
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(top = 16.dp, bottom = 16.dp),
preferredItemWidth = 186.dp,
itemSpacing = 8.dp,
contentPadding = PaddingValues(horizontal = 16.dp)
) { i ->
val item = items[i]
Image(
modifier = Modifier
.height(205.dp)
.maskClip(MaterialTheme.shapes.extraLarge),
painter = painterResource(id = item.imageResId),
contentDescription = item.contentDescription,
contentScale = ContentScale.Crop
)
}
}
// [END android_compose_carousel_multi_browse_basic]

@OptIn(ExperimentalMaterial3Api::class)
@Preview
// [START android_compose_carousel_uncontained_basic]
@Composable
fun CarouselExample() {
data class CarouselItem(
val id: Int,
@DrawableRes val imageResId: Int,
val contentDescription: String
)

val carouselItems = remember {
listOf(
CarouselItem(0, R.drawable.cupcake, "cupcake"),
CarouselItem(1, R.drawable.donut, "donut"),
CarouselItem(2, R.drawable.eclair, "eclair"),
CarouselItem(3, R.drawable.froyo, "froyo"),
CarouselItem(4, R.drawable.gingerbread, "gingerbread"),
)
}

HorizontalUncontainedCarousel(
state = rememberCarouselState { carouselItems.count() },
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(top = 16.dp, bottom = 16.dp),
itemWidth = 186.dp,
itemSpacing = 8.dp,
contentPadding = PaddingValues(horizontal = 16.dp)
) { i ->
val item = carouselItems[i]
Image(
modifier = Modifier
.height(205.dp)
.maskClip(MaterialTheme.shapes.extraLarge),
painter = painterResource(id = item.imageResId),
contentDescription = item.contentDescription,
contentScale = ContentScale.Crop
)
}
}
// [END android_compose_carousel_uncontained_basic]

@Preview
@Composable
fun CarouselExamples() {
Column {
CarouselExample()
CarouselExample_MultiBrowse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,59 @@

package com.example.compose.snippets.components

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.example.compose.snippets.navigation.TopComponentsDestination

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ComponentsScreen(
navigate: (TopComponentsDestination) -> Unit
) {
LazyColumn(
modifier = Modifier
.padding(16.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
items(TopComponentsDestination.entries) { destination ->
NavigationItem(destination) {
navigate(
destination
)
Scaffold(topBar = {
TopAppBar(title = {
Text("Common Components")
})
}, content = { padding ->
LazyColumn(
modifier = Modifier
.padding(padding)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
) {
items(TopComponentsDestination.entries) { destination ->
NavigationItem(destination) {
navigate(
destination
)
}
}
}
}
})
}

@Composable
fun NavigationItem(destination: TopComponentsDestination, onClick: () -> Unit) {
Button(
onClick = { onClick() }
) {
Text(destination.title)
}
ListItem(
headlineContent = {
Text(destination.title)
},
modifier = Modifier.clickable {
onClick()
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,45 @@ package com.example.compose.snippets.landing

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ListItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.compose.snippets.navigation.Destination

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LandingScreen(
navigate: (Destination) -> Unit
) {
Column(
modifier = Modifier
.padding(16.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(24.dp),
) {
Text(
modifier = Modifier.fillMaxWidth(),
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Bold,
textAlign = TextAlign.Center,
),
text = "Android snippets",
)
Text(
text = "Use the following buttons to view a selection of the snippets used in the Android documentation."
)
NavigationItems { navigate(it) }
Scaffold(
topBar = {
TopAppBar(title = {
Text(text = "Android snippets",)
})
}
) { padding ->
NavigationItems(modifier = Modifier.padding(padding)) { navigate(it) }
}
}

@Composable
fun NavigationItems(navigate: (Destination) -> Unit) {
fun NavigationItems(
modifier: Modifier = Modifier,
navigate: (Destination) -> Unit
) {
LazyColumn(
modifier = Modifier
modifier = modifier
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(8.dp),
horizontalAlignment = Alignment.CenterHorizontally,
Expand All @@ -84,14 +73,14 @@ fun NavigationItems(navigate: (Destination) -> Unit) {

@Composable
fun NavigationItem(destination: Destination, onClick: () -> Unit) {
Box(
ListItem(
headlineContent = {
Text(destination.title)
},
modifier = Modifier
.heightIn(min = 48.dp)
.clickable {
onClick()
}
) {
Text(destination.title)
HorizontalDivider(modifier = Modifier.align(Alignment.BottomCenter))
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ enum class TopComponentsDestination(val route: String, val title: String) {
PartialBottomSheet("partialBottomSheets", "Partial Bottom Sheet"),
TimePickerExamples("timePickerExamples", "Time Pickers"),
DatePickerExamples("datePickerExamples", "Date Pickers"),
CarouselExamples("carouselExamples", "Carousel")
}