From afd601f670046df7c1f83a0297ab2ce0d121f00b Mon Sep 17 00:00:00 2001 From: jbibik Date: Tue, 24 Dec 2024 15:24:17 -0800 Subject: [PATCH] Refactor non-ripple Modifier into a separate file Modifiers.kt will be a place for other extensions on Modifier class PiperOrigin-RevId: 709416429 --- .../media3/demo/compose/MainActivity.kt | 11 ++---- .../media3/demo/compose/layout/Modifiers.kt | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 demos/compose/src/main/java/androidx/media3/demo/compose/layout/Modifiers.kt diff --git a/demos/compose/src/main/java/androidx/media3/demo/compose/MainActivity.kt b/demos/compose/src/main/java/androidx/media3/demo/compose/MainActivity.kt index 32e8d02765..7416baba2a 100644 --- a/demos/compose/src/main/java/androidx/media3/demo/compose/MainActivity.kt +++ b/demos/compose/src/main/java/androidx/media3/demo/compose/MainActivity.kt @@ -20,8 +20,6 @@ import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth @@ -39,6 +37,7 @@ import androidx.media3.common.Player import androidx.media3.demo.compose.buttons.ExtraControls import androidx.media3.demo.compose.buttons.MinimalControls import androidx.media3.demo.compose.data.videos +import androidx.media3.demo.compose.layout.noRippleClickable import androidx.media3.exoplayer.ExoPlayer import androidx.media3.ui.compose.PlayerSurface import androidx.media3.ui.compose.SURFACE_TYPE_SURFACE_VIEW @@ -71,13 +70,7 @@ private fun MediaPlayerScreen(player: Player, modifier: Modifier = Modifier) { PlayerSurface( player = player, surfaceType = SURFACE_TYPE_SURFACE_VIEW, - modifier = - modifier.clickable( - interactionSource = remember { MutableInteractionSource() }, - indication = null, // to prevent the ripple from the tap - ) { - showControls = !showControls - }, + modifier = modifier.noRippleClickable { showControls = !showControls }, ) if (showControls) { MinimalControls(player, Modifier.align(Alignment.Center)) diff --git a/demos/compose/src/main/java/androidx/media3/demo/compose/layout/Modifiers.kt b/demos/compose/src/main/java/androidx/media3/demo/compose/layout/Modifiers.kt new file mode 100644 index 0000000000..441b36b1d0 --- /dev/null +++ b/demos/compose/src/main/java/androidx/media3/demo/compose/layout/Modifiers.kt @@ -0,0 +1,35 @@ +/* + * 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 androidx.media3.demo.compose.layout + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Modifier + +@Composable +internal fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier { + return then( + clickable( + interactionSource = remember { MutableInteractionSource() }, + indication = null, // to prevent the ripple from the tap + ) { + onClick() + } + ) +}