mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
feat: Add id prop to Text, TouchableWithoutFeedback and View components (#34522)
Summary: This adds the `id` prop to `Text`, `TouchableWithoutFeedback` and `View` components as requested on https://github.com/facebook/react-native/issues/34424 mapping the existing `nativeID` prop to `id`. As this components are inherited by others this also adds the `id` prop support to `Image`, `TouchableBounce`, `TouchableHighlight`, `TouchableOpacity` and `TextInput`. This PR also adds android tests ensuring that the `id` property is passed to the native view via the `nativeID` prop, these tests were based on the existing `nativeID` tests ([NativeIdTestCase.java](https://github.com/facebook/react-native/blob/main/ReactAndroid/src/androidTest/java/com/facebook/react/tests/NativeIdTestCase.java)). ## Changelog [General] [Added] - Add id prop to Text, TouchableWithoutFeedback and View components Pull Request resolved: https://github.com/facebook/react-native/pull/34522 Test Plan: Ensure that the new `id` prop android tests pass on CircleCI Reviewed By: lunaleaps Differential Revision: D39089639 Pulled By: cipolleschi fbshipit-source-id: 884fb2461720835ca5048004fa79096dac89c51c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
720cdbc658
commit
3e97d5fe58
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* 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';
|
||||
|
||||
const React = require('react');
|
||||
const TouchableBounce = require('react-native/Libraries/Components/Touchable/TouchableBounce');
|
||||
|
||||
const {
|
||||
Image,
|
||||
StyleSheet,
|
||||
Text,
|
||||
TextInput,
|
||||
TouchableHighlight,
|
||||
TouchableOpacity,
|
||||
TouchableWithoutFeedback,
|
||||
View,
|
||||
} = require('react-native');
|
||||
|
||||
/**
|
||||
* All the views implemented on Android, each with the id property set.
|
||||
* We test that:
|
||||
* - The app renders fine
|
||||
* - The id property is passed to the native views via the nativeID property
|
||||
*/
|
||||
class IdTestApp extends React.Component<{...}> {
|
||||
render(): React.Node {
|
||||
const uri =
|
||||
'data:image/gif;base64,' +
|
||||
'R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapy' +
|
||||
'uvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/' +
|
||||
'TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5' +
|
||||
'iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97V' +
|
||||
'riy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7';
|
||||
return (
|
||||
<View>
|
||||
<Image id="Image" source={{uri: uri}} style={styles.base} />
|
||||
<Text id="Text">text</Text>
|
||||
<TextInput id="TextInput" value="Text input" />
|
||||
<TouchableBounce id="TouchableBounce">
|
||||
<Text>TouchableBounce</Text>
|
||||
</TouchableBounce>
|
||||
<TouchableHighlight id="TouchableHighlight">
|
||||
<Text>TouchableHighlight</Text>
|
||||
</TouchableHighlight>
|
||||
<TouchableOpacity id="TouchableOpacity">
|
||||
<Text>TouchableOpacity</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableWithoutFeedback id="TouchableWithoutFeedback">
|
||||
<View>
|
||||
<Text>TouchableWithoutFeedback</Text>
|
||||
</View>
|
||||
</TouchableWithoutFeedback>
|
||||
<View id="View" />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
base: {
|
||||
width: 150,
|
||||
height: 50,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
IdTestApp,
|
||||
};
|
||||
@@ -48,6 +48,10 @@ const apps = [
|
||||
component: () =>
|
||||
require('./ScrollViewTestModule').HorizontalScrollViewTestApp,
|
||||
},
|
||||
{
|
||||
appKey: 'IdTestApp',
|
||||
component: () => require('./IdTestModule').IdTestApp,
|
||||
},
|
||||
{
|
||||
appKey: 'ImageOverlayColorTestApp',
|
||||
component: () => require('./ImageOverlayColorTestApp'),
|
||||
|
||||
Reference in New Issue
Block a user