Skip to content
Open
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 @@ -115,7 +115,8 @@ private class RecomposeHighlighterModifier : Modifier.Node(), DrawModifierNode {
// Draw actual content.
drawContent()

// Below is to draw the highlight, if necessary. A lot of the logic is copied from Modifier.border
// Below is to draw the highlight, if necessary.
// A lot of the logic is copied from Modifier.border

val hasValidBorderParams = size.minDimension > 0f
if (!hasValidBorderParams || totalCompositions <= 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
Expand Down Expand Up @@ -79,58 +81,70 @@ class SnippetsActivity : ComponentActivity() {
composable("LandingScreen") {
LandingScreen { navController.navigate(it.route) }
}
Destination.entries.forEach { destination ->
composable(destination.route) {
when (destination) {
Destination.BrushExamples -> BrushExamplesScreen()
Destination.ImageExamples -> ImageExamplesScreen()
Destination.AnimationQuickGuideExamples -> AnimationExamplesScreen()
Destination.ScreenshotExample -> BitmapFromComposableFullSnippet()
Destination.ComponentsExamples -> ComponentsScreen {
navController.navigate(
it.route
)
}
Destination.ShapesExamples -> ApplyPolygonAsClipImage()
Destination.SharedElementExamples -> PlaceholderSizeAnimated_Demo()
Destination.PagerExamples -> PagerExamples()
}
}
}
TopComponentsDestination.entries.forEach { destination ->
composable(destination.route) {
when (destination) {
TopComponentsDestination.CardExamples -> CardExamples()
TopComponentsDestination.SwitchExamples -> SwitchExamples()
TopComponentsDestination.SliderExamples -> SliderExamples()
TopComponentsDestination.DialogExamples -> DialogExamples()
TopComponentsDestination.ChipExamples -> ChipExamples()
TopComponentsDestination.FloatingActionButtonExamples -> FloatingActionButtonExamples()
TopComponentsDestination.ButtonExamples -> ButtonExamples()
TopComponentsDestination.ProgressIndicatorExamples -> ProgressIndicatorExamples()
TopComponentsDestination.ScaffoldExample -> ScaffoldExample()
TopComponentsDestination.AppBarExamples -> AppBarExamples {
navController.popBackStack()
}
TopComponentsDestination.CheckboxExamples -> CheckboxExamples()
TopComponentsDestination.DividerExamples -> DividerExamples()
TopComponentsDestination.BadgeExamples -> BadgeExamples()
TopComponentsDestination.PartialBottomSheet -> PartialBottomSheet()
TopComponentsDestination.TimePickerExamples -> TimePickerExamples()
TopComponentsDestination.DatePickerExamples -> DatePickerExamples()
TopComponentsDestination.CarouselExamples -> CarouselExamples()
TopComponentsDestination.MenusExample -> MenusExamples()
TopComponentsDestination.TooltipExamples -> TooltipExamples()
TopComponentsDestination.NavigationDrawerExamples -> NavigationDrawerExamples()
TopComponentsDestination.SegmentedButtonExamples -> SegmentedButtonExamples()
TopComponentsDestination.SwipeToDismissBoxExamples -> SwipeToDismissBoxExamples()
TopComponentsDestination.SearchBarExamples -> SearchBarExamples()
}
}
}
destinations(navController)
topComponentsDestinations(navController)
}
}
}
}
}
}

private fun NavGraphBuilder.destinations(navController: NavHostController) {
Destination.entries.forEach { destination ->
composable(destination.route) {
when (destination) {
Destination.BrushExamples -> BrushExamplesScreen()
Destination.ImageExamples -> ImageExamplesScreen()
Destination.AnimationQuickGuideExamples -> AnimationExamplesScreen()
Destination.ScreenshotExample -> BitmapFromComposableFullSnippet()
Destination.ComponentsExamples -> ComponentsScreen {
navController.navigate(
it.route
)
}

Destination.ShapesExamples -> ApplyPolygonAsClipImage()
Destination.SharedElementExamples -> PlaceholderSizeAnimated_Demo()
Destination.PagerExamples -> PagerExamples()
}
}
}
}

private fun NavGraphBuilder.topComponentsDestinations(navController: NavHostController) {
TopComponentsDestination.entries.forEach { destination ->
composable(destination.route) {
when (destination) {
TopComponentsDestination.CardExamples -> CardExamples()
TopComponentsDestination.SwitchExamples -> SwitchExamples()
TopComponentsDestination.SliderExamples -> SliderExamples()
TopComponentsDestination.DialogExamples -> DialogExamples()
TopComponentsDestination.ChipExamples -> ChipExamples()
TopComponentsDestination.FloatingActionButtonExamples ->
FloatingActionButtonExamples()

TopComponentsDestination.ButtonExamples -> ButtonExamples()
TopComponentsDestination.ProgressIndicatorExamples -> ProgressIndicatorExamples()
TopComponentsDestination.ScaffoldExample -> ScaffoldExample()
TopComponentsDestination.AppBarExamples -> AppBarExamples {
navController.popBackStack()
}

TopComponentsDestination.CheckboxExamples -> CheckboxExamples()
TopComponentsDestination.DividerExamples -> DividerExamples()
TopComponentsDestination.BadgeExamples -> BadgeExamples()
TopComponentsDestination.PartialBottomSheet -> PartialBottomSheet()
TopComponentsDestination.TimePickerExamples -> TimePickerExamples()
TopComponentsDestination.DatePickerExamples -> DatePickerExamples()
TopComponentsDestination.CarouselExamples -> CarouselExamples()
TopComponentsDestination.MenusExample -> MenusExamples()
TopComponentsDestination.TooltipExamples -> TooltipExamples()
TopComponentsDestination.NavigationDrawerExamples -> NavigationDrawerExamples()
TopComponentsDestination.SegmentedButtonExamples -> SegmentedButtonExamples()
TopComponentsDestination.SwipeToDismissBoxExamples -> SwipeToDismissBoxExamples()
TopComponentsDestination.SearchBarExamples -> SearchBarExamples()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,15 @@ fun SampleListDetailPaneScaffoldWithPredictiveBackFull() {
)
}

fun customPaneScaffoldDirective(currentWindowAdaptiveInfo: WindowAdaptiveInfo): PaneScaffoldDirective {
fun customPaneScaffoldDirective(
currentWindowAdaptiveInfo: WindowAdaptiveInfo,
): PaneScaffoldDirective {
val windowSizeClass = currentWindowAdaptiveInfo.windowSizeClass
val horizontalPartitions = when {
currentWindowAdaptiveInfo.windowSizeClass.isWidthAtLeastBreakpoint(
windowSizeClass.isWidthAtLeastBreakpoint(
WIDTH_DP_EXPANDED_LOWER_BOUND
) -> 3
currentWindowAdaptiveInfo.windowSizeClass.isWidthAtLeastBreakpoint(
windowSizeClass.isWidthAtLeastBreakpoint(
WIDTH_DP_MEDIUM_LOWER_BOUND
) -> 2
else -> 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,18 @@ fun SampleNavigableSupportingPaneScaffoldFull() {
.safeContentPadding()
.background(Color.Red)
) {
if (scaffoldNavigator.scaffoldValue[SupportingPaneScaffoldRole.Supporting] == PaneAdaptedValue.Hidden) {
val shouldShowSupportingPane =
scaffoldNavigator.scaffoldValue[SupportingPaneScaffoldRole.Supporting] ==
PaneAdaptedValue.Hidden
if (shouldShowSupportingPane) {
Button(
modifier = Modifier
.wrapContentSize(),
onClick = {
scope.launch {
scaffoldNavigator.navigateTo(SupportingPaneScaffoldRole.Supporting)
scaffoldNavigator.navigateTo(
pane = SupportingPaneScaffoldRole.Supporting,
)
}
}
) {
Expand Down Expand Up @@ -144,7 +149,8 @@ fun SampleNavigableSupportingPaneScaffoldSimplified() {
navigator = scaffoldNavigator,
mainPane = {
MainPane(
shouldShowSupportingPaneButton = scaffoldNavigator.scaffoldValue.secondary == PaneAdaptedValue.Hidden,
shouldShowSupportingPaneButton =
scaffoldNavigator.scaffoldValue.secondary == PaneAdaptedValue.Hidden,
onNavigateToSupportingPane = {
scope.launch {
scaffoldNavigator.navigateTo(ThreePaneScaffoldRole.Secondary)
Expand All @@ -157,6 +163,7 @@ fun SampleNavigableSupportingPaneScaffoldSimplified() {
// [END android_compose_adaptivelayouts_sample_supporting_pane_scaffold_simplified]
}

/* ktlint-disable standard:max-line-length */
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun SampleSupportingPaneScaffoldSimplifiedWithPredictiveBackHandler() {
Expand All @@ -173,8 +180,10 @@ fun SampleSupportingPaneScaffoldSimplifiedWithPredictiveBackHandler() {
directive = scaffoldNavigator.scaffoldDirective,
scaffoldState = scaffoldNavigator.scaffoldState,
mainPane = {
val shouldShowSupportingPaneButton =
scaffoldNavigator.scaffoldValue.secondary == PaneAdaptedValue.Hidden
MainPane(
shouldShowSupportingPaneButton = scaffoldNavigator.scaffoldValue.secondary == PaneAdaptedValue.Hidden,
shouldShowSupportingPaneButton = shouldShowSupportingPaneButton,
onNavigateToSupportingPane = {
scope.launch {
scaffoldNavigator.navigateTo(ThreePaneScaffoldRole.Secondary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ fun AnimatedVisibilityCookbook() {
var visible by remember {
mutableStateOf(true)
}
// Animated visibility will eventually remove the item from the composition once the animation has finished.
// Animated visibility will eventually remove the item from the composition once the
// animation has finished.
AnimatedVisibility(visible) {
// your composable here
// [START_EXCLUDE]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,10 @@ private fun ContentIcon() {
// [START android_compose_animations_char_by_char]
@Composable
private fun AnimatedText() {
val text = "This text animates as though it is being typed \uD83E\uDDDE\u200D♀\uFE0F \uD83D\uDD10 \uD83D\uDC69\u200D❤\uFE0F\u200D\uD83D\uDC68 \uD83D\uDC74\uD83C\uDFFD"
val text = "This text animates as though it is being typed" +
" \uD83E\uDDDE\u200D♀\uFE0F \uD83D\uDD10" +
" \uD83D\uDC69\u200D❤\uFE0F\u200D\uD83D\uDC68" +
" \uD83D\uDC74\uD83C\uDFFD"

// Use BreakIterator as it correctly iterates over characters regardless of how they are
// stored, for example, some emojis are made up of multiple characters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
* limitations under the License.
*/

@file:OptIn(ExperimentalSharedTransitionApi::class, ExperimentalSharedTransitionApi::class)
@file:OptIn(
ExperimentalSharedTransitionApi::class,
ExperimentalSharedTransitionApi::class,
)

package com.example.compose.snippets.animations.sharedelement

Expand Down Expand Up @@ -87,26 +90,30 @@ private fun AnimatedVisibilitySharedElementShortenedExample() {
.fillMaxSize()
.background(Color.LightGray.copy(alpha = 0.5f))
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(8.dp)
verticalArrangement = Arrangement.spacedBy(8.dp),
// [END_EXCLUDE]
) {
items(listSnacks) { snack ->
AnimatedVisibility(
visible = snack != selectedSnack,
enter = fadeIn() + scaleIn(),
exit = fadeOut() + scaleOut(),
modifier = Modifier.animateItem()
modifier = Modifier.animateItem(),
) {
Box(
modifier = Modifier
.sharedBounds(
sharedContentState = rememberSharedContentState(key = "${snack.name}-bounds"),
sharedContentState = rememberSharedContentState(
key = "${snack.name}-bounds"
),
// Using the scope provided by AnimatedVisibility
animatedVisibilityScope = this,
clipInOverlayDuringTransition = OverlayClip(shapeForSharedElement)
clipInOverlayDuringTransition = OverlayClip(
clipShape = shapeForSharedElement,
)
)
.background(Color.White, shapeForSharedElement)
.clip(shapeForSharedElement)
.background(Color.White, shape = shapeForSharedElement)
.clip(shape = shapeForSharedElement),
) {
SnackContents(
snack = snack,
Expand All @@ -116,7 +123,7 @@ private fun AnimatedVisibilitySharedElementShortenedExample() {
),
onClick = {
selectedSnack = snack
}
},
)
}
}
Expand All @@ -127,7 +134,7 @@ private fun AnimatedVisibilitySharedElementShortenedExample() {
snack = selectedSnack,
onConfirmClick = {
selectedSnack = null
}
},
)
}
// [END android_compose_shared_elements_animated_visibility]
Expand All @@ -137,19 +144,19 @@ private fun AnimatedVisibilitySharedElementShortenedExample() {
fun SharedTransitionScope.SnackEditDetails(
snack: Snack?,
modifier: Modifier = Modifier,
onConfirmClick: () -> Unit
onConfirmClick: () -> Unit,
) {
AnimatedContent(
modifier = modifier,
targetState = snack,
transitionSpec = {
fadeIn() togetherWith fadeOut()
},
label = "SnackEditDetails"
label = "SnackEditDetails",
) { targetSnack ->
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.Center
contentAlignment = Alignment.Center,
) {
if (targetSnack != null) {
Box(
Expand All @@ -158,18 +165,21 @@ fun SharedTransitionScope.SnackEditDetails(
.clickable {
onConfirmClick()
}
.background(Color.Black.copy(alpha = 0.5f))
.background(Color.Black.copy(alpha = 0.5f)),
)
Column(
modifier = Modifier
.padding(horizontal = 16.dp)
.sharedBounds(
sharedContentState = rememberSharedContentState(key = "${targetSnack.name}-bounds"),
sharedContentState = rememberSharedContentState(
key = "${targetSnack.name}-bounds",
),
animatedVisibilityScope = this@AnimatedContent,
clipInOverlayDuringTransition = OverlayClip(shapeForSharedElement)
clipInOverlayDuringTransition =
OverlayClip(shapeForSharedElement),
)
.background(Color.White, shapeForSharedElement)
.clip(shapeForSharedElement)
.clip(shapeForSharedElement),
) {

SnackContents(
Expand All @@ -186,7 +196,7 @@ fun SharedTransitionScope.SnackEditDetails(
Modifier
.fillMaxWidth()
.padding(bottom = 8.dp, end = 8.dp),
horizontalArrangement = Arrangement.End
horizontalArrangement = Arrangement.End,
) {
TextButton(onClick = { onConfirmClick() }) {
Text(text = "Save changes")
Expand All @@ -202,7 +212,7 @@ fun SharedTransitionScope.SnackEditDetails(
fun SnackContents(
snack: Snack,
modifier: Modifier = Modifier,
onClick: () -> Unit
onClick: () -> Unit,
) {
Column(
modifier = modifier
Expand All @@ -211,22 +221,22 @@ fun SnackContents(
indication = null
) {
onClick()
}
},
) {
Image(
painter = painterResource(id = snack.image),
modifier = Modifier
.fillMaxWidth()
.aspectRatio(20f / 9f),
contentScale = ContentScale.Crop,
contentDescription = null
contentDescription = null,
)
Text(
text = snack.name,
modifier = Modifier
.wrapContentWidth()
.padding(8.dp),
style = MaterialTheme.typography.titleSmall
style = MaterialTheme.typography.titleSmall,
)
}
}
Loading