From 9218d1ed89cc410ecb28938c399534904cd5f417 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 27 May 2025 06:44:54 -0700 Subject: [PATCH] Fix InputAccessoryView example in dark mode and convert to functional components (#51583) Summary: As I reviewed some examples, I noticed that this one's dark mode could be improved, and the code could be modernised a bit as well by converting its classes into functional components. ## Changelog: [INTERNAL] - Fix InputAccessoryView example in dark mode and convert to functional components Pull Request resolved: https://github.com/facebook/react-native/pull/51583 Test Plan:
Screenshots | Dark | Light | |--------|-------| | ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-05-24 at 17 39 16](https://github.com/user-attachments/assets/3ed7cb53-89d4-440d-ac4f-50816527774e) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2025-05-24 at 17 39 35](https://github.com/user-attachments/assets/94592d35-859d-4666-a836-977903e955af) |
Reviewed By: fabriziocucci Differential Revision: D75404561 Pulled By: cortinico fbshipit-source-id: 3318e9869919e99055e47b59c89de0b22976f142 --- .../InputAccessoryViewExample.js | 105 ++++++++---------- 1 file changed, 49 insertions(+), 56 deletions(-) diff --git a/packages/rn-tester/js/examples/InputAccessoryView/InputAccessoryViewExample.js b/packages/rn-tester/js/examples/InputAccessoryView/InputAccessoryViewExample.js index 798658d1456..532a9ea2837 100644 --- a/packages/rn-tester/js/examples/InputAccessoryView/InputAccessoryViewExample.js +++ b/packages/rn-tester/js/examples/InputAccessoryView/InputAccessoryViewExample.js @@ -10,8 +10,9 @@ 'use strict'; -const React = require('react'); -const { +import {useTheme} from '../../components/RNTesterTheme'; +import {useState} from 'react'; +import { Alert, Button, InputAccessoryView, @@ -20,66 +21,59 @@ const { Text, TextInput, View, -} = require('react-native'); +} from 'react-native'; -type MessageProps = $ReadOnly<{}>; -class Message extends React.PureComponent { - render(): React.Node { - return ( - - Text Message - - ); - } +function Message(): React.Node { + return ( + + Text Message + + ); } -type TextInputProps = $ReadOnly<{}>; -type TextInputState = {text: string}; -class TextInputBar extends React.PureComponent { - state: TextInputState = {text: ''}; +function TextInputBar(): React.Node { + const {PlaceholderTextColor, LabelColor, SeparatorColor} = useTheme(); + const [text, setText] = useState(''); - render(): React.Node { - return ( - - { - this.setState({text}); - }} - value={this.state.text} - placeholder={'Type a message...'} - /> -