-
Notifications
You must be signed in to change notification settings - Fork 204
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
Adding support for onLayoutChange notifier configuration #499
Conversation
Codecov Report
@@ Coverage Diff @@
## master #499 +/- ##
==========================================
+ Coverage 90.74% 90.74% +<.01%
==========================================
Files 135 135
Lines 5361 5383 +22
Branches 931 938 +7
==========================================
+ Hits 4865 4885 +20
- Misses 496 498 +2
Continue to review full report at Codecov.
|
f0f5020
to
871648e
Compare
871648e
to
afbdbcc
Compare
Rebased on master. In testing this, I see that when opening or closing the sidebar the width reported is the one before the state changed. This means that if an integrator tries to adjust the position of some elements when the sidebar becomes wider after it is opened or closed, it will end up in the wrong place: Example output logged by an
|
Testing using localhost:3000, the callback is not invoked when the client initially loads if Steps to reproduce:
window.hypothesisConfig = function () {
return {
liveReloadServer: 'ws://' + appHost + ':${port}',
onLayoutChange({ width, height, expanded }) {
console.log(\`Sidebar state changed \${width}x\${height}. Open: \${expanded}\`);
}
};
};
Expected: Callback invoked when client initially loads with |
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 found two issues in testing and left some minor comments on the code:
- The callback does not appear to be invoked when the client initially loads if the sidebar is not configured to open by default.
- When opening and closing the sidebar, the width reported in the callback is the width before the sidebar state changed rather than the width after the sidebar finishes opening/closing. In order for integrators to position elements correctly, we need to either tell them what the final state will be or trigger another callback once the open/close animation completes.
src/annotator/sidebar.coffee
Outdated
@@ -46,6 +46,8 @@ module.exports = class Sidebar extends Host | |||
@onProfileRequest = serviceConfig.onProfileRequest | |||
@onHelpRequest = serviceConfig.onHelpRequest | |||
|
|||
@onLayoutChange = config.onLayoutChange; |
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.
My CoffeeScript syntax highlighter complains if lines end with semicolons. The compiler doesn't complain but we should omit them for consistency.
src/annotator/sidebar.coffee
Outdated
this._notifyOfLayoutChange() | ||
|
||
_notifyOfLayoutChange: () => | ||
BUCKETBAR_WIDTH = 37 |
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.
Would it be possible to avoid hardcoding this number?
src/annotator/config/index.js
Outdated
@@ -19,6 +19,7 @@ function configFrom(window_) { | |||
|
|||
annotations: settings.annotations, | |||
branding: settings.hostPageSetting('branding'), | |||
onLayoutChange: settings.hostPageSetting('onLayoutChange'), |
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 wonder if we should rename this to onSidebarLayoutChange
to be more explicit about what thing's layout changed?
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.
Sidebar is probably redundant. it's not sidebarBranding, etc. Let's keep it the way it is 👍
ed1b7d4
to
d1a85b3
Compare
Updated the width algorithm to calculate properly when we toggle expanded states. I updated the expanded state to also reflect if we are above the fully collapsed width - allowing panning to properly update expanded or not. Also, made the padding for the left side of the sidebar dynamic based on the width of the toolbar |
d1a85b3
to
091a447
Compare
- Add a doc comment to the _notifyOfLayoutChange function to clarify the purpose of the optional param. - Add a comment inside the function to describe the high-level structure of the sidebar and how expanding/collapsing it is achieved. - Correct a typo with "frameVisbileWidth"
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.
LGTM. I added a doc comment to _notifyOfLayoutChange
and an internal comment about the structure of the sidebar and how expanding/collapsing it is achieved by adjusting the left margin of the container, since this existing aspect of how the sidebar works wasn't immediately obvious to me.
We'll need to make sure we document this, along with any other features added to support Readium's requirements.
We are trying to allow an integrator to know about the layout state of our sidebar as it changes.
The signature we are expecting is:
As noted above we will provide the width, height, and the expanded state.