question

jcmanke avatar image
0 Votes"
jcmanke asked RobCaplan edited

Responding to Dynamic Text changes at runtime

I'm working on adding some better accessibility support to a Xamarin.Forms application, including font scaling. For test purposes, I have made a new solution with a very simple layout:

 <StackLayout Padding="20">
     <Label Text="Small" FontSize="Small"/>
     <Label Text="Medium" FontSize="Medium"/>
     <Label Text="Large" FontSize="Large"/>
     <Label Text="BodyStyle" Style="{DynamicResource BodyStyle}"/>
     <Label Text="Font Size 24" FontSize="24"/>
 </StackLayout>

On Android, when I go to Settings, change the font size, and return to the app, all 5 labels change in response to the accessibility settings. On iOS, only the BodyStyle changes unless I swipe-kill and reopen the app. Is there an AppDelegate override or something I can add so I can respond to accessibility changes without killing the app or needing dynamic resources for everything?

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

jcmanke avatar image
0 Votes"
jcmanke answered

I've settled on using the built-in Device Styles for now.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered jcmanke commented

Hello,

Welcome to Microsoft Q&A!

You can simply use the following code in iOS project to detect when the accessibility settings has been changed .

Foundation.NSObject observerToken
             = UIApplication.Notifications.ObserveContentSizeCategoryChanged(
                 (s, e) =>
                 { 
                        //use messaging center
                 });


Then you can send message to forms project to rebuild your UI.

Refer to https://forums.xamarin.com/discussion/186212/how-to-handle-dynamic-type-the-larger-text-accessibility-option-on-ios-without-re-starting-app#latest .


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Even in my little test app, triggering an InvalidateMeasure() on the page or even resetting Application.Current.MainPage in response to that event doesn't appear to affect anything besides the BodyStyle label.

After looking at the source code, I added a few more NamedSize labels because it seems that a subset is designed to respond to accessibility changes. For that subset (Body/Caption/Header/Title/Subtitle) re-instantiating the page in response to the event makes them change size.

Unfortunately, about 99% of the font sizes in my real application are set using numbers, not named sizes, so even completely recreating the entire navigation stack of the application at runtime does not appear to be a viable solution without significant refactoring of all the styles defined in my application.

0 Votes 0 ·