-
-
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.
Batch update props JSI calls (#4503)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary Fixes #4495. <!-- Explain the motivation for this PR. Include "Fixes #<number>" if applicable. --> ## Test plan <!-- Provide a minimal but complete code snippet that can be used to test out this change along with instructions how to run it and a description of the expected behavior. -->
- Loading branch information
Showing
12 changed files
with
241 additions
and
91 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Animated, { | ||
useAnimatedStyle, | ||
withRepeat, | ||
withTiming, | ||
} from 'react-native-reanimated'; | ||
import { Animated as RNAnimated, View, StyleSheet } from 'react-native'; | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
const N = 1500; | ||
const array = Array(N).fill(0); | ||
|
||
function AnimatedBar() { | ||
const scaleX = useRef(new RNAnimated.Value(1.5)).current; | ||
|
||
useEffect(() => { | ||
RNAnimated.loop( | ||
RNAnimated.timing(scaleX, { | ||
duration: 500, | ||
toValue: Math.random() * 10, | ||
useNativeDriver: true, | ||
}), | ||
{ iterations: -1 } | ||
).start(); | ||
}, [scaleX]); | ||
|
||
return <RNAnimated.View style={[styles.bar, { transform: [{ scaleX }] }]} />; | ||
} | ||
|
||
function ReanimatedBar() { | ||
const style = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ | ||
scaleX: withRepeat( | ||
withTiming(Math.random() * 10, { duration: 500 }), | ||
-1, | ||
true | ||
), | ||
}, | ||
], | ||
}; | ||
}); | ||
|
||
return <Animated.View style={[styles.bar, style]} />; | ||
} | ||
|
||
export default function UpdatePropsPerfExample() { | ||
return ( | ||
<View style={styles.container}> | ||
{false && array.map((_, i) => <AnimatedBar key={i} />)} | ||
{true && array.map((_, i) => <ReanimatedBar key={i} />)} | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
flexDirection: 'column', | ||
}, | ||
bar: { | ||
width: 100, | ||
height: 1, | ||
backgroundColor: 'blue', | ||
}, | ||
}); |
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.