Skip to content

Commit

Permalink
[MUON-625] Added parameter animationIndicationNode to enable customis…
Browse files Browse the repository at this point in the history
…ation of clicking (#2141)

Co-authored-by: Lucia Jiang <[email protected]>
  • Loading branch information
lucia-jiang and Lucia Jiang authored Nov 12, 2024
1 parent dc6cdf2 commit b76e02e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

package net.skyscanner.backpack.compose.graphicpromotion

import androidx.compose.foundation.IndicationNodeFactory
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import net.skyscanner.backpack.compose.graphicpromotion.internal.BpkGraphicPromoImpl
import net.skyscanner.backpack.compose.graphicpromotion.internal.getInteractiveBackgroundIndicationNodeFactory
import net.skyscanner.backpack.compose.overlay.BpkOverlayType

enum class BpkGraphicPromoVariant { OnDark, OnLight, }
Expand All @@ -49,6 +51,7 @@ fun BpkGraphicPromo(
sponsorLogo: (@Composable () -> Unit)? = null,
interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
tapAction: () -> Unit = {},
animationIndicationNode: IndicationNodeFactory = getInteractiveBackgroundIndicationNodeFactory(),
) {
BpkGraphicPromoImpl(
headline = headline,
Expand All @@ -63,5 +66,6 @@ fun BpkGraphicPromo(
sponsorLogo = sponsorLogo,
interactionSource = interactionSource,
tapAction = tapAction,
animationIndicationNode = animationIndicationNode,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ internal fun BpkGraphicPromoImpl(
sponsor: BpkGraphicsPromoSponsor? = null,
sponsorLogo: (@Composable () -> Unit)? = null,
tapAction: () -> Unit = {},
animationIndicationNode: IndicationNodeFactory = InteractiveBackgroundIndicationNodeFactory,
) {
val (aspectRatio, maxHeight) = getDeviceConstrains()
val roundedCornerShape = RoundedCornerShape(BpkBorderRadius.Md)
Expand All @@ -98,6 +99,7 @@ internal fun BpkGraphicPromoImpl(
.aspectRatio(ratio = aspectRatio)
.heightIn(max = maxHeight.dp)
.clip(roundedCornerShape)
.indication(interactionSource, animationIndicationNode)
.clickable(
interactionSource = interactionSource,
indication = null,
Expand All @@ -111,8 +113,7 @@ internal fun BpkGraphicPromoImpl(
if (overlayType != null) {
BpkOverlay(
modifier = Modifier
.matchParentSize()
.indication(interactionSource, InteractiveBackgroundIndicationNodeFactory),
.matchParentSize(),
overlayType = overlayType,
foregroundContent = {
ForegroundContent(
Expand All @@ -130,8 +131,7 @@ internal fun BpkGraphicPromoImpl(
} else {
Box(
modifier = Modifier
.matchParentSize()
.indication(interactionSource, InteractiveBackgroundIndicationNodeFactory),
.matchParentSize(),
content = image,
)
ForegroundContent(
Expand Down Expand Up @@ -336,6 +336,10 @@ private object InteractiveBackgroundIndicationNodeFactory : IndicationNodeFactor
override fun equals(other: Any?) = other === this
}

fun getInteractiveBackgroundIndicationNodeFactory(): IndicationNodeFactory {
return InteractiveBackgroundIndicationNodeFactory
}

private class InteractiveBackgroundIndicationNode(private val interactionSource: InteractionSource) : Modifier.Node(),
DrawModifierNode {

Expand Down

0 comments on commit b76e02e

Please sign in to comment.