-
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
Bugfix FXIOS-10099 [Toolbar redesign] Only show address toolbar bottom border on webpages when scrolled #22120
Bugfix FXIOS-10099 [Toolbar redesign] Only show address toolbar bottom border on webpages when scrolled #22120
Conversation
guard let toolbarState = store.state.screenState(ToolbarState.self, for: .toolbar, window: action.windowUUID) | ||
else { return state.borderPosition } | ||
|
||
let isWebPage = action.url?.isWebPage() ?? false |
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.
Figma says that the navigation border should also be shown when the toolbar is set to top and we are on the homepage.
Also I am not sure why the middleware is not used to get the correct position anymore. I don't really like the mix between having logic here and also using Redux as the source of truth. So far the middleware was handling the toolbar border position using the ToolbarManager
. Is there a reason we don't use that anymore but also leave the code in place?
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.
Maybe I am misunderstanding the spec, but to me, it reads that it should only be visible on scroll when the toolbar is set to the top and on the homepage, but not when the page is scroll to the top.
I put this logic directly in the reducer instead of the middleware because it had no dependencies (if you don't include ToolbarManager
). This code is specifically for when the url changes and we either navigate to a webpage and show the border, or navigate to the homepage and hide the border. We still use the middleware (and ToolbarManager
) for monitoring for homepage scroll. I will take a look and see if there is a more consistent way to write this where the logic isn't as spread out, because I agree, it is confusing
GeneralBrowserMiddlewareAction( | ||
scrollOffset: scrollView.contentOffset, | ||
windowUUID: windowUUID, | ||
actionType: GeneralBrowserMiddlewareActionType.websiteDidScroll)) |
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 context, are we removing this because it is already handled in the Home Page and making this redundant?
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 code was specifically for showing/hiding the border when scrolling on webpages, which we don't care about because we always want to show the address bar border when on a webpage, and that is being handled in the new changes to AddressBarState
.
Scrolling on the homepage is handled in HomepageViewController.
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.
Oh okay, thanks for the clarity, didn't realize the design requirements for this. thanks!
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, I was totally wrong on this - as @thatswinnie pointed out in a comment below, the design requirement is to show the top address bar bottom border on scroll - so I will be adding this back 😅
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.
Oh okay cool, thank you! Feel free to ping me if you still like a review from me. thanks!
@@ -192,13 +192,14 @@ struct AddressBarState: StateType, Equatable { | |||
|
|||
case ToolbarActionType.urlDidChange: | |||
guard let toolbarAction = action as? ToolbarAction else { return state } | |||
let borderPosition = getAddressToolbarBorderPosition(action: toolbarAction, state: state) |
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 like that we're using an existing action, but also curious on why not moving the logic in the middleware and can pass in the border position using
let borderPosition = action.addressBorderPosition
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 would require a urlDidChange
middleware action, right? This was mainly to avoid adding an unnecessary middleware action for something that didn't technically need (i.e. no dependencies required) to go through the middleware, but I understand wanting to have all of the border logic in once place. Do you think it makes sense to add a middleware action here?
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 also send two actions: the existing urlDidChange
that goes to the reducer and one to the middleware that updates only the border. This way we don't duplicate code.
The concerns I have about this code being in multiple places is that it renders the code we have in DefaultToolbarManager
and it's unit tests useless and it's not the source of truth anymore. And we can't call the DefaultToolbarManager
from the reducer as it's not supposed to have dependencies.
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 have added ToolbarMiddlewareActionType.urlDidChange
so that the middleware continues to be the only one who handles border position logic therefore this logic is now removed from the AddressBarState
's reducer. The downfall is that we now have to dispatch both ToolbarMiddlewareActionType.urlDidChange
and ToolbarActionType.urlDidChange
in tandem 😪
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.
Instead of in tandem, what about dispatching one action that gets sent to the middleware first and then once the border position is calculated then we dispatch another action that can update the state altogether?
Also side note, I didn't add a isMicrosurveyShown
check in the DefaultToolbarManager
because I feel that the toolbar manager should be independent of knowing external views. It makes it seem coupled by adding the additional checks. What do you think about doing something similar to the microsurvey in which for the web page check we just send the payload of updating the border when needed?
scrollY: CGFloat) -> AddressToolbarBorderPosition { | ||
// display the top border if | ||
// - the toolbar is displayed at the bottom | ||
// display the bottom border if | ||
// - the toolbar is displayed at the top and the website was scrolled | ||
// - the toolbar is displayed at the top and page is scrolled (applies to homepage) | ||
// - the toolbar is displayed at the top and we are on a webpage |
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 am confused about this change. Is this coming from design? In Figma the requirements for websites are the following:
So the bottom border for websites should only be displayed on scroll unless the user is in private mode - only then it's displayed always.
This pull request has conflicts when rebasing. Could you fix it @MattLichtenstein? 🙏 |
2aa788a
to
4410006
Compare
Client.app: Coverage: 30.12
Generated by 🚫 Danger Swift against 5b1292f |
@@ -741,6 +741,11 @@ extension BrowserViewController: WKNavigationDelegate { | |||
actionType: ToolbarActionType.urlDidChange | |||
) | |||
store.dispatch(action) | |||
let middlewareAction = ToolbarMiddlewareAction( | |||
windowUUID: windowUUID, |
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 scrollOffset
should be added as a parameter as well.
if (lastContentOffsetY > 0 && scrollView.contentOffset.y <= 0) || | ||
(lastContentOffsetY <= 0 && scrollView.contentOffset.y > 0) { | ||
lastContentOffsetY = scrollView.contentOffset.y |
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.
nice!
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.
looking great now!~ theres some overlap between the tab scroll and home page so would be nice if we could keep it DRY. However, this was implemented prior so can leave as is. approved! thanks for going through the iterations!
📜 Tickets
Jira ticket
Github issue
💡 Description
📝 Notes
websiteDidScroll
based on the current redux state. This does not work becausescrollViewDidScroll
happens to quickly and frequently meaning the state information being checked to determine if we should dispatch another action will likely be outdated📹 Video
Simulator.Screen.Recording.-.iPhone.15.-.2024-09-26.at.17.59.51.mp4
📝 Checklist
You have to check all boxes before merging
@Mergifyio backport release/v120
)