Skip to content

Commit

Permalink
Merge pull request #7580 from mananjadhav/feat/emoji-picker-in-edit-m…
Browse files Browse the repository at this point in the history
…essage

PR 3: Adding EmojiPicker to the Edit Comment
  • Loading branch information
Julesssss authored Mar 30, 2022
2 parents 68ba8aa + dac1391 commit e7565c1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 9 deletions.
27 changes: 18 additions & 9 deletions src/components/EmojiPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class EmojiPicker extends React.Component {
this.showEmojiPicker = this.showEmojiPicker.bind(this);
this.selectEmoji = this.selectEmoji.bind(this);
this.measureEmojiPopoverAnchorPosition = this.measureEmojiPopoverAnchorPosition.bind(this);
this.measureEmojiPopoverAnchorPositionAndUpdateState = this.measureEmojiPopoverAnchorPositionAndUpdateState.bind(this);
this.focusEmojiSearchInput = this.focusEmojiSearchInput.bind(this);
this.measureContent = this.measureContent.bind(this);
this.onModalHide = () => {};
Expand All @@ -30,7 +31,7 @@ class EmojiPicker extends React.Component {
}

componentDidMount() {
this.emojiPopoverDimensionListener = Dimensions.addEventListener('change', this.measureEmojiPopoverAnchorPosition);
this.emojiPopoverDimensionListener = Dimensions.addEventListener('change', this.measureEmojiPopoverAnchorPositionAndUpdateState);
}

componentDidUpdate(prevProps, prevState) {
Expand Down Expand Up @@ -62,6 +63,7 @@ class EmojiPicker extends React.Component {
}

hideEmojiPicker() {
this.emojiPopoverAnchor = null;
this.setState({isEmojiPickerVisible: false});
}

Expand All @@ -77,18 +79,24 @@ class EmojiPicker extends React.Component {
this.onEmojiSelected = onEmojiSelected;
this.emojiPopoverAnchor = emojiPopoverAnchor;

this.setState({isEmojiPickerVisible: true});
this.measureEmojiPopoverAnchorPosition();
this.measureEmojiPopoverAnchorPosition().then((emojiPopoverAnchorPosition) => {
this.setState({isEmojiPickerVisible: true, emojiPopoverAnchorPosition});
});
}

measureEmojiPopoverAnchorPosition() {
if (!this.emojiPopoverAnchor) {
return;
}
return new Promise((resolve) => {
if (!this.emojiPopoverAnchor) {
return resolve({horizontal: 0, vertical: 0});
}
this.emojiPopoverAnchor.measureInWindow((x, y, width) => resolve({horizontal: x + width, vertical: y}));
});
}

this.emojiPopoverAnchor.measureInWindow((x, y, width) => this.setState({
emojiPopoverAnchorPosition: {horizontal: x + width, vertical: y},
}));
measureEmojiPopoverAnchorPositionAndUpdateState() {
this.measureEmojiPopoverAnchorPosition().then((emojiPopoverAnchorPosition) => {
this.setState({emojiPopoverAnchorPosition});
});
}

/**
Expand Down Expand Up @@ -125,6 +133,7 @@ class EmojiPicker extends React.Component {
onModalShow={this.focusEmojiSearchInput}
onModalHide={this.onModalHide}
hideModalContentWhileAnimating
shouldSetModalVisibility={false}
animationInTiming={1}
animationOutTiming={1}
anchorPosition={{
Expand Down
11 changes: 11 additions & 0 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React, {Component} from 'react';
import {withOnyx} from 'react-native-onyx';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import CONST from '../../../CONST';
Expand Down Expand Up @@ -144,6 +145,8 @@ class ReportActionItem extends Component {
reportID={this.props.reportID}
index={this.props.index}
ref={el => this.textInput = el}
report={this.props.report}
blockedFromConcierge={this.props.blockedFromConcierge}
/>
);
}
Expand Down Expand Up @@ -211,4 +214,12 @@ export default compose(
return lodashGet(drafts, draftKey, '');
},
}),
withOnyx({
blockedFromConcierge: {
key: ONYXKEYS.NVP_BLOCKED_FROM_CONCIERGE,
},
report: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`,
},
}),
)(ReportActionItem);
45 changes: 45 additions & 0 deletions src/pages/home/report/ReportActionItemMessageEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ import withLocalize, {withLocalizePropTypes} from '../../../components/withLocal
import Button from '../../../components/Button';
import ReportActionComposeFocusManager from '../../../libs/ReportActionComposeFocusManager';
import compose from '../../../libs/compose';
import EmojiPickerButton from '../../../components/EmojiPicker/EmojiPickerButton';
import * as ReportUtils from '../../../libs/reportUtils';
import * as ReportActionContextMenu from './ContextMenu/ReportActionContextMenu';
import VirtualKeyboard from '../../../libs/VirtualKeyboard';
import * as User from '../../../libs/actions/User';

const propTypes = {
/** All the data of the action */
Expand All @@ -33,6 +36,18 @@ const propTypes = {
/** A ref to forward to the text input */
forwardedRef: PropTypes.func,

/** The report currently being looked at */
report: PropTypes.shape({
/** Participants associated with current report */
participants: PropTypes.arrayOf(PropTypes.string),
}),

// The NVP describing a user's block status
blockedFromConcierge: PropTypes.shape({
// The date that the user will be unblocked
expiresAt: PropTypes.string,
}),

/** Window Dimensions Props */
...windowDimensionsPropTypes,

Expand All @@ -42,6 +57,8 @@ const propTypes = {

const defaultProps = {
forwardedRef: () => {},
report: {},
blockedFromConcierge: {},
};

class ReportActionItemMessageEdit extends React.Component {
Expand All @@ -53,6 +70,7 @@ class ReportActionItemMessageEdit extends React.Component {
this.publishDraft = this.publishDraft.bind(this);
this.triggerSaveOrCancel = this.triggerSaveOrCancel.bind(this);
this.onSelectionChange = this.onSelectionChange.bind(this);
this.addEmojiToTextBox = this.addEmojiToTextBox.bind(this);

const parser = new ExpensiMark();
const draftMessage = parser.htmlToMarkdown(this.props.draftMessage);
Expand Down Expand Up @@ -139,6 +157,21 @@ class ReportActionItemMessageEdit extends React.Component {
this.deleteDraft();
}

/**
* @param {String} emoji
*/
addEmojiToTextBox(emoji) {
const newComment = this.state.draft.slice(0, this.state.selection.start)
+ emoji + this.state.draft.slice(this.state.selection.end, this.state.draft.length);
this.setState(prevState => ({
selection: {
start: prevState.selection.start + emoji.length,
end: prevState.selection.start + emoji.length,
},
}));
this.updateDraft(newComment);
}

/**
* Key event handlers that short cut to saving/canceling.
*
Expand All @@ -155,6 +188,10 @@ class ReportActionItemMessageEdit extends React.Component {
}

render() {
const shouldDisableEmojiPicker = (ReportUtils.chatIncludesConcierge(this.props.report)
&& User.isBlockedFromConcierge(this.props.blockedFromConcierge))
|| ReportUtils.isArchivedRoom(this.props.report);

return (
<View style={styles.chatItemMessage}>
<View style={[styles.chatItemComposeBox, styles.flexRow, styles.chatItemComposeBoxColor]}>
Expand All @@ -176,6 +213,14 @@ class ReportActionItemMessageEdit extends React.Component {
selection={this.state.selection}
onSelectionChange={this.onSelectionChange}
/>
<View style={styles.editChatItemEmojiWrapper}>
<EmojiPickerButton
isDisabled={shouldDisableEmojiPicker}
onModalHide={() => InteractionManager.runAfterInteractions(() => this.textInput.focus())}
onEmojiSelected={this.addEmojiToTextBox}
/>
</View>

</View>
<View style={[styles.flexRow, styles.mt1]}>
<Button
Expand Down
4 changes: 4 additions & 0 deletions src/styles/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,6 +1417,10 @@ const styles = {
justifyContent: 'center',
},

editChatItemEmojiWrapper: {
marginRight: 3,
},

hoveredButton: {
backgroundColor: themeColors.buttonHoveredBG,
},
Expand Down

0 comments on commit e7565c1

Please sign in to comment.