question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Box shadow animated

See original GitHub issue

Description

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: image

After scroll: image

Package versions

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
karol-bisztygacommented, Oct 2, 2020

This has been closed automatically with iOS solution being merged. @VictorPullzz if the problem persists, please reopen.

0reactions
charles-goodecommented, Apr 26, 2021

I was getting TypeError: Attempting to define property on object that is not extensible when merging styles like style={[{/*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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found