diff --git a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js index 9dbacb997019..ecd867022751 100644 --- a/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js +++ b/packages/rn-tester/js/examples/Playground/RNTesterPlayground.js @@ -6,34 +6,157 @@ * * @flow strict-local * @format - * @oncall react_native */ - import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; -import RNTesterText from '../../components/RNTesterText'; import * as React from 'react'; -import {StyleSheet, View} from 'react-native'; +import {useState} from 'react'; +import {Modal, Pressable, StyleSheet, Text, View} from 'react-native'; + +function causeJSThreadBlocking() { + const intervalId = setInterval(() => { + const start = Date.now(); + while (Date.now() - start < 20) { + // Blocking operation + Math.random() * Math.random(); + } + }, 16); + setTimeout(() => { + clearInterval(intervalId); + }, 10000); +} + +function ModalInSequence(): React.Node { + const [firstModalVisible, setFirstModalVisible] = useState(false); + const [secondModalVisible, setSecondModalVisible] = useState(false); + + const showSecondHideFirst = () => { + setFirstModalVisible(false); + setSecondModalVisible(true); + }; -function Playground() { return ( - - Edit "RNTesterPlayground.js" to change this file - + setFirstModalVisible(false)}> + { + causeJSThreadBlocking(); + console.log('modal first', e.nativeEvent.layout); + }} + style={[styles.centeredView, styles.modalBackdrop]}> + + This is the first modal + { + // await new Promise(resolve => setTimeout(resolve, 100)); + setFirstModalVisible(false); + }}> + Close Modal + + + Show Second Modal + + + + + + setSecondModalVisible(false)}> + { + console.log('modal second', e.nativeEvent.layout); + }} + style={[styles.centeredView, styles.modalBackdrop]}> + + This is the second modal + setSecondModalVisible(false)}> + Close Modal + + + + + + setFirstModalVisible(true)}> + Show First Modal + ); } const styles = StyleSheet.create({ container: { + display: 'flex', + alignItems: 'center', + paddingVertical: 30, + }, + centeredView: { + flex: 1, + justifyContent: 'center', + alignItems: 'center', + }, + modalBackdrop: { + backgroundColor: 'rgba(0, 0, 0, 0.5)', + }, + modalView: { + backgroundColor: 'white', + margin: 20, + borderRadius: 20, + padding: 35, + alignItems: 'center', + shadowColor: '#000', + shadowOffset: { + width: 0, + height: 2, + }, + shadowOpacity: 0.25, + shadowRadius: 4, + elevation: 5, + }, + modalText: { + marginBottom: 15, + textAlign: 'center', + }, + button: { + borderRadius: 20, padding: 10, + marginVertical: 10, + elevation: 2, + minWidth: 150, + }, + buttonOpen: { + backgroundColor: '#F194FF', + }, + buttonClose: { + backgroundColor: '#2196F3', + }, + textStyle: { + color: 'white', + fontWeight: 'bold', + textAlign: 'center', }, }); + export default ({ title: 'Playground', name: 'playground', description: 'Test out new features and ideas.', - render: (): React.Node => , + render: (): React.Node => , }: RNTesterModuleExample); +