Not able to use Animated to animate the transparency of the header.
See original GitHub issueDescription
I am trying to make the React Navigation header change it’s transparency from 0 to .95 and back to 0 while scrolling up and down. I have followed many different methods to get this working but it does not work with the createNativeStackNavigator, but it does work with createStackNavigator.
I surmise this is because the way it gets handled is adding the opacity to the headerBackground, which does not exist with the Native Stack.
I have also noticed that when scrolling I do not see the change in the headerOpacity value when I try log it in the useEffect hook. It only does it once, and never calls it again.
Code
const headerOpacity = yOffset.interpolate({
inputRange: [0, 200],
outputRange: [0, 1],
extrapolate: "clamp",
});
<Animated.ScrollView
onScroll={Animated.event(
[
{
nativeEvent: {
contentOffset: {
y: yOffset,
},
},
},
],
{ useNativeDriver: true }
)}
scrollEventThrottle={16}
>
useEffect(() => {
navigation.setOptions({
headerStyle: {
opacity: headerOpacity,
},
headerBackground: () => (
<Animated.View
style={{
backgroundColor: "white",
...StyleSheet.absoluteFillObject,
opacity: headerOpacity,
}}
/>
),
headerTransparent: true,
});
}, [headerOpacity, navigation]);
Package versions
- Expo: 38.0.0
- React: 16.11.0
- React Native: 0.63
- React Native Screens: 2.9.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Animate navigation header opacity while scrolling in ...
In my screen, I want to change opacity of navigation header 0 to 1 when I scroll up. Here is code in Snack....
Read more >Change, remove or turn off animation effects - Microsoft Support
On the Animation tab, click Animation Pane. Open the Animation Pane. On the slide, click the animated object that you want to remove...
Read more >What's In A GIF - Animation and Transparency - GifLib
This file is similar to the ones we've previously encountered. The bytes start out with the GIF header.
Read more >Animating from "display: block" to "display: none"
For this reason, animating opacity to zero is simply not enough because an element with zero opacity still occupies the same space on...
Read more >How to Add a CSS Fade-in Transition Animation to Text ...
You can also check out The Main Difference Between CSS Animations & Transitions to ... example of fade in image transition using css...
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
@WoLewicki Sure!
So my stack has one screen like this:
And then in my component:
I am closing it due to no response in more than 30 days and I am not sure if there is something more to be done here. Feel free to comment to reopen it.