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

fix: Compute scrollbar size dynamically on need #297

Merged
merged 6 commits into from
Oct 19, 2019

Conversation

billychan
Copy link
Contributor

About issue #283 and react bootstrap issue react-bootstrap/react-bootstrap#3645

Verified locally react-bootstrap modal launched well.

Copy link
Member

@taion taion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see discussion around #283 (comment). This is not an acceptable fix. Calculating the scrollbar size requires inserting new elements to the DOM, and should not be done during the setContainerStyle calculation.

@billychan
Copy link
Contributor Author

@taion you are right at that point. How do you like if the manager instance instantiated here? https://github.com/billychan/react-overlays/blob/c885aa3102ec01569d18df447f67cb2f3a950eb9/src/Modal.js#L235

@taion
Copy link
Member

taion commented Jun 13, 2019

Yes – I think componentDidMount is the right place to construct the default modal manager.

@billychan
Copy link
Contributor Author

@taion Thanks checking man, please see how the new version looks 😃

src/Modal.js Outdated
@@ -233,6 +230,7 @@ class Modal extends React.Component {

componentDidMount() {
this._isMounted = true;
this.manager = new ModalManager();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • You should only instantiate this if a manager wasn't specified via props.
  • By default, we still want a single global singleton manager. We just want to delay when it gets initialized.

So I think I'd do something like:

let manager; // Maybe export this?

class Modal {
  // ...

  getModalManager() {
    if (this.props.manager) {
      return this.props.manager;
    }

    if (!manager) {
      manager = new ModalManager();
    }

    return manager;
  }

  // ...
}

Copy link
Contributor Author

@billychan billychan Jun 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I previously wrote that as this.manager = this.props.manager || new ModalManager() to still allow injection from props, removed when testing some issue and forgot to revert. Thanks catching 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But even so that doesn't quite preserve the semantics, as it means that changing the passed-in modal manager via the props would have no effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw your point, you want to keep a singleton of ModalManager instance which keeps global knowledge of this.modals.

That might be better wrapped in a separate module I guess, maybe something like this?

// Modal.js
import { getModalManager } from './ModalManager';

//.....
  componentDidMount() {
    this._isMounted = true;
    this.manager = this.props.manager || getModalManager();

And

// ModalManager.js
// ....

let manager;

function getModalManager() {
  if (manager) {
     return manager;
  }
 manager = new ModalManager();
 return manager;
}

Sounds good?

BTW maybe similar needs to be done in react-bootstrap later too https://github.com/react-bootstrap/react-bootstrap/blob/0bb8a6fd4ad110c49e5e89f05228ade0968652bf/src/Modal.js#L154

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the example code in #297 (comment). Do that, then use this.getModalManager(). The issue with your proposed solution above is that it wouldn't respect changes to the prop.

@deXterbed
Copy link

@taion any update on when this PR will be merged? thanks!

Copy link
Member

@taion taion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getModalManager doesn't need to be bound, as it's always called with the proper this context

additionally, you may need to merge to master to get CI to pass

i'll merge afterward. thanks!

src/Modal.js Outdated
@@ -314,6 +313,18 @@ class Modal extends React.Component {
this.backdrop = ref && ReactDOM.findDOMNode(ref);
};

getModalManager = () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
getModalManager = () => {
getModalManager() {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right 👍

src/Modal.js Outdated
}

return manager;
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
};
}

@deXterbed
Copy link

@billychan can you look into the changes suggested by taion?

@billychan
Copy link
Contributor Author

billychan commented Oct 19, 2019

@deXterbed @taion I've merged back master and updated code to remove binding.

The specs all passed while CI failed at uploading tests coverage step, maybe that's something temporary I guess.

@taion taion changed the title Compute scrollbar size dynamically on need fix: Compute scrollbar size dynamically on need Oct 19, 2019
@taion taion merged commit e022e9c into react-bootstrap:master Oct 19, 2019
@taion
Copy link
Member

taion commented Oct 19, 2019

Thanks!

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.

4 participants