Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test Layout Transition with size change #6178

Merged
merged 9 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import './tests/layoutAnimations/entering/predefinedEntering.test';

import './tests/layoutAnimations/exiting/predefinedExiting.test';

import './tests/layoutAnimations/layout/predefinedLayoutPosition.test';
import './tests/layoutAnimations/layout/positionAndSize.test';
import './tests/layoutAnimations/layout/entryExitTransition.test';

import './tests/advancedAPI/useFrameCallback.test';
// import './tests/advancedAPI/measure.test'; crash on Android

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const EXITING_SETS: Array<[string, unknown[], number]> = [
['Zoom', ZOOM_EXITING, 1800],
];

const ExitingOnMountComponent = ({ exiting }: { exiting: any }) => {
const ExitingComponent = ({ exiting }: { exiting: any }) => {
const [show, setShow] = useState(true);
useEffect(() => {
setShow(false);
Expand All @@ -104,7 +104,7 @@ async function getSnapshotUpdates(exiting: any, waitTime: number, duration: numb
const springExiting = springify ? exiting : exiting.springify();
const componentExiting = duration ? springExiting.duration(duration) : springExiting;

await render(<ExitingOnMountComponent exiting={componentExiting} />);
await render(<ExitingComponent exiting={componentExiting} />);

await wait(waitTime);
const updates = updatesContainer.getUpdates();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import React, { useState, useEffect } from 'react';
import { View, StyleSheet } from 'react-native';
import Animated from 'react-native-reanimated';
import { useTestRef } from '../../../ReanimatedRuntimeTestsRunner/RuntimeTestsApi';

export const TRANSITION_REF = 'TRANSITION_REF';
export enum Direction {
UP = 'UP',
DOWN = 'DOWN',
LEFT = 'LEFT',
RIGHT = 'RIGHT',
RIGHT_UP = 'RIGHT_UP',
LEFT_UP = 'LEFT_UP',
}

export const TransitionUpOrDown = ({
layout,
direction,
changeSize,
}: {
layout: any;
direction: Direction;
changeSize?: boolean;
}) => {
const [show, setShow] = useState(true);
const ref = useTestRef(TRANSITION_REF);

useEffect(() => {
setShow(false);
}, [setShow]);

return (
<View style={styles.containerVertical}>
{direction === Direction.UP && (
<>
{show && <Animated.View layout={layout} style={styles.animatedBox} />}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
{direction === Direction.DOWN && (
<>
{!show && <Animated.View layout={layout} style={styles.animatedBox} />}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
</View>
);
};

export const TransitionLeftOrRight = ({
layout,
direction,
changeSize,
}: {
layout: any;
direction: Direction;
changeSize?: boolean;
}) => {
const [show, setShow] = useState(true);
const ref = useTestRef(TRANSITION_REF);

useEffect(() => {
setShow(false);
}, [setShow]);

return (
<View style={styles.containerHorizontal}>
{direction === Direction.LEFT && (
<>
{show && <Animated.View layout={layout} style={styles.animatedBox} />}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
{direction === Direction.RIGHT && (
<>
{!show && <Animated.View layout={layout} style={styles.animatedBox} />}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
{direction === Direction.RIGHT_UP && (
<>
{show && <Animated.View layout={layout} style={styles.animatedBox} />}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
{direction === Direction.LEFT_UP && (
<>
{show && (
<>
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
</>
)}
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View layout={layout} style={styles.animatedBox} />
<Animated.View
ref={ref}
layout={layout}
style={[styles.animatedBox, styles.mainBox, changeSize && !show ? styles.bigBox : {}]}
/>
</>
)}
</View>
);
};

const styles = StyleSheet.create({
containerVertical: {
flex: 1,
flexDirection: 'column',
margin: 5,
width: 250,
},
containerHorizontal: {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'center',
margin: 5,
width: 250,
},
animatedBox: {
backgroundColor: 'royalblue',
width: 100,
height: 100,
margin: 5,
},
mainBox: { backgroundColor: 'darkorange' },
bigBox: {
width: 150,
height: 200,
},
});
Loading
Loading