-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Milestone
Description
Problem Description
When running an Animated API animation that uses an Animated.Value after calling setOffset on the value, the NativeAnimated animation does not match the experience for JS-driven animations. The root cause of this is likely because the current implementation of NativeAnimated seems to re-purpose the ValueAnimatedNode::Offset property to run the animation.
This is inconsistent with how the Animated API is supposed to work. Offsets in the Animated API are just a way to shift the animation, and the only time the offset values should change are when calling setOffset, flattenOffset, or extractOffset.
Steps To Reproduce
- Add an example to RNTester that calls
setOffseton a value animated node, e.g.:
class Tester extends React.Component<$FlowFixMeProps, $FlowFixMeState> {
state = {
native: new Animated.Value(0),
js: new Animated.Value(0),
};
current = 0;
stopped = 1;
onPress = () => {
const animConfig =
this.current && this.props.reverseConfig
? this.props.reverseConfig
: this.props.config;
this.current = this.current ? 0 : 1;
const config: Object = {
...animConfig,
toValue: this.current,
};
/* Added code for example purposes */
this.state.native.setOffset(0.5);
this.state.js.setOffset(0.5);
/* End example code */
Animated[this.props.type](this.state.native, {
...config,
useNativeDriver: true,
}).start();
Animated[this.props.type](this.state.js, {
...config,
useNativeDriver: false,
}).start();
};
render() {
return (
<TouchableWithoutFeedback onPress={this.onPress}>
<View>
<View>
<Text>Native:</Text>
</View>
<View style={styles.row}>
{this.props.children(this.state.native)}
</View>
<View>
<Text>JavaScript{':'}</Text>
</View>
<View style={styles.row}>{this.props.children(this.state.js)}</View>
</View>
</TouchableWithoutFeedback>
);
}
}- Run the examples in RNTester > Native Animated Example
- The animation should be offset (as if it animates from 0.5 -> 1.5, rather than 0 -> 1)
- NativeAnimated appears to still run the animation from 0 to 1.
Expected Results
The NativeAnimated animation should match the JS-driven animation.
CLI version
npx react-native --version
Environment
npx react-native infoTarget Platform Version
No response
Target Device(s)
No response
Visual Studio Version
No response
Build Configuration
No response