-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add optional configs to constructors for AnimatedValue/ValueXY/Color
Summary: There are use cases of needing to setValue multiple times per second (for example, using PanResponder to update a slider component). This requires the use of the native driver for perf reasons as using the JS driver will cause a rerender. Currently, the only way to make an animated node native is via setting useNativeDriver: true on an animation config. For example: ``` Animated.timing(animatedValue, { toValue: newValue, duration: 0, useNativeDriver: true }).start(); ``` To avoid needing to call the above, add a useNativeDriver param to the constructor. When set to true, the node will be made native immediately. ``` const animatedValue = new Animated.Value(0, useNativeDriver); ... animatedValue.setValue(newValue); ``` Note that, like with useNativeDriver in the animation config, once a node is made native, it cannot be reverted to JS-only. --- As an aside, PanResponder uses JS-side events, and thus we cannot use Animated.event with native driver; we instead need to setValue on a native AnimatedValue. A much more thorough explanation is in D34564598. --- Changelog: [General][Added] - [Animated] Add useNativeDriver as a param for setValue Reviewed By: JoshuaGross Differential Revision: D36459457 fbshipit-source-id: 284148a6d16537429efeab8b07184019990909cd
- Loading branch information
1 parent
841793a
commit 73191ed
Showing
3 changed files
with
45 additions
and
8 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