Skip to content

Commit fa5bcc6

Browse files
esquevinmattgperry
authored andcommitted
Move all children in <Transition /> (#683)
Fixes #682
1 parent b993b9d commit fa5bcc6

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

packages/react-pose/src/_tests/index.test.tsx

+38
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,44 @@ test('PoseGroup: Animate conditionally', () => {
321321
});
322322
});
323323

324+
test('PoseGroup: All remaining children have a flip transition when one is removed', () => {
325+
const items = [1, 2, 3, 4, 5, 6];
326+
let nbEnterPoseCompleted = 0;
327+
let flipTransitions = [];
328+
return new Promise(resolve => {
329+
const Group = ({ items }) => (
330+
<PoseGroup>
331+
{items.map((item, i) => (
332+
<Parent
333+
key={item}
334+
onPoseComplete={poses => {
335+
if (poses.includes('enter')) {
336+
flipTransitions[i] = poses.includes('flip');
337+
nbEnterPoseCompleted += 1;
338+
if (nbEnterPoseCompleted === items.length) {
339+
expect(flipTransitions).toEqual([
340+
true,
341+
true,
342+
true,
343+
true,
344+
true
345+
]);
346+
resolve();
347+
}
348+
}
349+
}}
350+
/>
351+
))}
352+
</PoseGroup>
353+
);
354+
355+
const { rerender } = render(<Group items={items} />);
356+
expect(flipTransitions).toEqual([]);
357+
358+
rerender(<Group items={[...items.slice(0, 2), ...items.slice(3)]} />);
359+
});
360+
});
361+
324362
test('PoseGroup: Forward props from PoseGroup to direct child', () => {
325363
let x = 0;
326364
let y = 0;

packages/react-pose/src/components/Transition/children.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,8 @@ const handleTransition = (
9595

9696
const moving = new Set(
9797
prevKeys.filter((key, i) => {
98-
if (entering.has(key)) {
99-
return false;
100-
}
101-
102-
const nextIndex = nextKeys.indexOf(key);
103-
return nextIndex !== -1 && i !== nextIndex;
98+
// if it's not entering or leaving
99+
return !entering.has(key) || leaving.indexOf(key) === -1;
104100
})
105101
);
106102

0 commit comments

Comments
 (0)