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

migrated ThreeDotsMenu/index.js to a functional component #24017

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 47 additions & 56 deletions src/components/ThreeDotsMenu/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Component} from 'react';
import React, {useState, useRef} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import _ from 'underscore';
Expand Down Expand Up @@ -61,65 +61,56 @@ const defaultProps = {
},
};
bondydaa marked this conversation as resolved.
Show resolved Hide resolved

class ThreeDotsMenu extends Component {
constructor(props) {
super(props);

this.hidePopoverMenu = this.hidePopoverMenu.bind(this);
this.showPopoverMenu = this.showPopoverMenu.bind(this);
this.state = {
isPopupMenuVisible: false,
};
this.button = null;
}

showPopoverMenu() {
this.setState({isPopupMenuVisible: true});
}

hidePopoverMenu() {
this.setState({isPopupMenuVisible: false});
}

render() {
return (
<>
<View>
<Tooltip text={this.props.translate(this.props.iconTooltip)}>
<PressableWithoutFeedback
onPress={() => {
this.showPopoverMenu();
if (this.props.onIconPress) {
this.props.onIconPress();
}
}}
ref={(el) => (this.button = el)}
style={[styles.touchableButtonImage, ...this.props.iconStyles]}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={this.props.translate(this.props.iconTooltip)}
>
<Icon
src={this.props.icon}
fill={this.props.iconFill}
/>
</PressableWithoutFeedback>
</Tooltip>
</View>
<PopoverMenu
onClose={this.hidePopoverMenu}
isVisible={this.state.isPopupMenuVisible}
anchorPosition={this.props.anchorPosition}
anchorAlignment={this.props.anchorAlignment}
onItemSelected={this.hidePopoverMenu}
menuItems={this.props.menuItems}
/>
</>
);
}
function ThreeDotsMenu({iconTooltip, icon, iconFill, iconStyles, onIconPress, menuItems, anchorPosition, anchorAlignment, translate}) {
const [isPopupMenuVisible, setPopupMenuVisible] = useState(false);
const buttonRef = useRef(null);

const showPopoverMenu = () => {
setPopupMenuVisible(true);
};

const hidePopoverMenu = () => {
setPopupMenuVisible(false);
};

return (
<>
<View>
<Tooltip text={translate(iconTooltip)}>
<PressableWithoutFeedback
onPress={() => {
showPopoverMenu();
if (onIconPress) {
onIconPress();
}
}}
ref={buttonRef}
style={[styles.touchableButtonImage, ...iconStyles]}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate(iconTooltip)}
>
<Icon
src={icon}
fill={iconFill}
/>
</PressableWithoutFeedback>
</Tooltip>
</View>
<PopoverMenu
onClose={hidePopoverMenu}
isVisible={isPopupMenuVisible}
anchorPosition={anchorPosition}
anchorAlignment={anchorAlignment}
onItemSelected={hidePopoverMenu}
menuItems={menuItems}
/>
</>
);
}

ThreeDotsMenu.propTypes = propTypes;
ThreeDotsMenu.defaultProps = defaultProps;
ThreeDotsMenu.displayName = 'ThreeDotsMenu';

export default withLocalize(ThreeDotsMenu);

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the useLocalize hook instead @adityaaa-r.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll also remove that from the props.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Expand Down
Loading