This repository was archived by the owner on Feb 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 168
Close channel/tx detail on escape press #455
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Component } from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| class Escapable extends Component { | ||
| constructor(props) { | ||
| super(props); | ||
| this.handleKeyDown = this.handleKeyDown.bind(this); | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| if (typeof document !== 'undefined') { | ||
| document.addEventListener('keydown', this.handleKeyDown); | ||
| } | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if (typeof document !== 'undefined') { | ||
| document.removeEventListener('keydown', this.handleKeyDown); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
| } | ||
|
|
||
| handleKeyDown(event) { | ||
| if (event.keyCode === 27) { | ||
| this.props.onClose(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Escapable.propTypes = { | ||
| onClose: PropTypes.func.isRequired, | ||
| }; | ||
|
|
||
| export default Escapable; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import React from 'react'; | ||
| import { View, ViewPropTypes, StyleSheet } from 'react-native'; | ||
| import PropTypes from 'prop-types'; | ||
| import { Button } from '../../src/component/button'; | ||
| import { Button } from './button'; | ||
| import { H4Text } from './text'; | ||
| import Icon from './icon'; | ||
| import Escapable from './escapable'; | ||
| import { color } from './style'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
|
|
@@ -34,15 +35,20 @@ const styles = StyleSheet.create({ | |
| }, | ||
| }); | ||
|
|
||
| const Modal = ({ title = '', onClose, children, style }) => ( | ||
| <View style={[styles.modal, style]}> | ||
| <H4Text style={styles.title}>{title.toUpperCase()}</H4Text> | ||
| <Button style={styles.cancelBtn} onPress={onClose}> | ||
| <Icon image="cancel-grey" style={styles.cancelIcon} /> | ||
| </Button> | ||
| {children} | ||
| </View> | ||
| ); | ||
| class Modal extends Escapable { | ||
| render() { | ||
| const { title = '', style, onClose, children } = this.props; | ||
| return ( | ||
| <View style={[styles.modal, style]}> | ||
| <H4Text style={styles.title}>{title.toUpperCase()}</H4Text> | ||
| <Button style={styles.cancelBtn} onPress={onClose}> | ||
| <Icon image="cancel-grey" style={styles.cancelIcon} /> | ||
| </Button> | ||
| {children} | ||
| </View> | ||
| ); | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we should pull this out into an |
||
|
|
||
| Modal.propTypes = { | ||
| title: PropTypes.string.isRequired, | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When checking for a global like
documentorwindowalways usetypeofotherwise you'll get this error in an environment that does not have them:ReferenceError: document is not defined