Box shadow animated
See original GitHub issueDescription
Hi guys! I was trying to make the box shadow appear smoothly when the user scrolls the block. But something doesn’t work, tell me what is the problem?)
Code
....
const [boxShadow, setBoxShadow] = useState<boolean>(false);
const scrollHandler = useAnimatedScrollHandler((event) => {
console.log(event.contentOffset.y)
setBoxShadow(event.contentOffset.y > 10);
});
const styleTopBox = useAnimatedStyle(() => {
if (boxShadow) {
return {
...Platform.select({
ios: {
shadowColor: theme.colors.colorBoxShadow,
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.27,
shadowRadius: 4.65,
},
android: {
elevation: 10,
}
})
}
}
return {};
});
<Animated.View
style={{
backgroundColor: '#000'
...styleTopBox
}}
>
...
</Animated.View>
Before scroll:
After scroll:
Package versions
- React: 16.13.1
- React Native: https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz
- React Native Reanimated: ^2.0.0-alpha.6
Issue Analytics
- State:
- Created 3 years ago
- Comments:14 (6 by maintainers)
Top Results From Across the Web
How to animate box-shadow with silky smooth performance
Animating a change of box-shadow will hurt performance. There's an easy way of mimicking the same effect, however, with minimal re-paints, ...
Read more >How to Animate CSS Box Shadows and Optimize ...
In CSS, the box-shadow property is used to add shadows to web elements, and these shadows can be animated. However, shadow animations can ......
Read more >Animation of box-shadow - W3Schools Tryit Editor
animation : mymove 5s infinite; } @keyframes mymove { 50% {box-shadow: 10px 20px 30px blue;} } </style> </head> <body> <h1>Animation of...
Read more >Stop animating box-shadows the wrong way! - YouTube
You can animate and transition just about anything with CSS, but that doesn't mean that it's a good idea to do it. Shadows...
Read more >Live Demo: Example of CSS3 box-shadow Property Animation
Note: The box-shadow property of the following DIV element is animating from its initial value "none" to "8px 8px 16px #999", and back...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This has been closed automatically with iOS solution being merged. @VictorPullzz if the problem persists, please reopen.
I was getting
TypeError: Attempting to define property on object that is not extensible
when merging styles likestyle={[{/*other styles */ shadowOffset: {width: 0, height: 0 }}, animateStyle]}
where the animatedStyle was animating shadowRadius. It was fixed by moving the static definition of shadowOffset into the animatedStyle. Pretty weird and the error message wasn’t helpful. I got it through process of elimination.