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 support topbar title font scaling #7904

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

mika-lindell
Copy link

  • Android only
  • To enable font scaling that can be adjusted via Android Settings-app:
    • Accessibility -> Display size and text -> Font size
  • Adds options.topBar.title.allowFontScaling
  • Adds and updated unit tests
  • When allowFontScaling is enabled, sets top bar title to use SP units. When font scaling is 1.0, it should be the same size as when using DIP
  • Here it's set to false by default, because it can conflict with other top bar options like subtitle, height, fontSize etc. that existing users may have
  • I'm thinking about making similar changes to iOS, but I wanted feedback on this one first. iOS has some issues especially when "Larger accessibility sizes"-setting is enabled
{
   topBar: {
      title: {
         text: "My title",
         fontSize: 18,
         allowFontScaling: true,
      },
   },
}
allowFontScaling=false allowFontScaling=true
Screenshot_20240813-183132 Screenshot_20240813-175043

Allowing font scaling in top bar title seems to be convention in "standard" Android apps:

Screenshot_20240812-155831 Screenshot_20240812-155816
Screenshot_20240812-155559 Screenshot_20240812-155736

Settings that can change font scaling in users' device

import kotlin.math.roundToInt
import kotlin.test.assertFalse

private const val UUT_WIDTH = 1000
private const val UUT_HEIGHT = 100

@Config(sdk = [30])
Copy link
Author

Choose a reason for hiding this comment

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

textSizeUnit is not available before api level 30

@@ -46,7 +48,16 @@ class TitleSubTitleLayout(context: Context) : LinearLayout(context) {
}
}

fun setTitleFontSize(size: Float) = titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size)
fun setTitleFontSize(size: Float) {
Copy link
Author

Choose a reason for hiding this comment

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

For it to make sense from the perspective of options, I didn't find a way to set units without setting font size. Using titleTextView.textSize returns scaled font size, so need to have the absolute font size somewhere

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.

1 participant