Skip to content
This repository was archived by the owner on Feb 23, 2021. It is now read-only.

Conversation

@valentinewallace
Copy link
Contributor

Closes #333

super(props);
this.handleKeyDown = this.handleKeyDown.bind(this);
}
componentDidMount() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing empty line between the two functions.

constructor(props) {
props.title = props.title || '';
super(props);
this.handleKeyDown = this.handleKeyDown.bind(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of the bind style. We should use arrow functions in the event handlers themselves to stay consistent with our current coding style.

this.handleKeyDown = this.handleKeyDown.bind(this);
}
componentDidMount() {
document.addEventListener('keydown', this.handleKeyDown);
Copy link
Contributor

Choose a reason for hiding this comment

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

We should check if document exist as this will crash on mobile.

Also please use e => this.handleKeyDown(e) instead of bind.


componentWillUnmount() {
document.removeEventListener('keydown', this.handleKeyDown);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above...

</View>
);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should pull this out into an Escapable component that the modal inherits from.

Copy link
Contributor

@tanx tanx left a comment

Choose a reason for hiding this comment

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

Great! I made two minor changes. Please take a look. Otherwise ready to merge from my side.


componentWillUnmount() {
if (typeof document !== 'undefined') {
document.removeEventListener('keydown', this.handleKeyDown);
Copy link
Contributor

Choose a reason for hiding this comment

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

@valentinewallace it turn out we needed to use the bind style after all otherwise the function pointer would not have been consistent and the event listener would not have been removed.

}

componentDidMount() {
if (typeof document !== 'undefined') {
Copy link
Contributor

Choose a reason for hiding this comment

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

When checking for a global like document or window always use typeof otherwise you'll get this error in an environment that does not have them: ReferenceError: document is not defined

@valentinewallace valentinewallace merged commit 3e16180 into master Jul 24, 2018
@valentinewallace valentinewallace deleted the close-widgets-on-esc branch July 24, 2018 20:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants