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

toggle reverse on useTransitions #1896

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions demo/src/sandboxes/chain/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default function App() {
from: { opacity: 0, scale: 0 },
enter: { opacity: 1, scale: 1 },
leave: { opacity: 0, scale: 0 },
toggleReverse: !open
})

// This will orchestrate the two animations above, comment the last arg and it creates a sequence
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/hooks/useTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export function useTransition(
expires = true,
exitBeforeEnter = false,
onDestroyed,
toggleReverse = false,
ref: propsRef,
config: propsConfig,
}: UseTransitionProps<any> = propsFn ? propsFn() : props
Expand Down Expand Up @@ -206,6 +207,11 @@ export function useTransition(
const exitingTransitions = useRef(new Map<TransitionState, Change>())

const forceChange = useRef(false)

if (toggleReverse) {
transitions.reverse()
}

each(transitions, (t, i) => {
const key = t.key
const prevPhase = t.phase
Expand Down Expand Up @@ -425,9 +431,9 @@ export function useTransition(
reset ? void 0 : deps
)

const renderTransitions: TransitionFn = render => (
const renderTransitions: TransitionFn = (render) => (
<>
{transitions.map((t, i) => {
{(toggleReverse ? transitions.reverse() : transitions).map((t, i) => {
const { springs } = changes.get(t) || t.ctrl
const elem: any = render({ ...springs }, t.item, t, i)
return elem && elem.type ? (
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export type UseTransitionProps<Item = any> = Merge<
leave?: TransitionTo<Item>
keys?: ItemKeys<Item>
sort?: (a: Item, b: Item) => number
toggleReverse?: boolean
trail?: number
exitBeforeEnter?: boolean
/**
Expand Down