-
Notifications
You must be signed in to change notification settings - Fork 429
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
[components] Switch to mobile on resize. No need to refresh browser #807
Conversation
This could need a rebase against current next |
82ba468
to
014e981
Compare
014e981
to
b5fa339
Compare
Rebased |
b5fa339
to
6076118
Compare
rebased again. |
6076118
to
6153fc0
Compare
|
||
componentWillUnmont() { | ||
if (window) { | ||
window.removeEventListener('resize', this.handleResize) |
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 is a performance killer as it will trigger a re-render of all split panes on every resize event. It would be much better if this event listener could've been shared between all instances and debounced.
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'll provide an example.
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.
Does it help if i make it a passive listener?
@@ -107,7 +132,7 @@ export default class PanesSplitController extends React.Component { | |||
|
|||
// TODO We need a way to target mobile devices in JS | |||
// --screen-medium-break: 32em; ~32 * 16 = 512 | |||
const isMobile = window && window.innerWidth < 512 | |||
const isMobile = this.state.windowWidth < 512 |
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 clarity I suggest renaming this variable to isSmallScreen
(or smth), since it has nothing to do with mobile really.
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.
agreed
@@ -18,8 +19,24 @@ export default class PanesSplitController extends React.Component { | |||
onSholdExpand() {} | |||
} | |||
|
|||
state = { | |||
windowWidth: 1000 |
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.
Should't this be set to the current window.innerWidth
?
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 thoughts was that window is not always available at this point. Maybe i should set it to undefined and set it on componentDidMount?
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.
Good point, window is available in componentDidMount. Hang on, I'm pushing a small fix in a moment.
6153fc0
to
7cbbdb1
Compare
A change in window width can also be triggered by the |
4ada6c1
to
5c4a426
Compare
bdc81a2
to
4c53006
Compare
Did a couple of improvements:
|
…807) * [components] Switch to mobile on resize. No need to refresh browser * [components] Variable that explains its meaning * [components] Optimize screen width change detection in split pane controller * [components] Set initial windowWidth * [components] Remove redundant .startWith
…807) * [components] Switch to mobile on resize. No need to refresh browser * [components] Variable that explains its meaning * [components] Optimize screen width change detection in split pane controller * [components] Set initial windowWidth * [components] Remove redundant .startWith
Switching to responsive when resizing browser. This is nice when developing.
Before it was necessary to refresh the browser.