Skip to content
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

Merged
merged 5 commits into from
May 23, 2018

Conversation

kristofferjs
Copy link
Contributor

Switching to responsive when resizing browser. This is nice when developing.
Before it was necessary to refresh the browser.

@bjoerge
Copy link
Member

bjoerge commented May 15, 2018

This could need a rebase against current next

@kristofferjs
Copy link
Contributor Author

Rebased

@kristofferjs
Copy link
Contributor Author

rebased again.


componentWillUnmont() {
if (window) {
window.removeEventListener('resize', this.handleResize)
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

@bjoerge
Copy link
Member

bjoerge commented May 23, 2018

A change in window width can also be triggered by the orientationchange event.

@bjoerge
Copy link
Member

bjoerge commented May 23, 2018

Did a couple of improvements:

  • Now sharing resize and orientationchange listeners between all SplitPaneController components. This will also synchronize their rendering.
  • Debouncing resize/orientationchange events every 50ms

@kristofferjs kristofferjs merged commit bdc174e into next May 23, 2018
@kristofferjs kristofferjs deleted the responsive-split-pane branch May 23, 2018 09:51
bjoerge pushed a commit that referenced this pull request May 23, 2018
…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
bjoerge pushed a commit that referenced this pull request May 24, 2018
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants