https://kotlinlang.org logo
s

Sergey Y.

09/01/2020, 8:30 PM
Is there any way to make the clickable region larger than the icon without making the icon size bigger? I want to achieve a borderless ripple effect and easier clicking. Maybe some modifier? Is there an analogy to the 
selectableItemBackgroundBorderless
 attribute? Thanks.
f

flosch

09/01/2020, 8:34 PM
I don’t know your implementation, but its probably adding a
Modifer.padding
before your
Modifier.clickable
that should do the trick
s

Sergey Y.

09/01/2020, 8:37 PM
Padding will shift the icon, it is already placed inside another container.
On legacy ui system you can do things like that.
Copy code
<ImageView
  ...
  android:background="?selectableItemBackgroundBorderless"/>
Is there an analogy to the
selectableItemBackgroundBorderless
attribute?
j

JD

09/01/2020, 8:46 PM
Does this work? Did using
Copy code
IconButton(
    onClick = {

    },modifier = Modifier.padding(16.dp)
) {
    Icon(asset = Icons.Filled.Favorite)
}
the catch here though in comparison to what you had shown was the icons were placed a lot closer but had a higher touch target for the ripple effect
s

Sergey Y.

09/01/2020, 8:48 PM
It will work, but in this case I have to put the icon on the upper level to keep the padding
But thanks )
👍 1
j

JD

09/01/2020, 9:13 PM
How about this @Sergey Y.
Copy code
Icon(
    asset = Icons.Filled.Favorite,
    modifier = Modifier.clickable(onClick = {

    }).padding(start = 32.dp, top = 0.dp, end = 0.dp, bottom = 32.dp)
)
the clickable is a square instead of a circle though
s

Sergey Y.

09/01/2020, 9:15 PM
It can be fixed by clipping
m

mbonnin

09/01/2020, 9:15 PM
selectableItemBackgroundBorderless
doesn't really increase the clickable area does it? I think it just draws in the the parent
1
j

JD

09/01/2020, 9:15 PM
you would have to get your image in if its at the edge it will clip the heart
U were right
Copy code
Icon(
    asset = Icons.Filled.Favorite,
    modifier = Modifier.clip(CircleShape).clickable(onClick = {

    }).padding(start = 24.dp, top = 8.dp, end = 8.dp, bottom = 24.dp)
)
s

Sergey Y.

09/01/2020, 9:17 PM
@mbonnin you are correct. It is only adds ripple effect
j

JD

09/01/2020, 9:18 PM
the top and end padding just to ensure its in
s

Sergey Y.

09/01/2020, 9:18 PM
@JD Thanks)
👍 1
a

Andrey Kulikov

09/01/2020, 9:40 PM
but as it was mentioned already it will not make a touch target larger
m

mbonnin

09/01/2020, 9:46 PM
@Andrey Kulikov is it like
selectableItemBackgroundBorderLess
in that the parent has to be big enough to contain the ripple overflow ? I remember some bugs where the ripple was clipped because the parent wasn't big enough
Or does compose handle clipping differently?
a

Adam Powell

09/02/2020, 12:44 AM
Compose does not clip to parents by default
👍 1
🙏 1
c

Colton Idle

09/02/2020, 4:18 AM
@Adam Powell this is inverse to the behavior in the current UI toolkit, right?
👌 3
14 Views