mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
09682b5109
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/46898 Replaces *many* `Text` component usages with `RNTesterText`: a thin wrapper around `Text` that applies color based on the color scheme chosen by the user. It makes text legible for dark mode across 41 different example files. This changes intentionally do not touch a few larger component sites that expand beyond RNTester, like `Animated` and `NewAppScreen` Changelog: [Internal] Reviewed By: rshest Differential Revision: D64053464 fbshipit-source-id: 9516fef2afe1b364eb38e85e3a2dbb5c434e44db
39 lines
1.0 KiB
JavaScript
39 lines
1.0 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 strict-local
|
|
* @format
|
|
*/
|
|
|
|
import type {TextProps} from 'react-native/Libraries/Text/TextProps';
|
|
|
|
import {RNTesterThemeContext} from './RNTesterTheme';
|
|
import React, {useContext, useMemo} from 'react';
|
|
import {Text} from 'react-native';
|
|
|
|
type Props = $ReadOnly<{
|
|
...TextProps,
|
|
variant?: 'body' | 'label' | 'caption',
|
|
}>;
|
|
|
|
export default function RNTesterText(props: Props): React.Node {
|
|
const {style, variant, ...rest} = props;
|
|
const theme = useContext(RNTesterThemeContext);
|
|
const color = useMemo(() => {
|
|
switch (variant) {
|
|
case 'body':
|
|
return theme.LabelColor;
|
|
case 'label':
|
|
return theme.SecondaryLabelColor;
|
|
case 'caption':
|
|
return theme.TertiaryLabelColor;
|
|
default:
|
|
return theme.LabelColor;
|
|
}
|
|
}, [variant, theme]);
|
|
return <Text {...rest} style={[{color}, style]} />;
|
|
}
|