Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions packages/rn-tester/js/examples/Playground/RNTesterPlayground.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,73 @@ 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 {Pressable, StyleSheet, View} from 'react-native';

// Repro for a recycled RCTViewComponentView keeping its custom container (iOS).
// Tap four times:
// 1. unmounts a view with overflow: 'hidden' + boxShadow; its native view is recycled.
// 2. mounts the bordered view, which dequeues that recycled view and mounts its
// children through the stale container.
// 3. replaces the second child: it lands BEHIND the first (green square hidden).
// 4. replaces it again; removing the old one asserts in debug builds:
// "Attempt to unmount a view which has a different index".
// Without the boxShadow on the first view, all four steps behave correctly.
function Playground() {
const [step, setStep] = useState(0);
return (
<View style={styles.container}>
<RNTesterText>
Edit "RNTesterPlayground.js" to change this file
</RNTesterText>
<Pressable onPress={() => setStep(s => s + 1)} style={styles.button}>
<RNTesterText>{`Step ${step}: tap to advance`}</RNTesterText>
</Pressable>
{step === 0 && <View style={styles.shadowClip} />}
{step >= 2 && (
<View collapsable={false} style={styles.bordered}>
<View style={styles.back} />
<View key={step} style={styles.front} />
</View>
)}
</View>
);
}

const styles = StyleSheet.create({
container: {
padding: 10,
gap: 24,
},
button: {
padding: 12,
backgroundColor: '#ddd',
},
shadowClip: {
width: 120,
height: 120,
overflow: 'hidden',
boxShadow: '0px 4px 12px rgba(0,0,0,0.4)',
backgroundColor: 'white',
},
bordered: {
width: 200,
height: 120,
borderTopWidth: 2,
borderTopColor: 'black',
},
back: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: 'tomato',
},
front: {
position: 'absolute',
top: 20,
left: 20,
width: 80,
height: 80,
backgroundColor: 'seagreen',
},
});

Expand Down