From 403db1d46e7e00c492ac34510bec105c4cdbeaa9 Mon Sep 17 00:00:00 2001 From: ewwwwwwww Date: Sat, 9 Jul 2022 10:52:08 -0700 Subject: [PATCH] mobile fixes --- .../components/emoji_picker_dropdown.tsx | 53 +++++++++---------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/app/soapbox/features/emoji/components/emoji_picker_dropdown.tsx b/app/soapbox/features/emoji/components/emoji_picker_dropdown.tsx index 18ba3b413..e20313b30 100644 --- a/app/soapbox/features/emoji/components/emoji_picker_dropdown.tsx +++ b/app/soapbox/features/emoji/components/emoji_picker_dropdown.tsx @@ -7,6 +7,7 @@ import { usePopper } from 'react-popper'; import { IconButton } from 'soapbox/components/ui'; import { useSettings } from 'soapbox/hooks'; +import { isMobile } from 'soapbox/is_mobile'; import { buildCustomEmojis } from '../../emoji'; import { EmojiPicker as EmojiPickerAsync } from '../../ui/util/async-components'; @@ -79,8 +80,9 @@ const EmojiPickerDropdown: React.FC = ({ custom_emojis, fr const [visible, setVisible] = useState(false); const [loading, setLoading] = useState(false); + const placement = condensed ? 'bottom-start' : 'top-start'; const { styles, attributes, update } = usePopper(popperReference, popperElement, { - placement: condensed ? 'bottom-start' : 'top-start', + placement: isMobile(window.innerWidth) ? 'auto' : placement, }); const handleToggle = () => { @@ -133,14 +135,15 @@ const EmojiPickerDropdown: React.FC = ({ custom_emojis, fr // }, // }; // }; - + useEffect(() => { document.addEventListener('click', handleDocClick, false); document.addEventListener('touchend', handleDocClick, listenerOptions); return function cleanup() { - document.removeEventListener('click', handleDocClick); - document.removeEventListener('touchend', handleDocClick); + document.removeEventListener('click', handleDocClick, false); + // @ts-ignore + document.removeEventListener('touchend', handleDocClick, listenerOptions); }; }); @@ -158,27 +161,10 @@ const EmojiPickerDropdown: React.FC = ({ custom_emojis, fr } }, [visible]); - let Popup; - - if (loading) { - Popup = () =>
; - } else { - Popup = () => ( - - ); - } + // TODO: move to class + const style = !isMobile(window.innerWidth) ? styles.popper : { + ...styles.popper, width: '100%', + }; return (
@@ -204,12 +190,25 @@ const EmojiPickerDropdown: React.FC = ({ custom_emojis, fr 'z-1000': true, })} ref={setPopperElement} - style={styles.popper} + style={style} {...attributes.popper} > {visible && ( - + {!loading && ( + + )} )}
,