-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Display create menu within the chat area and add bottom up transition. #2222
Changes from all commits
9d74c30
1068005
ee27ea5
0be1c12
4bcd10f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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'; | ||
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 know class components don't need 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. Do you know? |
||
export default withWindowDimensions(CreateMenu); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ const propTypes = { | |
bottom: PropTypes.number, | ||
left: PropTypes.number, | ||
}).isRequired, | ||
|
||
// Describes what type of pop over is it - based on the position | ||
popOverType: modalPropTypes.type, | ||
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. This is missing an inline comment to explain it. |
||
}; | ||
|
||
const defaultProps = { | ||
|
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.
Is there a reason this is a
PureComponent
instead of just a normalComponent
?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.
The pure component was implemented beforehand, not sure why it was done though.
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.
OK, I'll check on that and dig a little deeper. No need to let this block your PR since you didn't add it.