Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6426

How to use AnimateStyle with Stylesheet.create

$
0
0

I am using react-native-reanimated to create an Animated.View. I want to add a dynamic style to this Animated.View by changing the scale based on some state. This is my code:

import Animated from 'react-native-reanimated';......const scaleNode = useRef(new Animated.Value(1));const style = useMemo(() => {    return StyleSheet.create({      animated: {transform: [{scale: scaleNode.current}]},    });  }, []);  return (<Animated.View style={[style.animated, containerStyle]}>......

I am using typescript, and while I have figured out that the style definition for the styles that i pass to Animated.View should be Animated.AnimateStyle<ViewStyle>. I am not sure about how to add types to the style that I am defining as a separate variable (which gets created with Stylesheet.create). In the current code, I get a ts error on transform:

Type 'AnimatedValue<1>' is not assignable to type 'number'

Note that if I directly pass the transform style to Animated.View, it does not complain


Viewing all articles
Browse latest Browse all 6426

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>