diff --git a/packages/rn-tester/js/components/ListExampleShared.js b/packages/rn-tester/js/components/ListExampleShared.js index 7260f2fbd07e66..05fda82f9cdf9f 100644 --- a/packages/rn-tester/js/components/ListExampleShared.js +++ b/packages/rn-tester/js/components/ListExampleShared.js @@ -10,8 +10,9 @@ 'use strict'; -const React = require('react'); -const { +import RNTesterText from './RNTesterText'; +import React from 'react'; +import { ActivityIndicator, Animated, Image, @@ -22,7 +23,7 @@ const { TextInput, TouchableHighlight, View, -} = require('react-native'); +} from 'react-native'; export type Item = { title: string, @@ -260,7 +261,7 @@ function renderSmallSwitchOption( } return ( - {label}: + {label}: { return ( - {label} + {label} ); diff --git a/packages/rn-tester/js/components/RNTesterText.js b/packages/rn-tester/js/components/RNTesterText.js new file mode 100644 index 00000000000000..fc1767c4d0d343 --- /dev/null +++ b/packages/rn-tester/js/components/RNTesterText.js @@ -0,0 +1,22 @@ +/** + * 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 type {TextProps} from 'react-native/Libraries/Text/TextProps'; + +import {RNTesterThemeContext} from './RNTesterTheme'; +import React, {useContext} from 'react'; +import {Text} from 'react-native'; + +export default function RNTesterText(props: TextProps): React$Node { + const {style, ...rest} = props; + const theme = useContext(RNTesterThemeContext); + return ; +} diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js index 08ea74daba6759..f3713f727593e9 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityAndroidExample.js @@ -12,15 +12,9 @@ import RNTesterBlock from '../../components/RNTesterBlock'; import RNTesterPage from '../../components/RNTesterPage'; -import { - Alert, - StyleSheet, - Text, - TouchableWithoutFeedback, - View, -} from 'react-native'; - -const React = require('react'); +import RNTesterText from '../../components/RNTesterText'; +import {Alert, StyleSheet, TouchableWithoutFeedback, View} from 'react-native'; +import React from 'react'; const importantForAccessibilityValues = [ 'auto', @@ -67,27 +61,27 @@ class AccessibilityAndroidExample extends React.Component< return ( - - + + Bacon {this.state.count} Ipsum{'\n'} - - Dolor sit amet{'\n'} - Eggsecetur{'\n'} - {'\n'} - + + Dolor sit amet{'\n'} + Eggsecetur{'\n'} + {'\n'} + http://github.com - - + + - Click me + Click me - Clicked {this.state.count} times + Clicked {this.state.count} times @@ -102,7 +96,7 @@ class AccessibilityAndroidExample extends React.Component< ] }> - Hello + Hello - world + world - + Change importantForAccessibility for background layout. - + - Background layout importantForAccessibility - + + Background layout importantForAccessibility + + { importantForAccessibilityValues[ this.state.backgroundImportantForAcc ] } - + - + Change importantForAccessibility for forground layout. - + - Forground layout importantForAccessibility - + + Forground layout importantForAccessibility + + { importantForAccessibilityValues[ this.state.forgroundImportantForAcc ] } - + - + In the following example, the words "test", "inline links", "another link", and "link that spans multiple lines because the text is so long", should each be independently focusable elements, announced as their content followed by ", Link". - - + + They should be focused in order from top to bottom *after* the contents of the entire paragraph. - - + + Focusing on the paragraph itself should also announce that there are "links available", and opening Talkback's links menu should show these same links. - - + + Clicking on each link, or selecting the link From Talkback's links menu should trigger an alert. - - + + The links that wraps to multiple lines will intentionally only draw a focus outline around the first line, but using the "explore by touch" tap-and-drag gesture should move focus to this link even if the second line is touched. - - + + Using the "Explore by touch" gesture and touching an area that is *not* a link should move focus to the entire paragraph. - - Example - + + Example + This is a{' '} - { Alert.alert('pressed test'); }}> test - {' '} + {' '} of{' '} - { Alert.alert('pressed Inline Links'); }}> inline links - {' '} + {' '} in React Native. Here's{' '} - { Alert.alert('pressed another link'); }}> another link - + . Here is a{' '} - { Alert.alert('pressed long link'); }}> link that spans multiple lines because the text is so long. - + This sentence has no links in it. - + ); @@ -241,6 +239,9 @@ class AccessibilityAndroidExample extends React.Component< } const styles = StyleSheet.create({ + buttonText: { + color: 'black', + }, touchableContainer: { position: 'absolute', left: 10, diff --git a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js index 2848d48c6a4b4e..308ec71e43ba98 100644 --- a/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js +++ b/packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js @@ -13,15 +13,13 @@ import type {PressEvent} from 'react-native/Libraries/Types/CoreEventTypes'; import type {EventSubscription} from 'react-native/Libraries/vendor/emitter/EventEmitter'; -import {RNTesterThemeContext} from '../../components/RNTesterTheme'; - -const RNTesterBlock = require('../../components/RNTesterBlock'); -const checkImageSource = require('./check.png'); -const mixedCheckboxImageSource = require('./mixed.png'); -const uncheckImageSource = require('./uncheck.png'); -const React = require('react'); -const {createRef} = require('react'); -const { +import RNTesterBlock from '../../components/RNTesterBlock'; +import RNTesterText from '../../components/RNTesterText'; +import checkImageSource from './check.png'; +import mixedCheckboxImageSource from './mixed.png'; +import uncheckImageSource from './uncheck.png'; +import React, {createRef} from 'react'; +import { AccessibilityInfo, Alert, Button, @@ -31,13 +29,12 @@ const { ScrollView, StyleSheet, Switch, - Text, TextInput, TouchableNativeFeedback, TouchableOpacity, TouchableWithoutFeedback, View, -} = require('react-native'); +} from 'react-native'; const styles = StyleSheet.create({ sectionContainer: { @@ -106,214 +103,208 @@ const styles = StyleSheet.create({ class AccessibilityExample extends React.Component<{}> { render(): React.Node { return ( - - {theme => ( - - - - Text's accessibilityLabel is the raw text itself unless it is - set explicitly. - - + + + + Text's accessibilityLabel is the raw text itself unless it is set + explicitly. + + - - - This text component's accessibilityLabel is set explicitly. - - + + + This text component's accessibilityLabel is set explicitly. + + - - - This is text one. - This is text two. - - + + + + This is text one. + + + This is text two. + + + - - - This is text one. - This is text two. - - + + + + This is text one. + + + This is text two. + + + - - - This is text one. - This is text two. - - + + + + This is text one. + + + This is text two. + + + - - - - This view's children are hidden from the accessibility tree - - - + + + + This view's children are hidden from the accessibility tree + + + - {/* Android screen readers will say the accessibility hint instead of the text + {/* Android screen readers will say the accessibility hint instead of the text since the view doesn't have a label. */} - - - This is text one. - This is text two. - - + + + + This is text one. + + + This is text two. + + + - - - This is text one. - This is text two. - - + + + + This is text one. + + + This is text two. + + + - - - This is a title. - - + + + This is a title. + + - - - This is a title. - - + + This is a title. + - - Alert.alert('Link has been clicked!')} - accessibilityRole="link"> - - - Click me - - - - + + Alert.alert('Link has been clicked!')} + accessibilityRole="link"> + + Click me + + + - - Alert.alert('Button has been pressed!')} - accessibilityRole="button"> - Click me - - + + Alert.alert('Button has been pressed!')} + accessibilityRole="button"> + Click me + + - - Alert.alert('Button has been pressed!')} - accessibilityRole="button" - accessibilityState={{disabled: true}} - disabled={true}> - - - I am disabled. Clicking me will not trigger any action. - - - - + + Alert.alert('Button has been pressed!')} + accessibilityRole="button" + accessibilityState={{disabled: true}} + disabled={true}> + + + I am disabled. Clicking me will not trigger any action. + + + + - - Alert.alert('Disabled Button has been pressed!')} - accessibilityLabel={ - 'You are pressing Disabled TouchableOpacity' - } - accessibilityState={{disabled: true}}> - - - I am disabled. Clicking me will not trigger any action. - - - - - - - - This view is selected and disabled. - - - + + Alert.alert('Disabled Button has been pressed!')} + accessibilityLabel={'You are pressing Disabled TouchableOpacity'} + accessibilityState={{disabled: true}}> + + + I am disabled. Clicking me will not trigger any action. + + + + + + + This view is selected and disabled. + + - - - - Accessible view with label, hint, role, and state - - - + + + + Accessible view with label, hint, role, and state + + + - - - - Accessible view with label, hint, role, and state - - - + + + + Accessible view with label, hint, role, and state + + + - - - - Mail Address - - - - First Name - - - - - - - - Enable Notifications - - - - + + + Mail Address + + First Name + - )} - + + + + + Enable Notifications + + + + + ); } } @@ -321,170 +312,138 @@ class AccessibilityExample extends React.Component<{}> { class AutomaticContentGrouping extends React.Component<{}> { render(): React.Node { return ( - - {theme => ( - - - - - - Text number 1 with a role - - - Text number 2 - - - - - - - { - switch (event.nativeEvent.actionName) { - case 'cut': - Alert.alert('Alert', 'cut action success'); - break; - case 'copy': - Alert.alert('Alert', 'copy action success'); - break; - case 'paste': - Alert.alert('Alert', 'paste action success'); - break; - } - }} - accessibilityRole="button"> - - - Text number 1 - - - Text number 2Text number 3 - - - - + + + + + + Text number 1 with a role + + Text number 2 + + + - - - - Text number 1 - - - - + + { + switch (event.nativeEvent.actionName) { + case 'cut': + Alert.alert('Alert', 'cut action success'); + break; + case 'copy': + Alert.alert('Alert', 'copy action success'); + break; + case 'paste': + Alert.alert('Alert', 'paste action success'); + break; + } + }} + accessibilityRole="button"> + + Text number 1 + + Text number 2 + Text number 3 + + + + - - - - - Text number 1 - - console.warn('onPress child')} - accessible={false} - accessibilityLabel="this is my label" - accessibilityRole="image" - accessibilityState={{disabled: true}} - accessibilityValue={{ - text: 'this is the accessibility value', - }}> - - Text number 3 - - - - - + + + + Text number 1 + + + + - + + + + Text number 1 - + focusable={true} + onPress={() => console.warn('onPress child')} + accessible={false} + accessibilityLabel="this is my label" + accessibilityRole="image" + accessibilityState={{disabled: true}} + accessibilityValue={{ + text: 'this is the accessibility value', + }}> + Text number 3 - + + + - - - - Text number 2 - - Text number 3Text number 4 - - - - + + + + + - - console.warn('onPress child')} - accessible={true} - accessibilityRole="button"> - - - - - + + + + Text number 2 + + Text number 3 + Text number 4 + + + + - - - - - + + console.warn('onPress child')} + accessible={true} + accessibilityRole="button"> + + + + + + + + + - )} - + + ); } } @@ -516,20 +475,14 @@ class CheckboxExample extends React.Component< render(): React.Node { return ( - - {theme => ( - - - Checkbox example - - - )} - + + Checkbox example + ); } } @@ -554,20 +507,14 @@ class SwitchExample extends React.Component< render(): React.Node { return ( - - {theme => ( - - - Switch example - - - )} - + + Switch example + ); } } @@ -626,9 +573,9 @@ class SelectionExample extends React.Component< }} style={styles.touchable} accessibilityHint={accessibilityHint}> - + {`Selectable TouchableOpacity Example ${touchableHint}`} - + - {theme => ( - - - Expandable element example - - - )} - + + Expandable element example + ); } } @@ -756,59 +697,55 @@ class NestedCheckBox extends React.Component< render(): React.Node { return ( - - {theme => ( - - - - Meat - - - - Beef - - - - Bacon - - - )} - + + + + Meat + + + + Beef + + + + Bacon + + ); } } @@ -816,220 +753,168 @@ class NestedCheckBox extends React.Component< class AccessibilityRoleAndStateExample extends React.Component<{}> { render(): React.Node { const content = [ - This is some text, - This is some text, - This is some text, - This is some text, - This is some text, - This is some text, - This is some text, + This is some text, + This is some text, + This is some text, + This is some text, + This is some text, + This is some text, + This is some text, ]; return ( - - {theme => ( - - - - - {content} - - - - - - - {content} - - - - - - - {content} - - - - - - - - Alert example - - - - - - Combobox example - - - - - Menu example - - - - - Menu bar example - - - - - Menu item example - - - - - Progress bar example - - - - - Radio button example - - - - - Radio group example - - - - - Scrollbar example - - - - - Spin button example - - - - - - Tab example - - - - - Tab list example - - - - - Timer example - - - - - Toolbar example - - - - - State busy example - - - - - Drop Down List example - - - - - Pager example - - - - - Toggle Button example - - - - - Viewgroup example - - - - - Webview example - - - - - - Nested checkbox with delayed state change - - - - + + + + {content} + + + + + {content} + + + + + {content} + + + + + + Alert example + + + + Combobox example + + + Menu example + + + Menu bar example + + + Menu item example + + + Progress bar example + + + Radio button example + + + Radio group example + + + Scrollbar example + + + Spin button example + + + + Tab example + + + Tab list example + + + Timer example + + + Toolbar example + + + State busy example + + + Drop Down List example + + + Pager example + + + Toggle Button example + + + Viewgroup example + + + Webview example + + + + + Nested checkbox with delayed state change + + - )} - + + ); } } @@ -1037,150 +922,138 @@ class AccessibilityRoleAndStateExample extends React.Component<{}> { class AccessibilityActionsExample extends React.Component<{}> { render(): React.Node { return ( - - {theme => ( - - - { - switch (event.nativeEvent.actionName) { - case 'activate': - Alert.alert('Alert', 'View is clicked'); - break; - } - }}> - Click me - - + + + { + switch (event.nativeEvent.actionName) { + case 'activate': + Alert.alert('Alert', 'View is clicked'); + break; + } + }}> + Click me + + - - { - switch (event.nativeEvent.actionName) { - case 'cut': - Alert.alert('Alert', 'cut action success'); - break; - case 'copy': - Alert.alert('Alert', 'copy action success'); - break; - case 'paste': - Alert.alert('Alert', 'paste action success'); - break; - } - }}> - - This view supports many actions. - - - + + { + switch (event.nativeEvent.actionName) { + case 'cut': + Alert.alert('Alert', 'cut action success'); + break; + case 'copy': + Alert.alert('Alert', 'copy action success'); + break; + case 'paste': + Alert.alert('Alert', 'paste action success'); + break; + } + }}> + This view supports many actions. + + - - { - switch (event.nativeEvent.actionName) { - case 'increment': - Alert.alert('Alert', 'increment action success'); - break; - case 'decrement': - Alert.alert('Alert', 'decrement action success'); - break; - } - }}> - Slider - - + + { + switch (event.nativeEvent.actionName) { + case 'increment': + Alert.alert('Alert', 'increment action success'); + break; + case 'decrement': + Alert.alert('Alert', 'decrement action success'); + break; + } + }}> + Slider + + - - { - switch (event.nativeEvent.actionName) { - case 'cut': - Alert.alert('Alert', 'cut action success'); - break; - case 'copy': - Alert.alert('Alert', 'copy action success'); - break; - case 'paste': - Alert.alert('Alert', 'paste action success'); - break; - } - }} - onPress={() => Alert.alert('Button has been pressed!')} - accessibilityRole="button"> - - - Click me - - - - + + { + switch (event.nativeEvent.actionName) { + case 'cut': + Alert.alert('Alert', 'cut action success'); + break; + case 'copy': + Alert.alert('Alert', 'copy action success'); + break; + case 'paste': + Alert.alert('Alert', 'paste action success'); + break; + } + }} + onPress={() => Alert.alert('Button has been pressed!')} + accessibilityRole="button"> + + Click me + + + - -