-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animate StatusBar background color #20663
Merged
Merged
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
27536ec
Extract constant for SETTINGS.ROOT screen
roryabraham be225ff
Add theme color for SETTINGS_ROOT background color
roryabraham 1e5cb78
Add StatusBar animation for opening settings page
roryabraham f855656
Pass screenListeners down correctly
roryabraham 273e7e1
Move animation from AuthScreens to NavigationRoot
roryabraham a71d414
Implement correct background color, for homepage instead of settings …
roryabraham 5410e5a
Remove all unrelated / unecessary changes
roryabraham 9359c8a
Remove unused import
roryabraham e3d854c
useWindowDimensions instead of withWindowDimensions
roryabraham b7b58ed
Move useWindowDimensions declaration
roryabraham 62c3279
Fix lint
roryabraham 5a0c26a
Implement with Reanimated instead
roryabraham fd869f0
Merge branch 'main' into Rory-AnimateHeaderBackgroundColor
roryabraham 8bed0d2
Use a hook instead of a HOC to fix propTypes
roryabraham c6d1530
Merge branch 'main' into Rory-AnimateHeaderBackgroundColor
roryabraham 2ffa6fa
Add back exported context
roryabraham 5f33be8
Fix Reanimated error
roryabraham 23766ca
Merge branch 'main' into Rory-AnimateHeaderBackgroundColor
roryabraham b4a3cb0
fix warnings and resolve conflicts correctly
roryabraham bfd0cdf
Fix typo
roryabraham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {useContext} from 'react'; | ||
import {CurrentReportIdContext} from '../components/withCurrentReportId'; | ||
|
||
export default function useCurrentReportID() { | ||
return useContext(CurrentReportIdContext); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,15 @@ import React, {useRef} from 'react'; | |
import PropTypes from 'prop-types'; | ||
import {NavigationContainer, DefaultTheme, getPathFromState} from '@react-navigation/native'; | ||
import {useFlipper} from '@react-navigation/devtools'; | ||
import {useSharedValue, useAnimatedReaction, interpolateColor, withTiming, withDelay, Easing, runOnJS} from 'react-native-reanimated'; | ||
import Navigation, {navigationRef} from './Navigation'; | ||
import linkingConfig from './linkingConfig'; | ||
import AppNavigator from './AppNavigator'; | ||
import themeColors from '../../styles/themes/default'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from '../../components/withWindowDimensions'; | ||
import Log from '../Log'; | ||
import withCurrentReportId, {withCurrentReportIdPropTypes} from '../../components/withCurrentReportId'; | ||
import compose from '../compose'; | ||
import StatusBar from '../StatusBar'; | ||
import useCurrentReportID from '../../hooks/useCurrentReportID'; | ||
import useWindowDimensions from '../../hooks/useWindowDimensions'; | ||
|
||
// https://reactnavigation.org/docs/themes | ||
const navigationTheme = { | ||
|
@@ -21,14 +22,11 @@ const navigationTheme = { | |
}; | ||
|
||
const propTypes = { | ||
...windowDimensionsPropTypes, | ||
|
||
/** Whether the current user is logged in with an authToken */ | ||
authenticated: PropTypes.bool.isRequired, | ||
|
||
/** Fired when react-navigation is ready */ | ||
onReady: PropTypes.func.isRequired, | ||
...withCurrentReportIdPropTypes, | ||
}; | ||
|
||
/** | ||
|
@@ -56,18 +54,54 @@ function NavigationRoot(props) { | |
useFlipper(navigationRef); | ||
const navigationStateRef = useRef(undefined); | ||
|
||
const {updateCurrentReportId} = useCurrentReportID(); | ||
const {isSmallScreenWidth} = useWindowDimensions(); | ||
|
||
const prevStatusBarBackgroundColor = useRef(themeColors.appBG); | ||
const statusBarBackgroundColor = useRef(themeColors.appBG); | ||
const statusBarAnimation = useSharedValue(0); | ||
|
||
useAnimatedReaction( | ||
() => statusBarAnimation.value, | ||
() => { | ||
const color = interpolateColor(statusBarAnimation.value, [0, 1], [prevStatusBarBackgroundColor.current, statusBarBackgroundColor.current]); | ||
runOnJS(StatusBar.setBackgroundColor)(color); | ||
}, | ||
); | ||
|
||
const animateStatusBarBackgroundColor = () => { | ||
const currentRoute = navigationRef.getCurrentRoute(); | ||
const currentScreenBackgroundColor = themeColors.PAGE_BACKGROUND_COLORS[currentRoute.name] || themeColors.appBG; | ||
|
||
prevStatusBarBackgroundColor.current = statusBarBackgroundColor.current; | ||
statusBarBackgroundColor.current = currentScreenBackgroundColor; | ||
if (prevStatusBarBackgroundColor.current === statusBarBackgroundColor.current) { | ||
return; | ||
} | ||
|
||
statusBarAnimation.value = 0; | ||
statusBarAnimation.value = withDelay( | ||
300, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roryabraham, I have a question about the 300ms delay here. It seems to cause the visible issue. Could you please take a look when you have a chance? Thanks! |
||
withTiming(1, { | ||
duration: 300, | ||
easing: Easing.in, | ||
}), | ||
); | ||
}; | ||
|
||
const updateSavedNavigationStateAndLogRoute = (state) => { | ||
if (!state) { | ||
return; | ||
} | ||
navigationStateRef.current = state; | ||
props.updateCurrentReportId(state); | ||
updateCurrentReportId(state); | ||
parseAndLogRoute(state); | ||
animateStatusBarBackgroundColor(); | ||
}; | ||
|
||
return ( | ||
<NavigationContainer | ||
key={props.isSmallScreenWidth ? 'small' : 'big'} | ||
key={isSmallScreenWidth ? 'small' : 'big'} | ||
onStateChange={updateSavedNavigationStateAndLogRoute} | ||
initialState={navigationStateRef.current} | ||
onReady={props.onReady} | ||
|
@@ -85,4 +119,4 @@ function NavigationRoot(props) { | |
|
||
NavigationRoot.displayName = 'NavigationRoot'; | ||
NavigationRoot.propTypes = propTypes; | ||
export default compose(withWindowDimensions, withCurrentReportId)(NavigationRoot); | ||
export default NavigationRoot; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like above console error is related to
runOnJS
.