-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Web LA] Custom
Keyframe
animations (#6135)
## Summary This PR adds support for custom layout animations created via `Keyframe` on web. > [!IMPORTANT] > This PR replaces #5277 ## Test plan Tested on example app and the following code snippet: <details> <summary> Test code </summary> ```jsx import { StyleSheet, View, Text, Pressable } from 'react-native'; import React, { useState } from 'react'; import Animated, { Easing, Keyframe } from 'react-native-reanimated'; const entering = new Keyframe({ 0: { transform: [ { translateX: -500 }, { translateY: -300 }, { scale: 1.25 }, { skewY: '25deg' }, ], opacity: 0.3, easing: Easing.cubic, }, 70: { transform: [{ translateX: 250 }, { translateY: 100 }, { scale: 1.25 }], opacity: 0.7, }, }); const exiting = new Keyframe({ 0: { easing: Easing.exp, }, 100: { transform: [ { translateX: 700 }, { translateY: 250 }, { scale: 0.3 }, { rotate: '225deg' }, ], opacity: 0, }, }); export default function EmptyExample() { const [show, setShow] = useState(true); return ( <View style={styles.container}> {show && ( <Animated.View entering={entering.duration(1000)} exiting={exiting} style={styles.box} /> )} <Pressable onPress={() => setShow((prev) => !prev)} style={styles.button}> <Text style={{ color: 'white' }}> Click me! </Text> </Pressable> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, box: { width: 250, height: 250, backgroundColor: '#782aeb', }, button: { width: 100, height: 50, backgroundColor: '#57b495', display: 'flex', alignItems: 'center', justifyContent: 'space-around', borderRadius: 15, position: 'absolute', top: 10, left: 10, }, }); ``` </details>
- Loading branch information
Showing
9 changed files
with
208 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/react-native-reanimated/src/layoutReanimation/web/Easing.web.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// Those are the easings that can be implemented using Bezier curves. | ||
// Others should be done as CSS animations | ||
export const WebEasings = { | ||
linear: [0, 0, 1, 1], | ||
ease: [0.42, 0, 1, 1], | ||
quad: [0.11, 0, 0.5, 0], | ||
cubic: [0.32, 0, 0.67, 0], | ||
sin: [0.12, 0, 0.39, 0], | ||
circle: [0.55, 0, 1, 0.45], | ||
exp: [0.7, 0, 0.84, 0], | ||
}; | ||
|
||
export type WebEasingsNames = keyof typeof WebEasings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.