1 | import { Application } from '../application';
|
2 | import { FontScaleCategory, getClosestValidFontScale } from './font-scale-common';
|
3 | export * from './font-scale-common';
|
4 | let currentFontScale = null;
|
5 | function fontScaleChanged(origFontScale) {
|
6 | const oldValue = currentFontScale;
|
7 | currentFontScale = getClosestValidFontScale(origFontScale);
|
8 | if (oldValue !== currentFontScale) {
|
9 | Application.notify({
|
10 | eventName: Application.fontScaleChangedEvent,
|
11 | object: Application,
|
12 | newValue: currentFontScale,
|
13 | });
|
14 | }
|
15 | }
|
16 | export function getCurrentFontScale() {
|
17 | setupConfigListener();
|
18 | return currentFontScale;
|
19 | }
|
20 | export function getFontScaleCategory() {
|
21 | return FontScaleCategory.Medium;
|
22 | }
|
23 | function useAndroidFontScale() {
|
24 | fontScaleChanged(Number(Application.android.context.getResources().getConfiguration().fontScale));
|
25 | }
|
26 | let configChangedCallback;
|
27 | function setupConfigListener() {
|
28 | if (configChangedCallback) {
|
29 | return;
|
30 | }
|
31 | Application.off(Application.launchEvent, setupConfigListener);
|
32 | const context = Application.android?.context;
|
33 | if (!context) {
|
34 | Application.on(Application.launchEvent, setupConfigListener);
|
35 | return;
|
36 | }
|
37 | useAndroidFontScale();
|
38 | configChangedCallback = new android.content.ComponentCallbacks2({
|
39 | onLowMemory() {
|
40 |
|
41 | },
|
42 | onTrimMemory() {
|
43 |
|
44 | },
|
45 | onConfigurationChanged(newConfig) {
|
46 | fontScaleChanged(Number(newConfig.fontScale));
|
47 | },
|
48 | });
|
49 | context.registerComponentCallbacks(configChangedCallback);
|
50 | Application.on(Application.resumeEvent, useAndroidFontScale);
|
51 | }
|
52 | export function initAccessibilityFontScale() {
|
53 | setupConfigListener();
|
54 | }
|
55 |
|
\ | No newline at end of file |