mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
11c8bf3137
Summary: This adds Dynamic Type support in iOS as described [here](https://github.com/react-native-community/discussions-and-proposals/issues/519). `Text` elements have a new prop, `dynamicTypeRamp`, that allows users to specify which font ramp a particular `Text` element should take on as the OS's accessibility setting for text size. The different types line up with different values of `UIFontTextStyle`. If not specified, we default to the current behavior. ~~For the moment, this change is only for Paper. I tried applying a corresponding change to Fabric by adding an additional field to [`facebook::react::TextAttributes`](https://github.com/facebook/react-native/blob/main/ReactCommon/react/renderer/attributedstring/TextAttributes.h) and changing [`RCTEffectiveFontSizeMultiplierFromTextAttributes`](https://github.com/facebook/react-native/blob/afb124dcf0cdf0db525acc7cfd2cea2742c64068/ReactCommon/react/renderer/textlayoutmanager/platform/ios/RCTAttributedTextUtils.mm#L79-L84) to use that new field, but in the process I discovered that this function doesn't seem to ever get called, hence [this bug](https://github.com/facebook/react-native/issues/34990).~~ ## Changelog [iOS] [Added] - Dynamic Type support Pull Request resolved: https://github.com/facebook/react-native/pull/35017 Test Plan: Validated with a test page in RNTester. Screenshots follow: A) Default text size B) Largest non-accessibility text size C) Largest accessibility text size, split across two screenshots due to size | A | B | C | |-|-|-| |  |  |  | |||  | Reviewed By: sammy-SC Differential Revision: D40779346 Pulled By: NickGerleman fbshipit-source-id: efc7a8e9810a93afc82c5def97af15a2e8453d90
82 lines
2.4 KiB
JavaScript
82 lines
2.4 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
import {createViewConfig} from '../NativeComponent/ViewConfig';
|
|
import UIManager from '../ReactNative/UIManager';
|
|
import createReactNativeComponentClass from '../Renderer/shims/createReactNativeComponentClass';
|
|
import {type HostComponent} from '../Renderer/shims/ReactNativeTypes';
|
|
import {type ProcessedColorValue} from '../StyleSheet/processColor';
|
|
import {type PressEvent} from '../Types/CoreEventTypes';
|
|
import {type TextProps} from './TextProps';
|
|
|
|
type NativeTextProps = $ReadOnly<{
|
|
...TextProps,
|
|
isHighlighted?: ?boolean,
|
|
selectionColor?: ?ProcessedColorValue,
|
|
onClick?: ?(event: PressEvent) => mixed,
|
|
// This is only needed for platforms that optimize text hit testing, e.g.,
|
|
// react-native-windows. It can be used to only hit test virtual text spans
|
|
// that have pressable events attached to them.
|
|
isPressable?: ?boolean,
|
|
}>;
|
|
|
|
const textViewConfig = {
|
|
validAttributes: {
|
|
isHighlighted: true,
|
|
isPressable: true,
|
|
numberOfLines: true,
|
|
ellipsizeMode: true,
|
|
allowFontScaling: true,
|
|
dynamicTypeRamp: true,
|
|
maxFontSizeMultiplier: true,
|
|
disabled: true,
|
|
selectable: true,
|
|
selectionColor: true,
|
|
adjustsFontSizeToFit: true,
|
|
minimumFontScale: true,
|
|
textBreakStrategy: true,
|
|
onTextLayout: true,
|
|
onInlineViewLayout: true,
|
|
dataDetectorType: true,
|
|
android_hyphenationFrequency: true,
|
|
lineBreakStrategyIOS: true,
|
|
},
|
|
directEventTypes: {
|
|
topTextLayout: {
|
|
registrationName: 'onTextLayout',
|
|
},
|
|
topInlineViewLayout: {
|
|
registrationName: 'onInlineViewLayout',
|
|
},
|
|
},
|
|
uiViewClassName: 'RCTText',
|
|
};
|
|
|
|
const virtualTextViewConfig = {
|
|
validAttributes: {
|
|
isHighlighted: true,
|
|
isPressable: true,
|
|
maxFontSizeMultiplier: true,
|
|
},
|
|
uiViewClassName: 'RCTVirtualText',
|
|
};
|
|
|
|
export const NativeText: HostComponent<NativeTextProps> =
|
|
(createReactNativeComponentClass('RCTText', () =>
|
|
createViewConfig(textViewConfig),
|
|
): any);
|
|
|
|
export const NativeVirtualText: HostComponent<NativeTextProps> =
|
|
!global.RN$Bridgeless && !UIManager.hasViewManagerConfig('RCTVirtualText')
|
|
? NativeText
|
|
: (createReactNativeComponentClass('RCTVirtualText', () =>
|
|
createViewConfig(virtualTextViewConfig),
|
|
): any);
|