-
Notifications
You must be signed in to change notification settings - Fork 200
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
Introduce auto sizing for all app bar title components #891
Introduce auto sizing for all app bar title components #891
Conversation
f0f32a0
to
f15a996
Compare
Detekt check failed. Please run |
f15a996
to
596faa8
Compare
* of the text size, use [TextUnit.Unspecified] for that parameter.) | ||
* | ||
* Adapted from Alchitry on Stack Overflow, licensed under CC BY-SA 4.0: | ||
* https://stackoverflow.com/a/71416530 |
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.
It's tough to know if this is safe. I think we might have to publish our app code under CC BY-SA 4.0 as well, which makes using our app's code difficult.
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.
That's fair. I can reimplement the same solution by hand, but with a different API. Would you prefer that, or shall we skip the adjustments for bigger font sizes?
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.
We might need to reimplement this. I wish we had a library for it. 😅
If there isn't a licensing issue, I'll leave it up to you to implement this, as you are reliable.
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.
I reimplemented AutoSizeText
with the same idea, but without コピペ, in 24a66c0
596faa8
to
4572700
Compare
We introduced the MediumTopAppBar. Does it affect this PR? |
Yes, I believe it does. Let me rebase and do another pass on this! |
@takahirom Adjusted the MediumTopAppBar in 0eae2c3.
|
* with the upper bound being defined by the font size of its [style]. | ||
*/ | ||
@Composable | ||
fun AutoSizeText( |
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.
Looks great!
|
||
// Keep decreasing the font size until the text fits in the box without exceeding the max lines | ||
while (paragraph.didExceedMaxLines || maxHeight < paragraph.height.toDp() || maxWidth < paragraph.minIntrinsicWidth.toDp()) { | ||
targetFontSize *= 0.95 |
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.
If you are interested, we might be able to use binary search for this. 😄
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.
Fun idea! Added in 612af1c
Thank you for your comprehensive screenshots. |
0eae2c3
to
b0817f9
Compare
b0817f9
to
e0b7d8b
Compare
It took a bit to get the line count assertion for text nodes just right, but I managed to pull it off in e0b7d8b. From now on, we can assert the line count of any text based on expectations! |
Snapshot diff report
|
Text( | ||
text = text, | ||
color = color, | ||
fontSize = calculateFontSize(text, style, color, textAlign, maxLines), |
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.
I'm not sure, but could we consider using remember{}
caching for this? If so, it might lead to a open source library-level optimization. 👍
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.
Sorry, I forgot that we can't use Composable function in remember lambda.👀
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.
It should be possible to rearrange this to work. Let me think about this tonight!
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.
Turns out that Paragraph()
does not require any composable context. 👀 be532bb
This required a new type of matcher for asserting the line count of a text node
285de21
to
be532bb
Compare
.../src/commonMain/kotlin/io/github/droidkaigi/confsched/designsystem/component/AutoSizeText.kt
Outdated
Show resolved
Hide resolved
Looks awesome! I want to share this, and for the people who want to use this implementation, could you update the pull request content to match the current code? |
…onfsched/designsystem/component/AutoSizeText.kt Co-authored-by: Takahiro Menju <[email protected]>
I updated the description to reference the new implementation. @takahirom please let me know if you'd like me to change something else about the PR description. 🙇♂️ |
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.
Thank you for your valuable contribution!
Issue
Overview (Required)
AutoSizeText
, a component that automatically finds the correct size to fit a text into a boxstyle
of the text, but it will shrink if necessaryTimetableScreen
AnimatedTextTopAppBar
(fix for the main tabs on the home screen)AnimatedMediumTopAppBar
(fix for contributor, sponsor, staff, settings screens)Movie (Optional)
Before
before_1725061103.mp4
before2_1725061142.mp4
before3_1725061201.mp4
After
after_1725060593.mp4
after2_1725060638.mp4
after3_1725060970.mp4