-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ANDROID-14134 Set assets clickable #324
Conversation
@@ -110,7 +116,7 @@ sealed class ListRowIcon(val contentDescription: String?) { | |||
Image( | |||
painter = painter, | |||
contentDescription = contentDescription, | |||
modifier = Modifier | |||
modifier = modifier | |||
.size(40.dp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For accessibility reasons, we might consider expanding the clickable area of the asset to 48px. We have updated our specs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'm fine with that if the specs have also been updated. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just exposing the modifier and not making it clickable with just that. Also doing that includes breaking changes in the lib. In my opinion we should ensure what we want to make clickable or not on the designs and then use this modifier to make it clickable or not depending on those designs. I'm going to revert this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
fun setAssetOnClickListener(clickListener: OnClickListener) { | ||
assetImageLayout.setOnClickListener(clickListener) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the code added for classic views in order to be able to set the click listener.
@@ -28,31 +28,36 @@ sealed class ListRowIcon(val contentDescription: String?) { | |||
data class NormalIcon( | |||
val painter: Painter? = null, | |||
private val description: String? = null, | |||
val modifier: Modifier = Modifier, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In compose we expose the modifier which is a common used practice which we were not following until now: https://chrisbanes.me/posts/always-provide-a-modifier/
@Test | ||
fun `check ListRowView xml onClick`() { | ||
rule.scenario.onActivity { activity -> | ||
var clicks = 0 | ||
val wrapper: FrameLayout = activity.findViewById(R.id.dummy_activity_wrapper) | ||
activity.layoutInflater.inflate(R.layout.test_list_row_view, wrapper, true) | ||
|
||
with (activity.findViewById<ListRowView>(R.id.list_row_view_32)) { | ||
setOnClickListener { clicks++ } | ||
performClick() | ||
} | ||
|
||
assertEquals(1, clicks) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests that the asset is clickable on xml
@Test | ||
fun `check ListRowItem with clickable asset`() { | ||
var clicked = 0 | ||
val onAssetClick: () -> Unit = { | ||
clicked++ | ||
} | ||
`when ListRowItem with asset`( | ||
dimensions = ImageDimensions(width = 44, height = 44), | ||
onAssetClick = onAssetClick, | ||
) | ||
composeTestRule.onNode(hasTestTag(LIST_ROW_ITEM_ASSET_TAG)).performClick() | ||
|
||
assertEquals(1, clicked) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests that the asset is clickable on compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Good job!
@@ -298,10 +302,14 @@ const val IMAGE_URL = "https://www.fotoaparat.cz/imgs/a/26/2639/0n1wjdf0-cr-em13 | |||
@Composable | |||
fun Lists() { | |||
val samples = samples() | |||
val context = LocalContext.current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used only once, there is no need to declare it as a property
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -35,14 +43,30 @@ internal class ListRowItemKtTest: ScreenshotsTest() { | |||
`then screenshot is OK`() | |||
} | |||
|
|||
@Test | |||
fun `check ListRowItem with clickable asset`() { | |||
var clicked = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is acting as a boolean, not as an integer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not exactly as I want to know that it has been invoked only once. A boolean would only ensure it has been invoked but it could be multiple times. By doing it this way the condition is stronger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition is exactly the same, you are checking if it has been clicked 1 time instead of 0.
@Test | ||
fun `check ListRowView xml onClick`() { | ||
rule.scenario.onActivity { activity -> | ||
var clicks = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, it is used as a boolean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same answer here 😄
@@ -553,6 +556,31 @@ class ListsCatalogFragment : Fragment() { | |||
|
|||
class ListViewHolder(val rowView: ListRowView) : RecyclerView.ViewHolder(rowView) | |||
|
|||
class ClickableListAdapter( | |||
@ListRowView.BackgroundType private val backgroundType: Int, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parameter are not being used!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, it's not needed at least for now, removed from here the catalog. Thanks.
override fun onBindViewHolder(holder: ListViewHolder, position: Int) { | ||
with(holder.rowView) { | ||
setTitle("Clickable Asset") | ||
setAssetOnClickListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the way I have understood Figma, the list row should be clickable. cc: @AnaMontes11 is that true?
Otherwise, probably is a good idea to have all or atleast some of the list row variants with this new modification.
This is the intention of the catalog. A sample of the capabilities that each Mística's component has.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📱 New catalog for testing generated: Download |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Niiice!
🥅 What's the goal?
Until now the assets in ListRow didn't have a possible interaction different from the rest of the row but this should be allowed as it has been defined in the specs: https://www.figma.com/file/Be8QB9onmHunKCCAkIBAVr/%F0%9F%94%B8-Lists-Specs?type=design&node-id=0%3A608&mode=design&t=lG2wUE8oNXAI5z4d-1
🚧 How do we do it?
☑️ Checks
🧪 How can I test this?
In the catalog.
Classic views:
Compose: