Files
react-native/packages/rn-tester/js/components/RNTesterText.js
Peter Abbondanzo 09682b5109 Fix dark mode text (#46898)
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
2024-10-10 11:02:18 -07:00

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]} />;
}