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

PR 3: Adding EmojiPicker to the Edit Comment #7580

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
105e260
feat: Added EmojiPicker in Edit Comment
mananjadhav Feb 4, 2022
cfe4f80
feat: Added props to ReportActionItem
mananjadhav Feb 4, 2022
9e069e9
feat: Removed onBeforeShowEmojiPicker for EmojiPicker
mananjadhav Feb 4, 2022
9106221
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Feb 22, 2022
401fc2b
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Feb 22, 2022
f1d8e58
feat: Updated condition for edit message emojipicker
mananjadhav Feb 22, 2022
15ac99b
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Mar 5, 2022
6f34743
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Mar 8, 2022
3fd3690
fix: show emojipicker only aftr anchor position is measured
mananjadhav Mar 8, 2022
74ea882
fix: add focus to edit comment on emoji selection
mananjadhav Mar 8, 2022
9317bcb
fix: code cleanup
mananjadhav Mar 8, 2022
6d5ef67
fix: Removed extra space
mananjadhav Mar 9, 2022
f7043d6
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Mar 14, 2022
b5d1258
fix: split measure anchor position and update state
mananjadhav Mar 14, 2022
202cecd
fix: added this binding to measure function
mananjadhav Mar 14, 2022
eabc817
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Mar 23, 2022
38a602e
fix: added margin to emoji button in edit mode
mananjadhav Mar 23, 2022
dac1391
Merge branch 'main' of https://github.com/mananjadhav/App into feat/e…
mananjadhav Mar 24, 2022
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
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);
Julesssss marked this conversation as resolved.
Show resolved Hide resolved
}

componentWillUnmount() {
Expand All @@ -53,6 +54,7 @@ class EmojiPicker extends React.Component {
}

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

Expand All @@ -68,18 +70,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 @@ -116,6 +124,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())}
Copy link
Contributor

Choose a reason for hiding this comment

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

Coming from #30119

If, at the beginning, a composer's emoji picker is open, opening some other emoji picker results in a race:

  • Here, we focus the composer because the original emoji picker hides
  • The other emoji picker focuses its search field

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 @@ -1413,6 +1413,10 @@ const styles = {
justifyContent: 'center',
},

editChatItemEmojiWrapper: {
marginRight: 3,
},

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