Skip to content

fix(ios): Missing support for a11y font scale #10207

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

Merged
merged 6 commits into from
Mar 22, 2023

Conversation

CatchABus
Copy link
Contributor

@CatchABus CatchABus commented Feb 11, 2023

PR Checklist

What is the current behavior?

In iOS, fonts are not affected by device accessibility font scale settings.

What is the new behavior?

Fonts will be affected by device accessibility font scale settings.
We had a font scale implementation that actually was an incomplete work so I also performed a cleanup.

@NathanWalker For this to work, I used an API that was introduced at iOS 11. Do you think we should support older devices?
@farfromrefug Do you think this could have a performance impact? We could discuss about adding a property to make it configurable to both platforms perhaps.

Fixes https://discord.com/channels/603595811204366337/1048667697493319851

@nx-cloud
Copy link

nx-cloud bot commented Feb 11, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 2689f9e. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 2 targets

Sent with 💌 from NxCloud.

@cla-bot cla-bot bot added the cla: yes label Feb 11, 2023
@farfromrefug
Copy link
Collaborator

@CatchABus not 100% sure about perf consequences. But I think.it is always best to put that behind a property. Another reason to use a property is that components extending text-base (plugins) will also benefit from it. While if you do it in onCreateView and the plugin has its own onCreateView it won't get it.
We could try a perf test with collectionview to see If we see any slowdown because of it. But I dont think there will be any.

@CatchABus
Copy link
Contributor Author

CatchABus commented Feb 11, 2023

@CatchABus not 100% sure about perf consequences. But I think.it is always best to put that behind a property. Another reason to use a property is that components extending text-base (plugins) will also benefit from it. While if you do it in onCreateView and the plugin has its own onCreateView it won't get it. We could try a perf test with collectionview to see If we see any slowdown because of it. But I dont think there will be any.

I think we could add an accessibilityAdjustsFontSize boolean property and register it to text-base. Default value could be true (nowadays most frameworks force you to enable most of a11y anyway) and check for native view instance inside since the native API we'll be using has no support for views like UIButton.

@CatchABus CatchABus marked this pull request as draft February 12, 2023 23:19
@NathanWalker NathanWalker added this to the 8.5 milestone Feb 16, 2023
@dkzeb
Copy link

dkzeb commented Feb 24, 2023

I've tested the changes on iOS and i'm happy to report that it does fix scaling of labels / texts - however - this PR does not fix font-scaling in buttons - its missing an adjustsFontForContentSizeCategory in ui/button/index.ios.ts when creating the native view
I will keep testing font-scaling (as accessibility is a very important for our project), and report back if i find anything else missing

@CatchABus
Copy link
Contributor Author

CatchABus commented Feb 28, 2023

It seems that using UIFontMetrics API is not a suitable option for NativeScript right now.
The main problem is that even if adjustsFontForContentSizeCategory takes care of automatic resize, the height of affected elements will have to be recalculated manually by requesting a new layout. This would require traversing entire view tree to find affected views.

According to a11y guidelines, an iOS developer can align views with scaled font by meddling with layout constraints mechanism, and this isn't functional in {N} right now.
More information: https://a11y-guidelines.orange.com/en/mobile/ios/wwdc/2017/245/#auto-layout-system-spacing-constraints-1131

What we can do now is fix existing behaviour, it's like 1 or 2 missing lines to apply scale using an inherited property called _fontScale. The main problem right now is there is a flaw in Page elements related to inherited properties propagation and we'll need to fix that first.

@farfromrefug
Copy link
Collaborator

@CatchABus on iOS you dont need to find all the necessary views and call requestLayout. Simply relayout all pages
Even if you call requestLayout on a single view, the way it works in N is that it will go up to the parent page and relayout the full page (though not optimized at all)

@CatchABus
Copy link
Contributor Author

CatchABus commented Feb 28, 2023

@CatchABus on iOS you dont need to find all the necessary views and call requestLayout. Simply relayout all pages Even if you call requestLayout on a single view, the way it works in N is that it will go up to the parent page and relayout the full page (though not optimized at all)

Yes, that was my initial thought but unfortunately it didn't work as expected since it's going up as you mentioned. You have to call requestLayout or sizeToFit on those views directly so that they update their direct parents too.

We have already gotten an inherited property called _fontScale that's doing what we want, and I think it's part of an unfinished work from initial a11y merge to core.

I'm preparing another PR for fixing a problem related to inherited properties, then I think we can complete unfinished work for font scale. :D

@CatchABus CatchABus force-pushed the a11y-ios-font-scaling branch from 5e357f4 to ec1a617 Compare March 4, 2023 15:25
@CatchABus CatchABus closed this Mar 4, 2023
@CatchABus CatchABus force-pushed the a11y-ios-font-scaling branch from ec1a617 to 11cdf08 Compare March 4, 2023 15:27
@CatchABus CatchABus reopened this Mar 4, 2023
@CatchABus
Copy link
Contributor Author

@dkzeb Things took a different turn and I ended up extending current functionality for a number of reasons.
Can you try new changes? They should work along with changes from PR #10225

@dkzeb
Copy link

dkzeb commented Mar 6, 2023

@CatchABus - thx - i'll test it out :)

@dkzeb
Copy link

dkzeb commented Mar 6, 2023

@CatchABus, i still doesn't scale text in buttons

@CatchABus
Copy link
Contributor Author

@CatchABus, i still doesn't scale text in buttons

Strange, I have Button texts scale in the app I'm testing this.
Can you try it on a fresh new app or give me an app sample to check?

@NathanWalker NathanWalker marked this pull request as ready for review March 16, 2023 05:34
@NathanWalker NathanWalker merged commit 95f3772 into NativeScript:main Mar 22, 2023
@rigor789
Copy link
Member

I'll have to double check, but I believe the added

apps/automated/src/ui/styling/style-properties-tests.ios.ts

file will prevent running the tests from

apps/automated/src/ui/styling/style-properties-tests.ts

because it "overrides" it during the webpack build. Checking for global.isIOS would likely be a better solution (or whatever is used in other tests that check for the platform).

@NathanWalker
Copy link
Contributor

If that test fails we’ll swap that, good mention.

@CatchABus
Copy link
Contributor Author

I'll have to double check, but I believe the added

apps/automated/src/ui/styling/style-properties-tests.ios.ts

file will prevent running the tests from

apps/automated/src/ui/styling/style-properties-tests.ts

because it "overrides" it during the webpack build. Checking for global.isIOS would likely be a better solution (or whatever is used in other tests that check for the platform).

I think I might have accidentally missed this. The initial plan would be to have a common file and a blank android file that exports tests from common too. If checking for global.isIOS is an acceptable option, then sure I can change it to check for platform flag.
@rigor789 Should we display any message for the android plarform?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants