Skip to content

Commit

Permalink
Merge pull request #30048 from tienifr/fix/28698
Browse files Browse the repository at this point in the history
fix: 28698 Tapping emoji picker the message section is selected and shown
  • Loading branch information
marcochavezf authored Oct 23, 2023
2 parents 3e94d84 + 9f3ea4d commit d2ab5a7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
13 changes: 6 additions & 7 deletions src/components/EmojiPicker/EmojiPicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ import EmojiPickerMenu from './EmojiPickerMenu';
import CONST from '../../CONST';
import styles from '../../styles/styles';
import PopoverWithMeasuredContent from '../PopoverWithMeasuredContent';
import withWindowDimensions, {windowDimensionsPropTypes} from '../withWindowDimensions';
import withViewportOffsetTop from '../withViewportOffsetTop';
import compose from '../../libs/compose';
import * as StyleUtils from '../../styles/StyleUtils';
import calculateAnchorPosition from '../../libs/calculateAnchorPosition';
import useWindowDimensions from '../../hooks/useWindowDimensions';

const DEFAULT_ANCHOR_ORIGIN = {
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
};

const propTypes = {
...windowDimensionsPropTypes,
viewportOffsetTop: PropTypes.number.isRequired,
};

Expand All @@ -34,6 +32,7 @@ const EmojiPicker = forwardRef((props, ref) => {
const onModalHide = useRef(() => {});
const onEmojiSelected = useRef(() => {});
const emojiSearchInput = useRef();
const {isSmallScreenWidth, windowHeight} = useWindowDimensions();

/**
* Show the emoji picker menu.
Expand Down Expand Up @@ -125,7 +124,7 @@ const EmojiPicker = forwardRef((props, ref) => {
const emojiPopoverDimensionListener = Dimensions.addEventListener('change', () => {
if (!emojiPopoverAnchor.current) {
// In small screen width, the window size change might be due to keyboard open/hide, we should avoid hide EmojiPicker in those cases
if (isEmojiPickerVisible && !props.isSmallScreenWidth) {
if (isEmojiPickerVisible && !isSmallScreenWidth) {
hideEmojiPicker();
}
return;
Expand All @@ -137,7 +136,7 @@ const EmojiPicker = forwardRef((props, ref) => {
return () => {
emojiPopoverDimensionListener.remove();
};
}, [isEmojiPickerVisible, props.isSmallScreenWidth, emojiPopoverAnchorOrigin]);
}, [isEmojiPickerVisible, isSmallScreenWidth, emojiPopoverAnchorOrigin]);

// 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
Expand All @@ -162,7 +161,7 @@ const EmojiPicker = forwardRef((props, ref) => {
height: CONST.EMOJI_PICKER_SIZE.HEIGHT,
}}
anchorAlignment={emojiPopoverAnchorOrigin}
outerStyle={StyleUtils.getOuterModalStyle(props.windowHeight, props.viewportOffsetTop)}
outerStyle={StyleUtils.getOuterModalStyle(windowHeight, props.viewportOffsetTop)}
innerContainerStyle={styles.popoverInnerContainer}
avoidKeyboard
>
Expand All @@ -176,4 +175,4 @@ const EmojiPicker = forwardRef((props, ref) => {

EmojiPicker.propTypes = propTypes;
EmojiPicker.displayName = 'EmojiPicker';
export default compose(withViewportOffsetTop, withWindowDimensions)(EmojiPicker);
export default withViewportOffsetTop(EmojiPicker);
10 changes: 4 additions & 6 deletions src/components/EmojiPicker/EmojiPickerMenu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as StyleUtils from '../../../styles/StyleUtils';
import emojiAssets from '../../../../assets/emojis';
import EmojiPickerMenuItem from '../EmojiPickerMenuItem';
import Text from '../../Text';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../withWindowDimensions';
import withLocalize, {withLocalizePropTypes} from '../../withLocalize';
import compose from '../../../libs/compose';
import getOperatingSystem from '../../../libs/getOperatingSystem';
Expand All @@ -23,6 +22,7 @@ import CategoryShortcutBar from '../CategoryShortcutBar';
import TextInput from '../../TextInput';
import isEnterWhileComposition from '../../../libs/KeyboardShortcut/isEnterWhileComposition';
import canFocusInputOnScreenFocus from '../../../libs/canFocusInputOnScreenFocus';
import useWindowDimensions from '../../../hooks/useWindowDimensions';

const propTypes = {
/** Function to add the selected emoji to the main compose text input */
Expand All @@ -37,9 +37,6 @@ const propTypes = {
// eslint-disable-next-line react/forbid-prop-types
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.object),

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

...withLocalizePropTypes,
};

Expand All @@ -52,7 +49,9 @@ const defaultProps = {
const throttleTime = Browser.isMobile() ? 200 : 50;

function EmojiPickerMenu(props) {
const {forwardedRef, frequentlyUsedEmojis, preferredSkinTone, onEmojiSelected, preferredLocale, isSmallScreenWidth, windowHeight, translate} = props;
const {forwardedRef, frequentlyUsedEmojis, preferredSkinTone, onEmojiSelected, preferredLocale, translate} = props;

const {isSmallScreenWidth, windowHeight} = useWindowDimensions();

// Ref for the emoji search input
const searchInputRef = useRef(null);
Expand Down Expand Up @@ -528,7 +527,6 @@ EmojiPickerMenu.propTypes = propTypes;
EmojiPickerMenu.defaultProps = defaultProps;

export default compose(
withWindowDimensions,
withLocalize,
withOnyx({
preferredSkinTone: {
Expand Down

0 comments on commit d2ab5a7

Please sign in to comment.