-
Notifications
You must be signed in to change notification settings - Fork 1
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
b2ae744
commit 52e701a
Showing
3 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
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
43 changes: 43 additions & 0 deletions
43
taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/modifier/Klickable.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,43 @@ | ||
package xyz.ksharma.krail.taj.modifier | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.interaction.MutableInteractionSource | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.Role | ||
import xyz.ksharma.krail.taj.LocalThemeColor | ||
import xyz.ksharma.krail.taj.hexToComposeColor | ||
import xyz.ksharma.krail.taj.theme.getForegroundColor | ||
import xyz.ksharma.krail.taj.theme.krailRipple | ||
|
||
/** | ||
* Adds a click listener to the Modifier with a custom ripple effect. | ||
* This method is used when you need a custom ripple effect with a clickable element. | ||
* | ||
* @param role The role of the clickable element. | ||
* @param enabled Whether the clickable element is enabled. | ||
* @param onClick The callback to be invoked when the element is clicked. | ||
* @return The modified Modifier with the click listener and custom ripple effect. | ||
*/ | ||
@Composable | ||
fun Modifier.klickable( | ||
role: Role = Role.Button, | ||
enabled: Boolean = true, | ||
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() }, | ||
onClick: () -> Unit, | ||
): Modifier { | ||
val themeColorHex by LocalThemeColor.current | ||
val themeColor by remember { mutableStateOf(themeColorHex.hexToComposeColor()) } | ||
|
||
return this.clickable( | ||
role = role, | ||
interactionSource = interactionSource, | ||
enabled = enabled, | ||
indication = krailRipple(color = themeColor), | ||
onClick = onClick, | ||
) | ||
} |
26 changes: 26 additions & 0 deletions
26
taj/src/commonMain/kotlin/xyz/ksharma/krail/taj/theme/KrailRipple.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,26 @@ | ||
package xyz.ksharma.krail.taj.theme | ||
|
||
import androidx.compose.foundation.IndicationNodeFactory | ||
import androidx.compose.material3.ripple | ||
import androidx.compose.runtime.Stable | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.ColorProducer | ||
import androidx.compose.ui.unit.Dp | ||
|
||
@Stable | ||
fun krailRipple( | ||
bounded: Boolean = true, | ||
radius: Dp = Dp.Unspecified, | ||
color: Color = Color.Unspecified | ||
): IndicationNodeFactory { | ||
return ripple(bounded, radius, color) | ||
} | ||
|
||
@Stable | ||
fun krailRipple( | ||
color: ColorProducer, | ||
bounded: Boolean = true, | ||
radius: Dp = Dp.Unspecified | ||
): IndicationNodeFactory { | ||
return ripple(color, bounded, radius) | ||
} |