Files
react-native/packages/rn-tester/js/examples/TextInput/ExampleTextInput.js
T
Sam Zhou 797705c00d Make use of ref-as-prop support in examples (#51358)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51358

Make use of the React 19 feature so that we can remove the remaining `forwardRef` in react native.

Changelog: [Internal]

Reviewed By: yungsters

Differential Revision: D74812747

fbshipit-source-id: 7ded547ff62ca59d28abfc46a2f57466e2486acd
2025-05-15 09:55:32 -07:00

56 lines
1.2 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
* @oncall react_native
*/
import {RNTesterThemeContext} from '../../components/RNTesterTheme';
import React, {useContext} from 'react';
import {StyleSheet, TextInput} from 'react-native';
const ExampleTextInput: component(
ref: React.RefSetter<null | React.ElementRef<typeof TextInput>>,
...props: React.ElementConfig<typeof TextInput>
) = ({
ref,
...props
}: {
ref?: React.RefSetter<null | React.ElementRef<typeof TextInput>>,
...React.ElementConfig<typeof TextInput>,
}) => {
const theme = useContext(RNTesterThemeContext);
return (
<TextInput
ref={ref}
{...props}
style={[
{
color: theme.LabelColor,
backgroundColor: theme.SecondaryGroupedBackgroundColor,
borderColor: theme.QuaternaryLabelColor,
},
styles.input,
props.style,
]}
/>
);
};
const styles = StyleSheet.create({
input: {
borderWidth: 1,
fontSize: 13,
flexGrow: 1,
flexShrink: 1,
padding: 4,
},
});
export default ExampleTextInput;