From 0fc2e954be1e4b7e3ec6f42838251c4c1e997fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Tue, 29 Oct 2024 12:40:09 -0700 Subject: [PATCH] add example for dynamic sized text input (#46976) Summary: This PR adds an example showcasing a TextInput whose width gets resized dynamically based on the text content width. This example was added for this PR, which tries to address a flickering bug with dynamic sized TextInputs: - https://github.com/facebook/react-native/pull/46973 ## Changelog: [INTERNAL] [ADDED] Added dynamic content width TextInput example Pull Request resolved: https://github.com/facebook/react-native/pull/46976 Test Plan: Test in RNTester app: https://github.com/user-attachments/assets/7571b80b-7035-47df-b840-4218ab0802b5 Reviewed By: NickGerleman Differential Revision: D64271454 Pulled By: arushikesarwani94 fbshipit-source-id: 28fe7bd93891ffe5284340d73e9ee947654f1788 --- .../TextInput/TextInputSharedExamples.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js index fbf4deb29d2..f4e9c9801aa 100644 --- a/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js +++ b/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js @@ -846,6 +846,40 @@ function MultilineStyledTextInput({ ); } +function DynamicContentWidth() { + const [text, setText] = useState(''); + const update = () => { + const randomNumber = Math.floor(Math.random() * 10); + setText(text + randomNumber); + }; + + return ( + + Uncontrolled: + + Controlled: + +