Skip to content

Commit

Permalink
Move all children in <Transition /> (#683)
Browse files Browse the repository at this point in the history
Fixes #682
  • Loading branch information
esquevin authored and mattgperry committed Jan 8, 2019
1 parent b993b9d commit fa5bcc6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
38 changes: 38 additions & 0 deletions packages/react-pose/src/_tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,44 @@ test('PoseGroup: Animate conditionally', () => {
});
});

test('PoseGroup: All remaining children have a flip transition when one is removed', () => {
const items = [1, 2, 3, 4, 5, 6];
let nbEnterPoseCompleted = 0;
let flipTransitions = [];
return new Promise(resolve => {
const Group = ({ items }) => (
<PoseGroup>
{items.map((item, i) => (
<Parent
key={item}
onPoseComplete={poses => {
if (poses.includes('enter')) {
flipTransitions[i] = poses.includes('flip');
nbEnterPoseCompleted += 1;
if (nbEnterPoseCompleted === items.length) {
expect(flipTransitions).toEqual([
true,
true,
true,
true,
true
]);
resolve();
}
}
}}
/>
))}
</PoseGroup>
);

const { rerender } = render(<Group items={items} />);
expect(flipTransitions).toEqual([]);

rerender(<Group items={[...items.slice(0, 2), ...items.slice(3)]} />);
});
});

test('PoseGroup: Forward props from PoseGroup to direct child', () => {
let x = 0;
let y = 0;
Expand Down
8 changes: 2 additions & 6 deletions packages/react-pose/src/components/Transition/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,8 @@ const handleTransition = (

const moving = new Set(
prevKeys.filter((key, i) => {
if (entering.has(key)) {
return false;
}

const nextIndex = nextKeys.indexOf(key);
return nextIndex !== -1 && i !== nextIndex;
// if it's not entering or leaving
return !entering.has(key) || leaving.indexOf(key) === -1;
})
);

Expand Down

0 comments on commit fa5bcc6

Please sign in to comment.