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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix textoverflow on top appbar for components with long names #240

Merged
merged 3 commits into from Jul 12, 2022

Conversation

oas004
Copy link
Contributor

@oas004 oas004 commented Jul 7, 2022

Thank you for a very cool library! I absolutely love this! 馃槃 馃槏 When I started using it I noticed that the names of our components where quite long and that the toolbar was not quite handling this as you can see from the screenshots.

I had some trouble testing this and would love some help and feedback on that. I tried to make an Android test in the :showcase-browser-testsing but could not quite figure out a good way to test it. I also thought that it might be a bit flaky since the overflow will change with regards to screen size.

Before

toolbar_large_title

Now

toolbar_large_title_truncated

@vinaygaba
Copy link
Collaborator

@oas004 Could you upload the screenshots again. I'm not able to see them

Screen Shot 2022-07-07 at 9 11 30 PM

@vinaygaba
Copy link
Collaborator

Re: Testing

You can add a composable here that has a really long value for name in the ShowkaseComposable or Preview annotation (a name that extends at least 2 lines). Then you can add a test case in this file that verifies that the entire name is visible. You are right about the different screen sizes generally speaking but the testing we are doing in this repo are restricted to a single device as defined in the android.yml file so it should be fine to add a test case.

@@ -91,8 +92,7 @@ internal fun ShowkaseAppBar(
Row(
Modifier.fillMaxWidth()
.graphicsLayer(shadowElevation = 4f)
.padding(padding2x)
.height(64.dp),
.padding(padding2x),
Copy link
Collaborator

Choose a reason for hiding this comment

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

we might want to add a maxSize for the height but I'm curious to see the screenshots before that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm yeah maybe you're right 馃 Is it also maybe a bit weird that it spans 3 lines instead of 2? What do you think? :)

@oas004
Copy link
Contributor Author

oas004 commented Jul 8, 2022

@oas004 Could you upload the screenshots again. I'm not able to see them

Screen Shot 2022-07-07 at 9 11 30 PM

Hi, thanks for quick review! 馃槃 I tried to replace the screenshots now and upload them manually(instead of dragging and dropping them). Does it work now? :)

@oas004
Copy link
Contributor Author

oas004 commented Jul 8, 2022

Re: Testing

You can add a composable here that has a really long value for name in the ShowkaseComposable or Preview annotation (a name that extends at least 2 lines). Then you can add a test case in this file that verifies that the entire name is visible. You are right about the different screen sizes generally speaking but the testing we are doing in this repo are restricted to a single device as defined in the android.yml file so it should be fine to add a test case.

Thanks for quick review! Actually, when trying to write a test case for this I ran in to an issue. If I try to make a test on the node with test tag that the text is ellipsis, the NodeText has the entire text. So that means the text will go green if the text is correctly clipped an if It is not. There is an issue on this: https://issuetracker.google.com/issues/238332005 :) Could you please provide me with guidance on how to write a test case for this? :)

@@ -186,19 +189,34 @@ private fun ShowkaseAppBarTitle(
}
}

val LineCountKey = SemanticsPropertyKey<Int>("lineCount")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this be in its own file? :) What do u think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe move to a file called SemanticsUtils or something along those lines

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Moved it into SemanticsUtils in 833e234 馃槃

@oas004
Copy link
Contributor Author

oas004 commented Jul 10, 2022

Re: Testing
You can add a composable here that has a really long value for name in the ShowkaseComposable or Preview annotation (a name that extends at least 2 lines). Then you can add a test case in this file that verifies that the entire name is visible. You are right about the different screen sizes generally speaking but the testing we are doing in this repo are restricted to a single device as defined in the android.yml file so it should be fine to add a test case.

Thanks for quick review! Actually, when trying to write a test case for this I ran in to an issue. If I try to make a test on the node with test tag that the text is ellipsis, the NodeText has the entire text. So that means the text will go green if the text is correctly clipped an if It is not. There is an issue on this: https://issuetracker.google.com/issues/238332005 :) Could you please provide me with guidance on how to write a test case for this? :)

Managed to find a workaround for the test. Added it in baea74a 馃槃 What do you think?

@oas004 oas004 requested a review from vinaygaba July 11, 2022 23:12
@Composable
fun ToolbarTitle(
string: String,
modifier: Modifier
) {
val lineCount = remember {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not ideal to have test logic live in the component directly but I guess that happens pretty often in Compose due to how semantics are setup with some hooks into testing. Don't have a better idea on testing this so might be fine for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally agree with you on that! I think this can work for now :)

Copy link
Collaborator

@vinaygaba vinaygaba left a comment

Choose a reason for hiding this comment

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

Great work. One minor request and we are good to merge this after that.

@vinaygaba vinaygaba merged commit 504db33 into airbnb:master Jul 12, 2022
@oas004 oas004 deleted the fix/textoverflow-top-appbar branch July 12, 2022 07:30
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.

None yet

2 participants