react-native icon indicating copy to clipboard operation
react-native copied to clipboard

[iOS] getFontScale not updating when settings change

Open joebochill opened this issue 3 years ago • 1 comments

Description

When using PixelRatio.getFontScale within an application, the value does not update after the system font size changes without reloading the app.

React Native version:

System:
    OS: macOS 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 27.50 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.16.3 - /usr/local/bin/node
    Yarn: 1.22.5 - /usr/local/bin/yarn
    npm: 6.14.4 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.10.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1
    Android SDK:
      API Levels: 23, 24, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 27.0.3, 28.0.2, 28.0.3, 29.0.0, 29.0.2
      System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
      Android NDK: Not Found
  IDEs:
    Android Studio: 3.5 AI-191.8026.42.35.5791312
    Xcode: 12.2/12B45b - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_181 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.1 => 17.0.1 
    react-native: 0.64.0 => 0.64.0 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Add a console log statement to your application: console.log(PixelRatio.getFontScale)
  2. Start the application
  3. Observe the value that is printed
  4. Open Settings -> Accessibility -> Display & Text Size -> Larger Text and change the value in the font size selector
  5. Return to the application
  6. Observe that the application does not trigger a re-render and there is no re-calculation of the value

Expected Results

I would expect a redraw/re-render to be triggered automatically to reflect the change in the settings (Note that Text elements in the app scale appropriately based on the updated font size without reloading the JS).

Android works as expected. iOS does not get the new value unless I restart the application.

Snack, code example, screenshot, or link to a repository:

https://user-images.githubusercontent.com/29152776/111916528-c9f20e80-8a51-11eb-8ba0-17067cdc685f.mov

export const App = () => {
    console.log(PixelRatio.getFontScale());
    return (
        <Text>{PixelRatio.getFontScale()}</Text>
    )
}

joebochill avatar Mar 21 '21 18:03 joebochill

Similar to this issue (on the android side) from 2017: https://github.com/facebook/react-native/issues/17209

joebochill avatar Mar 21 '21 18:03 joebochill