-
Notifications
You must be signed in to change notification settings - Fork 3.9k
PR 1: Moving EmojiPicker as an Independent Component #6977
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
Merged
puneetlath
merged 32 commits into
Expensify:main
from
mananjadhav:feat/edit-comment-emoji-picker
Feb 9, 2022
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
77e670f
feat: Moved EmojiPicker into a fresh component
mananjadhav fe803e7
fix: Temp removed EmojiUtils ref
mananjadhav 9caf347
fix: Added getSkinToneEmoji to utils
mananjadhav 4484bb2
fix: Added getSkinToneEmojiFromIndex as a separate lib
mananjadhav 3be92ed
fix: Renamed components and updated refs
mananjadhav 186bc14
fix: Updated refs for picker
mananjadhav a445cc7
fix: Added emoji selection function
mananjadhav 33c8117
chore: Code cleanup
mananjadhav 3b5f410
fix: Reordered function and fixed import typo
mananjadhav 223d1bb
fix: Changed prop to optional
mananjadhav 2c411ac
fix: Added EmojiPicker to the edit comment
mananjadhav 8ec4008
fix: Corrected imports
mananjadhav 48ceaf1
fix: Added background to EmojiPicker
mananjadhav fd76442
fix: Added props to Edit component
mananjadhav 14d23c2
fix: Moved isBlockedFromConcierge to utils
mananjadhav e8000a5
fix: Added onBeforeShowEmojiPicker
mananjadhav 8d88ad8
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav 0ca63c4
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav 43cdc7e
fix: Removed emoji code from edit mode
mananjadhav a870c0f
fix: Removed Emoji code from Edit Message
mananjadhav 2e3f792
fix: Removed report object to rollback for edit mode
mananjadhav 5199d9d
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav f2e3d4d
fix: Removed extra space
mananjadhav 0b84ee6
fix: comment style changes
mananjadhav 1d497e1
fix: Added type checks and removed unwanted inits
mananjadhav 3c33ca6
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav b5bdb8c
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav 2e1c842
feat: Updated isBlockedFromConcierge function
mananjadhav a116525
feat: Removed isBlockedFromConcierge function from ReportUtils
mananjadhav 9edf829
feat: Update references for isBlockedFromConcierge
mananjadhav 25a6a89
feat: Added comment for chatIncludesConcierge
mananjadhav 30e91db
feat: Updated jsdocs
mananjadhav 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
16 changes: 8 additions & 8 deletions
16
...me/report/EmojiPickerMenu/index.native.js → ...ojiPicker/EmojiPickerMenu/index.native.js
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
10 changes: 5 additions & 5 deletions
10
src/pages/home/report/EmojiPickerMenuItem.js → ...onents/EmojiPicker/EmojiPickerMenuItem.js
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
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
2 changes: 1 addition & 1 deletion
2
...jiPickerMenu/getSkinToneEmojiFromIndex.js → .../EmojiPicker/getSkinToneEmojiFromIndex.js
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
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,199 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import {Pressable, Dimensions} from 'react-native'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import _ from 'underscore'; | ||
| import compose from '../../libs/compose'; | ||
| import Popover from '../Popover'; | ||
| import Tooltip from '../Tooltip'; | ||
| import Icon from '../Icon'; | ||
| import ONYXKEYS from '../../ONYXKEYS'; | ||
| import EmojiPickerMenu from './EmojiPickerMenu'; | ||
| import * as StyleUtils from '../../styles/StyleUtils'; | ||
| import * as Expensicons from '../Icon/Expensicons'; | ||
| import * as User from '../../libs/actions/User'; | ||
| import * as EmojiUtils from '../../libs/EmojiUtils'; | ||
| import getButtonState from '../../libs/getButtonState'; | ||
| import styles from '../../styles/styles'; | ||
| import CONST from '../../CONST'; | ||
| import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions'; | ||
| import withLocalize, {withLocalizePropTypes} from '../withLocalize'; | ||
|
|
||
| const propTypes = { | ||
| /** Flag to disable the emoji picker button */ | ||
| isDisabled: PropTypes.bool, | ||
|
|
||
| /** Callback on emoji popover hide */ | ||
| onModalHide: PropTypes.func, | ||
|
|
||
| /** Callback on before showing emoji picker */ | ||
| onBeforeShowEmojiPicker: PropTypes.func, | ||
|
puneetlath marked this conversation as resolved.
|
||
|
|
||
| /** Callback on emoji selection */ | ||
| onEmojiSelected: PropTypes.func.isRequired, | ||
| ...windowDimensionsPropTypes, | ||
| ...withLocalizePropTypes, | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| isDisabled: false, | ||
| onModalHide: () => {}, | ||
| onBeforeShowEmojiPicker: () => {}, | ||
| }; | ||
|
|
||
| class EmojiPicker extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
|
|
||
| this.hideEmojiPicker = this.hideEmojiPicker.bind(this); | ||
| this.showEmojiPicker = this.showEmojiPicker.bind(this); | ||
| this.selectEmoji = this.selectEmoji.bind(this); | ||
| this.measureEmojiPopoverAnchorPosition = this.measureEmojiPopoverAnchorPosition.bind(this); | ||
| this.setPreferredSkinTone = this.setPreferredSkinTone.bind(this); | ||
| this.focusEmojiSearchInput = this.focusEmojiSearchInput.bind(this); | ||
|
|
||
| this.state = { | ||
| isEmojiPickerVisible: false, | ||
|
|
||
| // The horizontal and vertical position (relative to the window) where the emoji popover will display. | ||
| emojiPopoverAnchorPosition: { | ||
| horizontal: 0, | ||
| vertical: 0, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| this.emojiPopoverDimensionListener = Dimensions.addEventListener('change', this.measureEmojiPopoverAnchorPosition); | ||
| } | ||
|
|
||
| componentWillUnmount() { | ||
| if (!this.emojiPopoverDimensionListener) { | ||
| return; | ||
| } | ||
| this.emojiPopoverDimensionListener.remove(); | ||
| } | ||
|
|
||
| /** | ||
| * Update preferredSkinTone and sync with Onyx, NVP. | ||
| * @param {Number|String} skinTone | ||
| */ | ||
| setPreferredSkinTone(skinTone) { | ||
| if (skinTone === this.props.preferredSkinTone) { | ||
| return; | ||
| } | ||
|
|
||
| User.setPreferredSkinTone(skinTone); | ||
| } | ||
|
|
||
| /** | ||
| * Callback for the emoji picker to add whatever emoji is chosen into the main input | ||
| * | ||
| * @param {String} emoji | ||
| * @param {Object} emojiObject | ||
| */ | ||
| selectEmoji(emoji, emojiObject) { | ||
| EmojiUtils.addToFrequentlyUsedEmojis(this.props.frequentlyUsedEmojis, emojiObject); | ||
| this.hideEmojiPicker(); | ||
| this.props.onEmojiSelected(emoji); | ||
| } | ||
|
|
||
| hideEmojiPicker() { | ||
| this.setState({isEmojiPickerVisible: false}); | ||
| } | ||
|
|
||
| showEmojiPicker() { | ||
| if (_.isFunction(this.props.onBeforeShowEmojiPicker)) { | ||
| this.props.onBeforeShowEmojiPicker(); | ||
| } | ||
| this.setState({isEmojiPickerVisible: true}); | ||
| } | ||
|
|
||
| measureEmojiPopoverAnchorPosition() { | ||
| if (!this.emojiPopoverAnchor) { | ||
| return; | ||
| } | ||
|
|
||
| this.emojiPopoverAnchor.measureInWindow((x, y, width) => this.setState({ | ||
| emojiPopoverAnchorPosition: {horizontal: x + width, vertical: y}, | ||
| })); | ||
| } | ||
|
|
||
| /** | ||
| * Focus the search input in the emoji picker. | ||
| */ | ||
| focusEmojiSearchInput() { | ||
| if (!this.emojiSearchInput) { | ||
| return; | ||
| } | ||
| this.emojiSearchInput.focus(); | ||
| } | ||
|
|
||
| render() { | ||
| return ( | ||
| <> | ||
| { | ||
|
|
||
|
mananjadhav marked this conversation as resolved.
|
||
| // There is no way to disable animations and they are really laggy, because there are so many | ||
| // emojis. The best alternative is to set it to 1ms so it just "pops" in and out | ||
| } | ||
| <Popover | ||
| isVisible={this.state.isEmojiPickerVisible} | ||
| onClose={this.hideEmojiPicker} | ||
| onModalShow={this.focusEmojiSearchInput} | ||
| onModalHide={this.props.onModalHide} | ||
| hideModalContentWhileAnimating | ||
| animationInTiming={1} | ||
| animationOutTiming={1} | ||
| anchorPosition={{ | ||
| bottom: this.props.windowHeight - this.state.emojiPopoverAnchorPosition.vertical, | ||
| left: this.state.emojiPopoverAnchorPosition.horizontal - CONST.EMOJI_PICKER_SIZE, | ||
| }} | ||
| > | ||
| <EmojiPickerMenu | ||
| onEmojiSelected={this.selectEmoji} | ||
| ref={el => this.emojiSearchInput = el} | ||
| preferredSkinTone={this.props.preferredSkinTone} | ||
| updatePreferredSkinTone={this.setPreferredSkinTone} | ||
| frequentlyUsedEmojis={this.props.frequentlyUsedEmojis} | ||
| /> | ||
| </Popover> | ||
| <Pressable | ||
| style={({hovered, pressed}) => ([ | ||
| styles.chatItemEmojiButton, | ||
| StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed)), | ||
| ])} | ||
| ref={el => this.emojiPopoverAnchor = el} | ||
| onLayout={this.measureEmojiPopoverAnchorPosition} | ||
| onPress={this.showEmojiPicker} | ||
| disabled={this.props.isDisabled} | ||
| > | ||
| {({hovered, pressed}) => ( | ||
| <Tooltip text={this.props.translate('reportActionCompose.emoji')}> | ||
| <Icon | ||
| src={Expensicons.Emoji} | ||
| fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed))} | ||
| /> | ||
| </Tooltip> | ||
| )} | ||
| </Pressable> | ||
| </> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| EmojiPicker.propTypes = propTypes; | ||
| EmojiPicker.defaultProps = defaultProps; | ||
|
|
||
| export default compose( | ||
| withWindowDimensions, | ||
| withLocalize, | ||
| withOnyx({ | ||
| preferredSkinTone: { | ||
| key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, | ||
| }, | ||
| frequentlyUsedEmojis: { | ||
| key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, | ||
| }, | ||
| }), | ||
| )(EmojiPicker); | ||
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
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.