-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2222 from npsedhain/npsedhain-create-menu
Display create menu within the chat area and add bottom up transition.
- Loading branch information
Showing
10 changed files
with
202 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,99 @@ | ||
import React, {PureComponent} from 'react'; | ||
import {View} from 'react-native'; | ||
import PropTypes from 'prop-types'; | ||
import Popover from './Popover'; | ||
import styles from '../styles/styles'; | ||
import withWindowDimensions, {windowDimensionsPropTypes} from './withWindowDimensions'; | ||
import MenuItem from './MenuItem'; | ||
import CONST from '../CONST'; | ||
import {propTypes as ModalPropTypes} from './Modal/ModalPropTypes'; | ||
|
||
const propTypes = { | ||
// Callback to fire on request to modal close | ||
onClose: PropTypes.func.isRequired, | ||
|
||
// State that determines whether to display the create menu or not | ||
isVisible: PropTypes.bool.isRequired, | ||
|
||
// Callback to fire when a CreateMenu item is selected | ||
onItemSelected: PropTypes.func.isRequired, | ||
|
||
// Gives the type of the modal | ||
popOverType: ModalPropTypes.type, | ||
|
||
// Menu items to be rendered on the list | ||
menuItems: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
icon: PropTypes.func.isRequired, | ||
text: PropTypes.string.isRequired, | ||
onSelected: PropTypes.func.isRequired, | ||
}), | ||
).isRequired, | ||
|
||
...windowDimensionsPropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
popOverType: CONST.MODAL.MODAL_TYPE.POPOVER_LEFT_DOCKED, | ||
}; | ||
|
||
class CreateMenu extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
this.onModalHide = () => {}; | ||
this.setOnModalHide = this.setOnModalHide.bind(this); | ||
this.resetOnModalHide = this.resetOnModalHide.bind(this); | ||
} | ||
|
||
/** | ||
* Sets a new function to execute when the modal hides | ||
* @param {Function} callback The function to be called on modal hide | ||
*/ | ||
setOnModalHide(callback) { | ||
this.onModalHide = callback; | ||
} | ||
|
||
/** | ||
* After the modal hides, reset the onModalHide to an empty function | ||
*/ | ||
resetOnModalHide() { | ||
this.onModalHide = () => {}; | ||
} | ||
|
||
render() { | ||
return ( | ||
<Popover | ||
onClose={this.props.onClose} | ||
isVisible={this.props.isVisible} | ||
onModalHide={() => { | ||
this.onModalHide(); | ||
this.resetOnModalHide(); | ||
}} | ||
popOverType={this.props.popOverType} | ||
> | ||
<View style={this.props.isSmallScreenWidth ? {} : styles.createMenuContainer}> | ||
{this.props.menuItems.map(({ | ||
icon, | ||
text, | ||
onSelected = () => {}, | ||
}) => ( | ||
<MenuItem | ||
key={text} | ||
icon={icon} | ||
title={text} | ||
onPress={() => { | ||
this.props.onItemSelected(); | ||
this.setOnModalHide(onSelected); | ||
}} | ||
/> | ||
))} | ||
</View> | ||
</Popover> | ||
); | ||
} | ||
} | ||
|
||
CreateMenu.propTypes = propTypes; | ||
CreateMenu.defaultProps = defaultProps; | ||
CreateMenu.displayName = 'CreateMenu'; | ||
export default withWindowDimensions(CreateMenu); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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