1 | import { CssProperty, InheritedCssProperty, Property } from '../ui/core/properties';
|
2 | import { booleanConverter } from '../ui/core/view-base';
|
3 | import { Style } from '../ui/styling/style';
|
4 | import { AccessibilityLiveRegion, AccessibilityRole, AccessibilityState } from './accessibility-types';
|
5 | function makePropertyEnumConverter(enumValues) {
|
6 | return (value) => {
|
7 | if (!value || typeof value !== 'string') {
|
8 | return null;
|
9 | }
|
10 | for (const [enumKey, enumValue] of Object.entries(enumValues)) {
|
11 | if (typeof enumKey !== 'string') {
|
12 | continue;
|
13 | }
|
14 | if (enumKey === value || `${enumValue}`.toLowerCase() === `${value}`.toLowerCase()) {
|
15 | return enumValue;
|
16 | }
|
17 | }
|
18 | return null;
|
19 | };
|
20 | }
|
21 | export const accessibilityEnabledProperty = new CssProperty({
|
22 | name: 'accessible',
|
23 | defaultValue: true,
|
24 | cssName: 'a11y-enabled',
|
25 | valueConverter: booleanConverter,
|
26 | });
|
27 | accessibilityEnabledProperty.register(Style);
|
28 | export const iosAccessibilityAdjustsFontSizeProperty = new InheritedCssProperty({
|
29 | defaultValue: false,
|
30 | name: 'iosAccessibilityAdjustsFontSize',
|
31 | cssName: 'ios-a11y-adjusts-font-size',
|
32 | valueConverter: booleanConverter,
|
33 | });
|
34 | iosAccessibilityAdjustsFontSizeProperty.register(Style);
|
35 | export const iosAccessibilityMinFontScaleProperty = new InheritedCssProperty({
|
36 | defaultValue: 0,
|
37 | name: 'iosAccessibilityMinFontScale',
|
38 | cssName: 'ios-a11y-min-font-scale',
|
39 | valueConverter: parseFloat,
|
40 | });
|
41 | iosAccessibilityMinFontScaleProperty.register(Style);
|
42 | export const iosAccessibilityMaxFontScaleProperty = new InheritedCssProperty({
|
43 | defaultValue: 0,
|
44 | name: 'iosAccessibilityMaxFontScale',
|
45 | cssName: 'ios-a11y-max-font-scale',
|
46 | valueConverter: parseFloat,
|
47 | });
|
48 | iosAccessibilityMaxFontScaleProperty.register(Style);
|
49 | export const accessibilityHiddenProperty = new (__APPLE__ ? InheritedCssProperty : CssProperty)({
|
50 | name: 'accessibilityHidden',
|
51 | cssName: 'a11y-hidden',
|
52 | valueConverter: booleanConverter,
|
53 | });
|
54 | accessibilityHiddenProperty.register(Style);
|
55 | export const accessibilityIdentifierProperty = new Property({
|
56 | name: 'accessibilityIdentifier',
|
57 | });
|
58 | export const accessibilityRoleProperty = new CssProperty({
|
59 | name: 'accessibilityRole',
|
60 | cssName: 'a11y-role',
|
61 | valueConverter: makePropertyEnumConverter(AccessibilityRole),
|
62 | });
|
63 | accessibilityRoleProperty.register(Style);
|
64 | export const accessibilityStateProperty = new CssProperty({
|
65 | name: 'accessibilityState',
|
66 | cssName: 'a11y-state',
|
67 | valueConverter: makePropertyEnumConverter(AccessibilityState),
|
68 | });
|
69 | accessibilityStateProperty.register(Style);
|
70 | export const accessibilityLabelProperty = new Property({
|
71 | name: 'accessibilityLabel',
|
72 | });
|
73 | export const accessibilityValueProperty = new Property({
|
74 | name: 'accessibilityValue',
|
75 | });
|
76 | export const accessibilityHintProperty = new Property({
|
77 | name: 'accessibilityHint',
|
78 | });
|
79 | export const accessibilityIgnoresInvertColorsProperty = new Property({
|
80 | name: 'accessibilityIgnoresInvertColors',
|
81 | valueConverter: booleanConverter,
|
82 | });
|
83 | export const accessibilityLiveRegionProperty = new CssProperty({
|
84 | name: 'accessibilityLiveRegion',
|
85 | cssName: 'a11y-live-region',
|
86 | defaultValue: AccessibilityLiveRegion.None,
|
87 | valueConverter: makePropertyEnumConverter(AccessibilityLiveRegion),
|
88 | });
|
89 | accessibilityLiveRegionProperty.register(Style);
|
90 | export const accessibilityTraitsProperty = new Property({
|
91 | name: 'accessibilityTraits',
|
92 | });
|
93 | export const accessibilityLanguageProperty = new CssProperty({
|
94 | name: 'accessibilityLanguage',
|
95 | cssName: 'a11y-lang',
|
96 | });
|
97 | accessibilityLanguageProperty.register(Style);
|
98 | export const accessibilityMediaSessionProperty = new CssProperty({
|
99 | name: 'accessibilityMediaSession',
|
100 | cssName: 'a11y-media-session',
|
101 | });
|
102 | accessibilityMediaSessionProperty.register(Style);
|
103 |
|
104 |
|
105 |
|
106 | export const accessibilityStepProperty = new CssProperty({
|
107 | name: 'accessibilityStep',
|
108 | cssName: 'a11y-step',
|
109 | defaultValue: 10,
|
110 | valueConverter: (v) => {
|
111 | const step = parseFloat(v);
|
112 | if (isNaN(step) || step <= 0) {
|
113 | return 10;
|
114 | }
|
115 | return step;
|
116 | },
|
117 | });
|
118 | accessibilityStepProperty.register(Style);
|
119 |
|
\ | No newline at end of file |