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

feat: Dynamic emoji size #3561

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 2 additions & 9 deletions src/pages/home/report/EmojiPickerMenu/dynamicEmojiSize.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import styleVariables from '../../../../styles/variables';

const dynamicEmojiSize = (windowWidth) => {
if (windowWidth <= 320) {
return styleVariables.fontSizeSmall;
}
if (
windowWidth <= 480
) {
return styleVariables.fontSizeNormal;
}

if (windowWidth <= 320) { return styleVariables.fontSizeSmall; }
if (windowWidth <= 480) { return styleVariables.fontSizeNormal; }
Copy link
Contributor

Choose a reason for hiding this comment

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

oh sorry for the confusion, i didn't mean the whole line, just the if condition, i.e.,

if (windowWidth <= 480) {
    return styleVariables.fontSizeNormal;
}

That would match our examples in the style guide. Could you make the same changes to the if conditions in your file.

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

return styleVariables.fontSizeLarge;
};

Expand Down
19 changes: 10 additions & 9 deletions src/pages/home/report/EmojiPickerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,23 @@ class EmojiPickerMenu extends Component {
this.setupEventHandlers();
}


componentDidUpdate(prevProps) {
if (
this.props.windowWidth !== prevProps.windowWidth
) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
emojiSize: dynamicEmojiSize(this.props.windowWidth),
});
}
if (this.props.windowWidth !== prevProps.windowWidth) { this.setDynamicEmojiSize(); }
}

componentWillUnmount() {
this.cleanupEventHandlers();
}

/**
* Sets emoji size dynamically based on the window width
*/
setDynamicEmojiSize() {
this.setState({
emojiSize: dynamicEmojiSize(this.props.windowWidth),
});
}

/**
* Setup and attach keypress/mouse handlers for highlight navigation.
*/
Expand Down
18 changes: 10 additions & 8 deletions src/pages/home/report/EmojiPickerMenu/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const propTypes = {
/** Function to add the selected emoji to the main compose text input */
onEmojiSelected: PropTypes.func.isRequired,

/** Props related to the dimensions of the window */
...windowDimensionsPropTypes,
Copy link
Contributor

Choose a reason for hiding this comment

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

NAB: I see there are many places in our code where this is prop is not documented but as per our style guide it would be nice if you include a JS comment doc for this for consistency.

};

Expand Down Expand Up @@ -41,16 +42,17 @@ class EmojiPickerMenu extends Component {
}

componentDidUpdate(prevProps) {
if (
this.props.windowWidth !== prevProps.windowWidth
) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState({
emojiSize: dynamicEmojiSize(this.props.windowWidth),
});
}
if (this.props.windowWidth !== prevProps.windowWidth) { this.setDynamicEmojiSize(); }
}

/**
* Sets emoji size dynamically based on the window width
*/
setDynamicEmojiSize() {
this.setState({
emojiSize: dynamicEmojiSize(this.props.windowWidth),
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

remove unnecessary line break

/**
* Given an emoji item object, render a component based on its type.
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/EmojiPickerMenuItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const propTypes = {
/** Whether this menu item is currently highlighted or not */
isHighlighted: PropTypes.bool.isRequired,

/** Size of the emoji item */
size: PropTypes.number.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

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

missing JS doc.

};

Expand Down