Skip to content

[Web LA] Add EntryExitTransition#6232

Merged
m-bert merged 19 commits intomainfrom
@mbert/add-entry-exit-transition
Jul 16, 2024
Merged

[Web LA] Add EntryExitTransition#6232
m-bert merged 19 commits intomainfrom
@mbert/add-entry-exit-transition

Conversation

@m-bert
Copy link
Copy Markdown
Contributor

@m-bert m-bert commented Jul 8, 2024

Summary

This PR adds EntryExitTransition to set of transitions available on web.

This transition is different from others, therefore logic behind its creation is also different.

Two animations

First approach was to run 2 animations - exiting and entering. While it seemed like an easier approach, there were few problems:

  • It lead to many code duplications (especially when starting animation, handling end/cancel)
  • I couldn't find a way to keep elements in good positions (transform was overriden by animations and we need to use it to put element back in its starting position)

While I haven't observed any flickers caused by having 2 animations, arguments above made me try seconds approach)

Dynamic keyframe

Second approach to this problem involves creating dynamic keyframe animation - just like in case of other transitions. First we obtain data of both exiting and entering animations. Then we perform two operations:

  1. We add calculated transform into exiting animation (unshift is used to make sure that it will be placed at the beginning of keyframe timestamps
  2. We merge two animations object into one keyframe data object.

In 2. we have to make sure that both animations will fit in one keyframe, therefore exiting animation is squeezed into interval [0,49] and entering animation runs from 50 to 100.

Examples

Nagranie.z.ekranu.2024-07-8.o.14.28.38.mov
Nagranie.z.ekranu.2024-07-8.o.14.42.40.mov

Test plan

Verified on DefaultLayoutTransitions example.

@m-bert m-bert marked this pull request as ready for review July 8, 2024 12:43
@m-bert m-bert requested a review from piaskowyk July 8, 2024 12:43
@m-bert m-bert requested a review from piaskowyk July 16, 2024 09:02
r0h0gg6 pushed a commit to r0h0gg6/react-native-reanimated that referenced this pull request Jul 28, 2025
## Summary

This PR adds `EntryExitTransition` to set of transitions available on
`web`.

This transition is different from others, therefore logic behind its
creation is also different.

### Two animations

First approach was to run 2 animations - `exiting` and `entering`. While
it seemed like an easier approach, there were few problems:

- It lead to many code duplications (especially when starting animation,
handling `end`/`cancel`)
- I couldn't find a way to keep elements in good positions (`transform`
was overriden by animations and we need to use it to put element back in
its starting position)

While I haven't observed any flickers caused by having 2 animations,
arguments above made me try seconds approach)

### Dynamic keyframe

Second approach to this problem involves creating dynamic keyframe
animation - just like in case of other transitions. First we obtain data
of both `exiting` and `entering` animations. Then we perform two
operations:

1. We add calculated transform into `exiting` animation (`unshift` is
used to make sure that it will be placed at the beginning of keyframe
timestamps
2. We merge two animations object into one keyframe data object. 

In 2. we have to make sure that both animations will fit in one
keyframe, therefore `exiting` animation is squeezed into interval
`[0,49]` and `entering` animation runs from `50` to `100`.

### Examples


https://github.com/software-mansion/react-native-reanimated/assets/63123542/6ee7fcfe-4ebd-41cf-bc33-9ab7d262b20b


https://github.com/software-mansion/react-native-reanimated/assets/63123542/a9d15f48-c158-461b-8343-33c6d20ae5bd

## Test plan

Verified on `DefaultLayoutTransitions` example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants