1 /*
2  * Copyright 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.camera.integration.avsync.ui.widget
18 
19 import androidx.compose.foundation.interaction.MutableInteractionSource
20 import androidx.compose.foundation.shape.CornerSize
21 import androidx.compose.material.ExperimentalMaterialApi
22 import androidx.compose.material.FloatingActionButton
23 import androidx.compose.material.FloatingActionButtonDefaults
24 import androidx.compose.material.FloatingActionButtonElevation
25 import androidx.compose.material.LocalRippleConfiguration
26 import androidx.compose.material.MaterialTheme
27 import androidx.compose.material.RippleConfiguration
28 import androidx.compose.material.contentColorFor
29 import androidx.compose.runtime.Composable
30 import androidx.compose.runtime.CompositionLocalProvider
31 import androidx.compose.ui.Modifier
32 import androidx.compose.ui.graphics.Color
33 import androidx.compose.ui.graphics.Shape
34 
35 @OptIn(ExperimentalMaterialApi::class)
36 @Composable
AdvancedFloatingActionButtonnull37 fun AdvancedFloatingActionButton(
38     modifier: Modifier = Modifier,
39     enabled: Boolean = true,
40     onClick: () -> Unit,
41     interactionSource: MutableInteractionSource? = null,
42     shape: Shape = MaterialTheme.shapes.small.copy(CornerSize(percent = 50)),
43     backgroundColor: Color = MaterialTheme.colors.secondary,
44     contentColor: Color = contentColorFor(backgroundColor),
45     elevation: FloatingActionButtonElevation = FloatingActionButtonDefaults.elevation(),
46     content: @Composable () -> Unit
47 ) {
48     CompositionLocalProvider(
49         LocalRippleConfiguration provides if (enabled) RippleConfiguration() else null
50     ) {
51         FloatingActionButton(
52             onClick =
53                 if (enabled) onClick
54                 else {
55                     {}
56                 },
57             modifier = modifier,
58             interactionSource = interactionSource,
59             shape = shape,
60             backgroundColor = if (enabled) backgroundColor else Color.Gray,
61             contentColor = contentColor,
62             elevation = elevation,
63             content = content
64         )
65     }
66 }
67