Skip to content

Commit cf436ce

Browse files
authored
Correct text sizing at the RSD native boundary (#59869)
Summary: Resolve opted-in React Strict DOM native styles at baseline font scale so native text rendering applies accessibility enlargement once. Relative `rem`/`em` layout uses the same baseline units. Existing applications remain on the legacy path, and direct React Native text/input sizing is unchanged. Changelog: [Internal] Reviewed By: Picowchew Differential Revision: D129139800 Pull Request resolved: #59869
1 parent 82dab20 commit cf436ce

4 files changed

Lines changed: 136 additions & 0 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import type {TextProps} from '../../../Libraries/Text/TextProps';
12+
import type {NativeTextRole} from '../text/NativeTextScalingTypes';
13+
14+
import Platform from '../../../Libraries/Utilities/Platform';
15+
16+
export type NativeUIAccessibilityAdapter = Readonly<{
17+
supportsSystemAccessibility: boolean,
18+
getDynamicTypeRamp: (
19+
role?: NativeTextRole,
20+
) => ?NonNullable<TextProps['dynamicTypeRamp']>,
21+
}>;
22+
23+
const appleTVRamps = {
24+
body: 'body',
25+
caption: 'caption1',
26+
label: 'callout',
27+
heading1: 'title1',
28+
heading2: 'title2',
29+
heading3: 'title3',
30+
} as const;
31+
32+
const appleTVAdapter: NativeUIAccessibilityAdapter = {
33+
supportsSystemAccessibility: true,
34+
getDynamicTypeRamp: (role?: NativeTextRole) => appleTVRamps[role ?? 'body'],
35+
};
36+
37+
const legacyAdapter: NativeUIAccessibilityAdapter = {
38+
supportsSystemAccessibility: false,
39+
getDynamicTypeRamp: () => undefined,
40+
};
41+
42+
/**
43+
* The capability gate is intentionally limited to validated platforms.
44+
* Native scaling support does not require an Apple Dynamic Type ramp.
45+
*/
46+
export function getNativeUIAccessibilityAdapter(): NativeUIAccessibilityAdapter {
47+
return Platform.OS === 'ios' && Platform.constants.interfaceIdiom === 'tv'
48+
? appleTVAdapter
49+
: legacyAdapter;
50+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import {getNativeUIAccessibilityAdapter} from './NativeUIAccessibilityPlatform';
12+
13+
export type NativeUIAccessibilityMode = 'legacy' | 'system-v2';
14+
export type NativeUIAccessibilityConfigurationResult = Readonly<{
15+
requestedMode: NativeUIAccessibilityMode,
16+
effectiveMode: NativeUIAccessibilityMode,
17+
status: 'applied' | 'unsupported-platform',
18+
}>;
19+
20+
let mode: NativeUIAccessibilityMode = 'legacy';
21+
22+
/**
23+
* Select the shared UI accessibility behavior before mounting any surfaces.
24+
* The version is a compatibility boundary, not a per-feature opt-in.
25+
* Unsupported adoption retains legacy behavior and is reported to the caller.
26+
*/
27+
export function configureNativeUIAccessibility(
28+
config: Readonly<{mode: NativeUIAccessibilityMode}>,
29+
): NativeUIAccessibilityConfigurationResult {
30+
const unsupported =
31+
config.mode === 'system-v2' &&
32+
!getNativeUIAccessibilityAdapter().supportsSystemAccessibility;
33+
mode = unsupported ? 'legacy' : config.mode;
34+
return {
35+
requestedMode: config.mode,
36+
effectiveMode: mode,
37+
status: unsupported ? 'unsupported-platform' : 'applied',
38+
};
39+
}
40+
41+
export function getNativeUIAccessibilityMode(): NativeUIAccessibilityMode {
42+
return mode;
43+
}
44+
45+
export function isNativeUIAccessibilityEnabled(): boolean {
46+
return mode === 'system-v2';
47+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
import type {TextProps} from '../../../Libraries/Text/TextProps';
12+
import type {NativeTextRole} from './NativeTextScalingTypes';
13+
14+
import {getNativeUIAccessibilityAdapter} from '../accessibility/NativeUIAccessibilityPlatform';
15+
import {isNativeUIAccessibilityEnabled} from '../accessibility/NativeUIAccessibilityPolicy';
16+
17+
export function isNativeTextScalingEnabled(): boolean {
18+
return isNativeUIAccessibilityEnabled();
19+
}
20+
21+
export function getNativeTextScalingRamp(
22+
role?: NativeTextRole,
23+
): ?NonNullable<TextProps['dynamicTypeRamp']> {
24+
return isNativeTextScalingEnabled()
25+
? getNativeUIAccessibilityAdapter().getDynamicTypeRamp(role)
26+
: undefined;
27+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
export type NativeTextRole =
12+
'body' | 'caption' | 'label' | 'heading1' | 'heading2' | 'heading3';

0 commit comments

Comments
 (0)