UNPKG

1.81 kBJavaScriptView Raw
1import { Application } from '../application';
2import { FontScaleCategory, getClosestValidFontScale } from './font-scale-common';
3export * from './font-scale-common';
4let currentFontScale = null;
5function 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}
16export function getCurrentFontScale() {
17 setupConfigListener();
18 return currentFontScale;
19}
20export function getFontScaleCategory() {
21 return FontScaleCategory.Medium;
22}
23function useAndroidFontScale() {
24 fontScaleChanged(Number(Application.android.context.getResources().getConfiguration().fontScale));
25}
26let configChangedCallback;
27function 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 // Dummy
41 },
42 onTrimMemory() {
43 // Dummy
44 },
45 onConfigurationChanged(newConfig) {
46 fontScaleChanged(Number(newConfig.fontScale));
47 },
48 });
49 context.registerComponentCallbacks(configChangedCallback);
50 Application.on(Application.resumeEvent, useAndroidFontScale);
51}
52export function initAccessibilityFontScale() {
53 setupConfigListener();
54}
55//# sourceMappingURL=font-scale.android.js.map
\No newline at end of file