-
-
Notifications
You must be signed in to change notification settings - Fork 674
Clean up navigation logic (4/x): Tidy up our use of ZulipStatusBar a bit more.
#4468
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
e918500
Screen [nfc]: Convert to use Hooks (1/2).
chrisbobbe 565c125
Screen [nfc]: Convert to use Hooks (2/2).
chrisbobbe 69a30e7
Screen: Use `SafeAreaView`.
chrisbobbe 05bd898
MainTabsScreen: Use `SafeAreaView`.
chrisbobbe a40bc52
ZulipStatusBar [nfc]: Expand/improve jsdoc.
chrisbobbe 08f0feb
ChatNavBar [nfc]: Put `ZulipStatusBar` in `ChatNavBar`.
chrisbobbe ebda227
Screen [nfc]: Set status bar color in `Modal(Search)NavBar` instead.
chrisbobbe a86b395
Lightbox: Move `ZulipStatusBar` callsite here, from `LightboxScreen`.
chrisbobbe 91920e2
Lightbox: Show and hide the status bar with the header/footer.
chrisbobbe d24f96c
types [nfc]: Add jsdoc for `EditMessage`.
chrisbobbe 771f3c2
ChatScreen: Store `editMessage` as a nav param, not React state.
chrisbobbe bbab920
KeyboardAvoider [nfc]: Write a jsdoc.
chrisbobbe 70eca07
KeyboardAvoider [nfc]: Allow setting `keyboardVerticalOffset`.
chrisbobbe 5380150
ChatScreen [nfc]: Slightly move a definition.
chrisbobbe 188e238
ChatScreen [nfc]: Remove unnecessary wrapping `View`.
chrisbobbe 5bd0274
ZulipStatusBar: Set default background/visibility once, in outer scope.
chrisbobbe c1fae32
FullScreenLoading [nfc]: Move `ZulipStatusBar` out of a `View`.
chrisbobbe 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 hidden or 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 hidden or 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,14 +1,13 @@ | ||
| /* @flow strict-local */ | ||
| import React from 'react'; | ||
| import { View } from 'react-native'; | ||
| import { useIsFocused } from '@react-navigation/native'; | ||
|
|
||
| import { useSelector, useDispatch } from '../react-redux'; | ||
| import type { RouteProp } from '../react-navigation'; | ||
| import type { AppNavigationProp } from '../nav/AppNavigator'; | ||
| import styles, { ThemeContext, createStyleSheet } from '../styles'; | ||
| import { ThemeContext, createStyleSheet } from '../styles'; | ||
| import type { Narrow, EditMessage } from '../types'; | ||
| import { KeyboardAvoider, OfflineNotice, ZulipStatusBar } from '../common'; | ||
| import { KeyboardAvoider, OfflineNotice } from '../common'; | ||
| import ChatNavBar from '../nav/ChatNavBar'; | ||
| import MessageList from '../webview/MessageList'; | ||
| import NoMessages from '../message/NoMessages'; | ||
|
|
@@ -21,11 +20,10 @@ import { canSendToNarrow } from '../utils/narrow'; | |
| import { getLoading, getSession } from '../directSelectors'; | ||
| import { getFetchingForNarrow } from './fetchingSelectors'; | ||
| import { getShownMessagesForNarrow, isNarrowValid as getIsNarrowValid } from './narrowsSelectors'; | ||
| import { getStreamColorForNarrow } from '../subscriptions/subscriptionSelectors'; | ||
|
|
||
| type Props = $ReadOnly<{| | ||
| navigation: AppNavigationProp<'chat'>, | ||
| route: RouteProp<'chat', {| narrow: Narrow |}>, | ||
| route: RouteProp<'chat', {| narrow: Narrow, editMessage: EditMessage | null |}>, | ||
| |}>; | ||
|
|
||
| const componentStyles = createStyleSheet({ | ||
|
|
@@ -99,11 +97,12 @@ const useFetchMessages = args => { | |
| }; | ||
|
|
||
| export default function ChatScreen(props: Props) { | ||
| const { route, navigation } = props; | ||
| const { backgroundColor } = React.useContext(ThemeContext); | ||
|
|
||
| const [editMessage, setEditMessage] = React.useState<EditMessage | null>(null); | ||
|
|
||
| const { narrow } = props.route.params; | ||
| const { narrow, editMessage } = route.params; | ||
| const setEditMessage = (value: EditMessage | null) => | ||
| navigation.setParams({ editMessage: value }); | ||
|
Member
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. Hmm, interesting! |
||
|
|
||
| const isNarrowValid = useSelector(state => getIsNarrowValid(state, narrow)); | ||
|
|
||
|
|
@@ -113,40 +112,35 @@ export default function ChatScreen(props: Props) { | |
| const sayNoMessages = haveNoMessages && !isFetching; | ||
| const showComposeBox = canSendToNarrow(narrow) && !showMessagePlaceholders; | ||
|
|
||
| const streamColor = useSelector(state => getStreamColorForNarrow(state, narrow)); | ||
|
|
||
| return ( | ||
| <View style={[componentStyles.screen, { backgroundColor }]}> | ||
| <KeyboardAvoider style={styles.flexed} behavior="padding"> | ||
| <ZulipStatusBar backgroundColor={streamColor} /> | ||
| <ChatNavBar narrow={narrow} editMessage={editMessage} /> | ||
| <OfflineNotice /> | ||
| <UnreadNotice narrow={narrow} /> | ||
| {(() => { | ||
| if (!isNarrowValid) { | ||
| return <InvalidNarrow narrow={narrow} />; | ||
| } else if (fetchError !== null) { | ||
| return <FetchError narrow={narrow} error={fetchError} />; | ||
| } else if (sayNoMessages) { | ||
| return <NoMessages narrow={narrow} />; | ||
| } else { | ||
| return ( | ||
| <MessageList | ||
| narrow={narrow} | ||
| showMessagePlaceholders={showMessagePlaceholders} | ||
| startEditMessage={setEditMessage} | ||
| /> | ||
| ); | ||
| } | ||
| })()} | ||
| {showComposeBox && ( | ||
| <ComposeBox | ||
| narrow={narrow} | ||
| editMessage={editMessage} | ||
| completeEditMessage={() => setEditMessage(null)} | ||
| /> | ||
| )} | ||
| </KeyboardAvoider> | ||
| </View> | ||
| <KeyboardAvoider style={[componentStyles.screen, { backgroundColor }]} behavior="padding"> | ||
| <ChatNavBar narrow={narrow} editMessage={editMessage} /> | ||
| <OfflineNotice /> | ||
| <UnreadNotice narrow={narrow} /> | ||
| {(() => { | ||
| if (!isNarrowValid) { | ||
| return <InvalidNarrow narrow={narrow} />; | ||
| } else if (fetchError !== null) { | ||
| return <FetchError narrow={narrow} error={fetchError} />; | ||
| } else if (sayNoMessages) { | ||
| return <NoMessages narrow={narrow} />; | ||
| } else { | ||
| return ( | ||
| <MessageList | ||
| narrow={narrow} | ||
| showMessagePlaceholders={showMessagePlaceholders} | ||
| startEditMessage={setEditMessage} | ||
| /> | ||
| ); | ||
| } | ||
| })()} | ||
| {showComposeBox && ( | ||
| <ComposeBox | ||
| narrow={narrow} | ||
| editMessage={editMessage} | ||
| completeEditMessage={() => setEditMessage(null)} | ||
| /> | ||
| )} | ||
| </KeyboardAvoider> | ||
| ); | ||
| } | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
We could aim to reduce the contents of
editMessage, probably to just the ID of the message being edited, along the lines of what React Navigation recommends should go in these params.I think the biggest drawback to storing the whole original content and topic equally applies in the status quo (i.e., where
editMessageis stored in React state): we should be getting model data from react-redux, in a way that ensures that the UI live-updates. So, perhaps a fix can be done as a followup, or we can add a TODO. (Er, or actually it might be quite easy to do in this PR; I've just assumed it might be a bit complicated because of how tricky it was to work out whateditMessagedoes in the first place.)The article gives a couple of other good reasons, but some of them (like gracefully handling deep-linking) don't yet really apply to us. But I think their guidance that "You can also think of the route object like a URL" makes sense. For this screen, I'm thinking of the analogy of a URL that has something like
?msg-edit-id=12345.Uh oh!
There was an error while loading. Please reload this page.
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.
In my draft that moves
ModalSearchNavBarto the header, the search term is stored in the nav state. This seems fine; I'm thinking of the analogy of a URL that has something like?q=foo.Also, from the doc about what should go in params:
Uh oh!
There was an error while loading. Please reload this page.
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.
While at first I thought we might not want to keep the search bar in the header/nav bar, I think it's actually a fine place to put it, at least on Android.
From an Android doc:
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.
I think the thing that makes that tricky is mainly just the message content. If you look at where
setEditMessagegets called (after getting renamed tostartEditMessagealong the way >_> -- this whole edit-message path is not a model of good software design), we have to fetch the raw Markdown content from the server at that point:We don't have any cause to keep that information beyond the scope of one edit-message operation, so I think it is best kept as local state of one form or another. If we want the message ID in the nav state, I think the least awkward thing may be for the content and topic to go there along with it, as this PR currently does.
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.
Yep, this is pretty classic in Material Design and on Android.
It's not really that foreign on iOS either, I think. Open up Safari, or Photos, and start searching -- the search box is at the top in basically an equivalent of the app bar.
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.
Ahh—right, you're right. I saw that but forgot about it when commenting.