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 basic segmented button examples (#383)
* Add basic segmented button examples

* Apply Spotless

* Add region tags

---------

Co-authored-by: jakeroseman <jakeroseman@users.noreply.github.com>
  • Loading branch information
jakeroseman and jakeroseman authored Oct 24, 2024
commit 514653c318c747c557f70e32aad2cc7051d44115
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.example.compose.snippets.components.MenusExamples
import com.example.compose.snippets.components.PartialBottomSheet
import com.example.compose.snippets.components.ProgressIndicatorExamples
import com.example.compose.snippets.components.ScaffoldExample
import com.example.compose.snippets.components.SegmentedButtonExamples
import com.example.compose.snippets.components.SliderExamples
import com.example.compose.snippets.components.SwitchExamples
import com.example.compose.snippets.components.TimePickerExamples
Expand Down Expand Up @@ -119,6 +120,7 @@ class SnippetsActivity : ComponentActivity() {
TopComponentsDestination.MenusExample -> MenusExamples()
TopComponentsDestination.TooltipExamples -> TooltipExamples()
TopComponentsDestination.NavigationDrawerExamples -> NavigationDrawerExamples()
TopComponentsDestination.SegmentedButtonExamples -> SegmentedButtonExamples()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.DirectionsWalk
import androidx.compose.material.icons.filled.DirectionsBus
import androidx.compose.material.icons.filled.DirectionsCar
import androidx.compose.material3.Icon
import androidx.compose.material3.MultiChoiceSegmentedButtonRow
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

@Composable
fun SegmentedButtonExamples() {
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally

) {
SingleChoiceSegmentedButton()
Spacer(modifier = Modifier.height(16.dp))
MultiChoiceSegmentedButton()
}
}

// [START android_compose_components_singlechoicesegmentedbutton]
@Composable
fun SingleChoiceSegmentedButton(modifier: Modifier = Modifier) {
var selectedIndex by remember { mutableIntStateOf(0) }
val options = listOf("Day", "Month", "Week")

SingleChoiceSegmentedButtonRow {
options.forEachIndexed { index, label ->
SegmentedButton(
shape = SegmentedButtonDefaults.itemShape(
index = index,
count = options.size
),
onClick = { selectedIndex = index },
selected = index == selectedIndex,
label = { Text(label) }
)
}
}
}
// [END android_compose_components_singlechoicesegmentedbutton]

@Preview
@Composable
private fun SingleChoiceSegmentedButtonPreview() {
SingleChoiceSegmentedButton()
}

// [START android_compose_components_multichoicesegmentedbutton]
@Composable
fun MultiChoiceSegmentedButton(modifier: Modifier = Modifier) {
val selectedOptions = remember {
mutableStateListOf(false, false, false)
}
val options = listOf("Walk", "Ride", "Drive")

MultiChoiceSegmentedButtonRow {
options.forEachIndexed { index, label ->
SegmentedButton(
shape = SegmentedButtonDefaults.itemShape(
index = index,
count = options.size
),
checked = selectedOptions[index],
onCheckedChange = {
selectedOptions[index] = !selectedOptions[index]
},
icon = { SegmentedButtonDefaults.Icon(selectedOptions[index]) },
label = {
when (label) {
"Walk" -> Icon(
imageVector =
Icons.AutoMirrored.Filled.DirectionsWalk,
contentDescription = "Directions Walk"
)
"Ride" -> Icon(
imageVector =
Icons.Default.DirectionsBus,
contentDescription = "Directions Bus"
)
"Drive" -> Icon(
imageVector =
Icons.Default.DirectionsCar,
contentDescription = "Directions Car"
)
}
}
)
}
}
}
// [END android_compose_components_multichoicesegmentedbutton]

@Preview
@Composable
private fun MultiChoiceSegmentedButtonPreview() {
MultiChoiceSegmentedButton()
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,6 @@ enum class TopComponentsDestination(val route: String, val title: String) {
CarouselExamples("carouselExamples", "Carousel"),
MenusExample("menusExamples", "Menus"),
TooltipExamples("tooltipExamples", "Tooltips"),
NavigationDrawerExamples("navigationDrawerExamples", "Navigation drawer")
NavigationDrawerExamples("navigationDrawerExamples", "Navigation drawer"),
SegmentedButtonExamples("segmentedButtonExamples", "Segmented button")
}