Skip to content
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

Merged
merged 6 commits into from
Dec 26, 2023

Conversation

jeprubio
Copy link
Contributor

@jeprubio jeprubio commented Dec 22, 2023

🥅 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?

  • Added setAssetOnClickListener for traditional views.
  • Made the modifier accessible for the different ListRowIcon so they can be made clickable.
  • Added tests for the traditional views and compose elements.
  • Added a row example in the catalog at the end.
  • Also added some section titles in the compose catalog as the traditional views already had.

☑️ Checks

  • I updated the documentation, including readmes and wikis. If this is a breaking change, update UPGRADING.md to inform users how to proceed. If no updates are necessary, indicate so.
  • Tested with dark mode.
  • Tested with API 23.

🧪 How can I test this?

In the catalog.
Classic views:
clickableAsset
Compose:
composeClickableAsset

  • 🖼️ Screenshots/Videos
  • Mistica App QR or download link
  • Reviewed by Mistica design team
  • ...

@jeprubio jeprubio requested review from a team, dpastor, jdelga and AnaMontes11 and removed request for a team December 22, 2023 13:22
@@ -110,7 +116,7 @@ sealed class ListRowIcon(val contentDescription: String?) {
Image(
painter = painter,
contentDescription = contentDescription,
modifier = Modifier
modifier = modifier
.size(40.dp)

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.

Copy link
Contributor Author

@jeprubio jeprubio Dec 22, 2023

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.

Copy link
Contributor Author

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.

Copy link

@AnaMontes11 AnaMontes11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!

@jeprubio jeprubio requested review from dagonco and removed request for dpastor December 26, 2023 08:06
@Telefonica Telefonica deleted a comment from github-actions bot Dec 26, 2023
@Telefonica Telefonica deleted a comment from github-actions bot Dec 26, 2023
Comment on lines +312 to +314
fun setAssetOnClickListener(clickListener: OnClickListener) {
assetImageLayout.setOnClickListener(clickListener)
}
Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

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,
Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

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/

Comment on lines +31 to +45
@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)
}
}
Copy link
Contributor Author

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

Comment on lines +46 to +59
@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)
}
Copy link
Contributor Author

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

@Telefonica Telefonica deleted a comment from github-actions bot Dec 26, 2023
Copy link
Member

@jdelga jdelga left a 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
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but can't ve moved to the same line it's used as that would not compile:
Screenshot 2023-12-26 at 12 07 00

@@ -35,14 +43,30 @@ internal class ListRowItemKtTest: ScreenshotsTest() {
`then screenshot is OK`()
}

@Test
fun `check ListRowItem with clickable asset`() {
var clicked = 0
Copy link
Member

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

Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

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.

Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

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,
Copy link
Member

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!

Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

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.

@Telefonica Telefonica deleted a comment from github-actions bot Dec 26, 2023
override fun onBindViewHolder(holder: ListViewHolder, position: Int) {
with(holder.rowView) {
setTitle("Clickable Asset")
setAssetOnClickListener {
Copy link
Member

@dagonco dagonco Dec 26, 2023

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.

Copy link
Contributor Author

@jeprubio jeprubio Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The row can be clickable, that's for sure, and that remains the same as it was.

Added an extra row which is clickable the row and the asset to each of the catalogs if it's that what you mean.
Screenshot 2023-12-26 at 12 35 32

When clicking on the row:
Screenshot 2023-12-26 at 12 43 04

And on the asset:
Screenshot 2023-12-26 at 12 43 13

@Telefonica Telefonica deleted a comment from github-actions bot Dec 26, 2023
Copy link

📱 New catalog for testing generated: Download

Copy link
Member

@dagonco dagonco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiice!

@jeprubio jeprubio merged commit b760ce2 into main Dec 26, 2023
5 checks passed
@jeprubio jeprubio deleted the feature/ANDROID-14134-SetAssetsClickable branch December 26, 2023 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants