-
-
Notifications
You must be signed in to change notification settings - Fork 668
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
Clean up navigation logic (2/x). #4440
Conversation
Thanks! I think you mean #4267 as the issue this will fix. I'll look at the code shortly, but first a couple of thoughts on those helpful screenshots:
|
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.
OK, and read through the code! All looks good modulo one comment below, and my comment above about the UI.
One more thought as I reread your PR description:
The status bar still appears in the lightbox after this PR, despite passing
hidden
to the lightbox'sZulipStatusBar
. I'll get to the bottom of that, later, but it's orthogonal to what's really needed to fix #4267:
Hmm, does the status bar really appear in the lightbox? In your screenshot above in portrait mode, there's a status bar... but I think it is the status bar from the image being shown (which is itself a screenshot from a similar phone.) The time in it is "1:04", and that's the same as I see in that image.
As discussed above, I think the desired behavior is:
- We should show the status bar -- the real live one from the device right now 🙂 -- when we're showing the header and footer. I think we currently don't, and don't in your screenshots from after this PR.
- We should hide it when we're hiding the header and footer. I think we currently get this right (and from the code in the PR, I think it doesn't change that.)
src/nav/ModalSearchNavBar.js
Outdated
ModalSearchNavBar.defaultProps = { | ||
canGoBack: true, | ||
}; |
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.
It looks like this is our first Hooks conversion involving defaultProps!
What do you think of handling this in one of the normal ways for just a function that takes some arguments? That seems like it'd be most in the spirit of Hooks. I think it'd also help make it clearer what's going on. As is, there's actually a bit of a regression in the readability of this code, I think, because the default (and the fact that this one has a default, and parent components aren't required to pass it) gets moved down here, far from the Props
definition and the top of the function.
For example, we could say
const { autoFocus, searchBarOnChange, canGoBack = true } = props;
and then the Props
type could say
canGoBack?: boolean,
That style would also have the added benefit that the Props
type would now reflect the actual external interface. In the class-component world, we need to define a Props
type that's inward-facing, reflecting the defaults already being applied, because the component's implementation may have a lot of entry points (the various methods that use this.props
), and we need to express that they can all count on those props already being filled in, even if they're optional for callers. So we've accepted not actually having the interface written down anywhere, because the Props type is mostly close enough and the defaultProps
are right there (at the top of the class, a few lines below the Props
definition) and the duplication of writing both would be worse. But with a function component, there's just the one entry point (the top of the function), and we can handle filling in the defaults explicitly and do so just once.
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.
Sounds good!
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.
For cross-reference: I've now added this to the style guide:
https://github.com/zulip/zulip-mobile/blob/master/docs/style.md#react-function-prop-defaults
3160704
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.
Thank you!
src/lightbox/LightboxFooter.js
Outdated
<SafeAreaView | ||
mode="padding" | ||
// Why we don't do anything about the unsafe area at the | ||
// bottom here: `Lightbox` ensures that the footer clears it | ||
// when it slides in. | ||
edges={['right', 'left']} | ||
style={[styles.wrapper, style]} | ||
> |
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.
Ah, so perhaps adding 'bottom'
here would be the way to get the footer's padding to extend through to the bottom?
return ( | ||
<ActionSheetProvider> | ||
<View style={[componentStyles.screen, { backgroundColor }]}> | ||
<KeyboardAvoider style={styles.flexed} behavior="padding"> | ||
<ZulipStatusBar narrow={narrow} /> | ||
<ZulipStatusBar backgroundColor={titleBackgroundColor} /> |
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.
Ah, this is much nicer!
…lor`. Soon, we'll have `ZulipStatusBar` stop taking `narrow`, and have `ChatScreen`, the only thing that's been passing it, supply the appropriate `backgroundColor` for the narrow. This will simplify `ZulipStatusBar`'s interface.
And have the only caller that was passing it, `ChatScreen`, calculate for itself what the background color should be.
11ec206
to
80cbcc1
Compare
I think I'll tackle #4267 in a separate PR after this one—I've just pushed a revision that excludes that part. 🙂 |
style={[styles.overlay, { width: windowWidth, bottom: windowHeight - 44 }]} | ||
from={windowHeight} | ||
to={windowHeight - 44} |
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 also notice, thanks to this cleanup calling my attention to it, that this longstanding bit of code is all unnecessarily complicated -- if you subtract windowHeight
from all three of these vertical values, it gets a lot simpler. Maybe simpler still if you subtract windowHeight - 44
, so that it's:
bottom: 0
from={44}
to={0}
But that might all be made moot by the changes you're already working on to replace this translateY
animation entirely.
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've got a commit that does exactly that simplification; about to send the PR. 😄
@chrisbobbe Can I help you with the cleanup and in conversion of component to hooks based components? |
Sure, @karanb1, thanks! Several of our components don't have any lifecycle methods beyond |
(Just split off some work on the lightbox in #4442.) |
Originally discussed here: #4440 (comment) (with a bit of additional rationale) when this question first came up. It's come up a couple more times since then, as we've continued converting a lot of our components to functions with Hooks: #4555 (comment) #4699 (comment) so it's definitely time to have it written down in a proper place.
This is the second PR in the series that began with #4428.
It converts some more components to Hooks-based components, to prepare for future work, and it also makes some preparatory changes to
ZulipStatusBar
, which I'd like to focus on in the next PR in this series. (ZulipStatusBar
, I've found, isn't the best place to put logic that handles the safe-area view at the top; that PR will relocate that logic.)I found that I could reasonably include a fix for #4267 in this PR, to help it land sooner. The status bar still appears in the lightbox after this PR, despite passing
hidden
to the lightbox'sZulipStatusBar
. I'll get to the bottom of that, later, but it's orthogonal to what's really needed for fixing #4267:(I neglected 2 and 3 in my #4268; so, I'm closing that.)
After those fixes, the lightbox looks like this on a newer iPhone (showing the image in this message). These screenshots show the state when the header and footer are visible; tapping the screen makes them slide cleanly off the screen. I've also tested on the office Android device, and on my own, older, iPhone; all works as expected.