-
-
Notifications
You must be signed in to change notification settings - Fork 748
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eda3ceb
commit 57e70ce
Showing
2 changed files
with
67 additions
and
12 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/main/java/app/revanced/manager/ui/component/FloatingActionButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package app.revanced.manager.ui.component | ||
|
||
import androidx.compose.material.ripple.LocalRippleTheme | ||
import androidx.compose.material.ripple.RippleAlpha | ||
import androidx.compose.material.ripple.RippleTheme | ||
import androidx.compose.material3.ExtendedFloatingActionButton | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.vector.ImageVector | ||
|
||
@Composable | ||
fun FloatingActionButton( | ||
text: String, | ||
icon: ImageVector, | ||
onClick: () -> Unit, | ||
enabled: Boolean = true | ||
) { | ||
val tint = if (enabled) MaterialTheme.colorScheme.primary else Color.Gray | ||
CompositionLocalProvider( | ||
LocalRippleTheme provides if (enabled) { | ||
LocalRippleTheme.current | ||
} else NoRippleTheme | ||
) { | ||
ExtendedFloatingActionButton( | ||
text = { | ||
Text( | ||
text = text, | ||
color = tint | ||
) | ||
}, | ||
icon = { | ||
Icon( | ||
imageVector = icon, | ||
contentDescription = null, | ||
tint = tint | ||
) | ||
}, | ||
onClick = { | ||
if (enabled) onClick() | ||
}, | ||
containerColor = if (enabled) MaterialTheme.colorScheme.primaryContainer else Color.LightGray, | ||
) | ||
} | ||
} | ||
|
||
private object NoRippleTheme : RippleTheme { | ||
@Composable | ||
override fun defaultColor() = Color.Unspecified | ||
|
||
@Composable | ||
override fun rippleAlpha(): RippleAlpha = RippleAlpha(0.0f, 0.0f, 0.0f, 0.0f) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters