-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix: Blank screen after creating an account #2575
Merged
marcaaron
merged 26 commits into
Expensify:main
from
kidroca:kidroca/use-navigation-after-init-is-done
Apr 29, 2021
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
529f0fb
feat: Navigation navigateLater and enableNavigation
kidroca 78490e7
refactor: AuthScreens empty string is a valid initial value for initi…
kidroca 8aeafcc
fix: Report.fetchAllReports - fetchChatReportsByIDs would be called w…
kidroca da36c16
fix: Report.fetchAllReports - new report created by `fetchOrCreateCha…
kidroca c4d25f5
fix: Report.fetchAllReports - Navigation.navigate does not work when …
kidroca d6596c5
refactor: Move initialReportID from AuthScreens to MainDrawerNavigator
kidroca 1591d76
refactor: Mount the Report Screen only when initial data is resolved
kidroca f394b98
refactor: Reuse `updateCurrentlyViewedReportID`
kidroca 9faf5e4
Revert "feat: Navigation navigateLater and enableNavigation"
kidroca fdc8259
Revert "fix: Report.fetchAllReports - Navigation.navigate does not wo…
kidroca d0a952f
refactor: Bring back the cast logic to fetchAllReports
kidroca bfdbb5f
refactor: Move Onyx updating code to promise finally
kidroca c71967f
fix: Remove `loading` from the URL path in the address bar
kidroca 5c91d54
update: Keep the Report Screen mounted since the first time it's reso…
kidroca b20db83
refactor: Replace inline Screen names with values from SCREENS
kidroca a2aa335
refactor: convert MainDrawerNavigator to class to avoid `route.state`…
kidroca 6b224e1
fix: The logic moved to finally was not correctly translated
kidroca 6326456
refactor: remove memo usage
kidroca 3395cda
Revert "refactor: convert MainDrawerNavigator to class to avoid `rout…
kidroca 8bc3104
refactor: base home navigator mounting on whether there are any repor…
kidroca 14df6cb
Revert "refactor: Reuse `updateCurrentlyViewedReportID`"
kidroca fa3eaa2
refactor: remove the `shouldRedirectToReport` and lastReportID setting
kidroca 558babb
feat: findLastAccessedReport a function to derive the last viewed report
kidroca f0050f6
refactor: move `findLastAccessedReport` to `reportUtils`
kidroca 48f2427
refactor: remove `initialReportID` no longer needed
kidroca 13435af
fix: When `fetchAllReports` creates a chat with concierge it don't ha…
kidroca 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*/ | ||
export default { | ||
HOME: 'Home', | ||
LOADING: 'Loading', | ||
REPORT: 'Report', | ||
SIGN_IN: 'SignIn', | ||
}; |
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 |
---|---|---|
@@ -1,49 +1,87 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'underscore'; | ||
import {createDrawerNavigator} from '@react-navigation/drawer'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
|
||
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; | ||
import FullScreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator'; | ||
import {getLastAccessedReport} from '../../reportUtils'; | ||
import styles, { | ||
getNavigationDrawerType, | ||
getNavigationDrawerStyle, | ||
} from '../../../styles/styles'; | ||
import ONYXKEYS from '../../../ONYXKEYS'; | ||
import compose from '../../compose'; | ||
import SCREENS from '../../../SCREENS'; | ||
|
||
// Screens | ||
import SidebarScreen from '../../../pages/home/sidebar/SidebarScreen'; | ||
import ReportScreen from '../../../pages/home/ReportScreen'; | ||
|
||
const propTypes = { | ||
// Available reports that would be displayed in this navigator | ||
reports: PropTypes.objectOf(PropTypes.shape({ | ||
reportID: PropTypes.number, | ||
})), | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
reports: {}, | ||
}; | ||
|
||
const Drawer = createDrawerNavigator(); | ||
|
||
const MainDrawerNavigator = props => ( | ||
<Drawer.Navigator | ||
openByDefault | ||
drawerType={getNavigationDrawerType(props.isSmallScreenWidth)} | ||
drawerStyle={getNavigationDrawerStyle( | ||
props.windowWidth, | ||
props.isSmallScreenWidth, | ||
)} | ||
sceneContainerStyle={styles.navigationSceneContainer} | ||
edgeWidth={500} | ||
drawerContent={() => <SidebarScreen />} | ||
> | ||
<Drawer.Screen | ||
name="Report" | ||
component={ReportScreen} | ||
|
||
// Providing an empty string here will ensure that the ReportScreen does not show as '/r/undefined' | ||
// eslint-disable-next-line react/jsx-props-no-multi-spaces | ||
initialParams={{reportID: ''}} | ||
options={{ | ||
// Decorated to always returning the result of the first call - keeps Screen initialParams from changing | ||
const getInitialReport = _.once(getLastAccessedReport); | ||
kidroca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const MainDrawerNavigator = (props) => { | ||
// When there are no reports there's no point to render the empty navigator | ||
if (_.size(props.reports) === 0) { | ||
return <FullScreenLoadingIndicator visible />; | ||
} | ||
|
||
const initialReportID = getInitialReport(props.reports).reportID; | ||
kidroca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* After the app initializes and reports are available the home navigation is mounted | ||
* This way routing information is updated (if needed) based on the initial report ID resolved. | ||
* This is usually needed after login/create account and re-launches */ | ||
return ( | ||
<Drawer.Navigator | ||
openByDefault | ||
drawerType={getNavigationDrawerType(props.isSmallScreenWidth)} | ||
drawerStyle={getNavigationDrawerStyle( | ||
props.windowWidth, | ||
props.isSmallScreenWidth, | ||
)} | ||
sceneContainerStyle={styles.navigationSceneContainer} | ||
edgeWidth={500} | ||
drawerContent={() => <SidebarScreen />} | ||
screenOptions={{ | ||
cardStyle: styles.navigationScreenCardStyle, | ||
headerShown: false, | ||
}} | ||
/> | ||
</Drawer.Navigator> | ||
); | ||
> | ||
<Drawer.Screen | ||
name={SCREENS.REPORT} | ||
component={ReportScreen} | ||
initialParams={{reportID: initialReportID.toString()}} | ||
/> | ||
</Drawer.Navigator> | ||
); | ||
}; | ||
|
||
MainDrawerNavigator.propTypes = propTypes; | ||
MainDrawerNavigator.defaultProps = defaultProps; | ||
MainDrawerNavigator.displayName = 'MainDrawerNavigator'; | ||
export default withWindowDimensions(MainDrawerNavigator); | ||
|
||
export default compose( | ||
withWindowDimensions, | ||
withOnyx({ | ||
reports: { | ||
key: ONYXKEYS.COLLECTION.REPORT, | ||
}, | ||
}), | ||
)(MainDrawerNavigator); |
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
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.
This comment is a little hard to follow and I might change it to something like:
Which also begs the question... what happens if the
initialParams
change? And why do we care? Maybe we can explain that as well here just so it is very obvious?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.
Nothing will happen if we pass different
initialParams
after the screen is mounted. And that's why we want to stop calculating them each timeMainDrawerNavigator
re-rendersIt might be better to just remove this
_.once
optimization and address it if it ever becomes a problemThere 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.
Nice one, yep I think this is fine in any case but took me a second to get why so a small comment would have been helpful.