mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: While investigating https://github.com/facebook/react-native/issues/22186, some false positives showed up as some of the examples also have non-strict mode compatible code. In this PR: - Converting from class to functional components some TextInput and Image examples that were using `UNSAFE_` lifecycles. - Unifying the auto-expanding example as it was exactly the same for iOS and Android. ## Changelog: [INTERNAL] - Fix RNTester strict mode warnings for TextInput and Image examples Pull Request resolved: https://github.com/facebook/react-native/pull/48619 Test Plan: - Wrapped the the entry app component in `RNTesterAppShared.js` with `StrictMode` and verified that no warnings are shown anymore for the updated components. - Checked the examples are still working as they were. Reviewed By: fabriziocucci Differential Revision: D68094402 Pulled By: rshest fbshipit-source-id: e13878cb290735095afaef3d0377fd6dab33c380
52 lines
1.6 KiB
JavaScript
52 lines
1.6 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.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
import React, {useEffect, useState} from 'react';
|
|
import {TextInput, View} from 'react-native';
|
|
|
|
function TextInputKeyProp() {
|
|
const [startKey, setStartKey] = useState(0);
|
|
|
|
useEffect(() => {
|
|
const interval = setInterval(() => setStartKey(startKey + 100), 3000);
|
|
return () => clearInterval(interval);
|
|
}, [startKey]);
|
|
|
|
const textInputs = [];
|
|
for (let i = 0; i < 101; i++) {
|
|
const key = (startKey + i).toString();
|
|
console.log('Adding a TextInput with key ' + key);
|
|
textInputs.push(
|
|
<TextInput
|
|
style={{height: 40, borderColor: 'gray', borderWidth: 1}}
|
|
key={key}
|
|
/>,
|
|
);
|
|
}
|
|
|
|
return <View>{textInputs}</View>;
|
|
}
|
|
|
|
exports.title = 'TextInputs with key prop';
|
|
exports.description =
|
|
'Periodically render large number of TextInputs with key prop without a Runtime Error';
|
|
exports.examples = [
|
|
{
|
|
title: 'Long List of TextInputs with key props',
|
|
description:
|
|
'100 TextInputs are added every 3 seconds to the View. #29452 avoids a NPE Runtime Error. If you want to trigger the Runtime, change 101 to 1001 in RNTester/TextInputKeyProp.js and use an Emulator with 8GB of RAM. This example is only meant to verify no RuntimeError is triggered. To test TextInput functionalities use the <TextInput> example.',
|
|
render: function (): React.Node {
|
|
return <TextInputKeyProp />;
|
|
},
|
|
},
|
|
];
|