Skip to content

Commit

Permalink
Add optional portal prop to emoji picker
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Dec 20, 2024
1 parent 20fa7fe commit 03eb1d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
16 changes: 6 additions & 10 deletions src/screens/Messages/components/MessagesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {ChatEmptyPill} from '#/components/dms/ChatEmptyPill'
import {MessageItem} from '#/components/dms/MessageItem'
import {NewMessagesPill} from '#/components/dms/NewMessagesPill'
import {Loader} from '#/components/Loader'
import {Portal} from '#/components/Portal'
import {Text} from '#/components/Typography'
import {MessageInputEmbed, useMessageEmbed} from './MessageInputEmbed'

Expand Down Expand Up @@ -449,15 +448,12 @@ export function MessagesList({
</Animated.View>

{isWeb && (
<Portal>
<EmojiPicker
pinToTop
state={emojiPickerState}
close={() =>
setEmojiPickerState(prev => ({...prev, isOpen: false}))
}
/>
</Portal>
<EmojiPicker
portal
pinToTop
state={emojiPickerState}
close={() => setEmojiPickerState(prev => ({...prev, isOpen: false}))}
/>
)}

{newMessagesPill.show && <NewMessagesPill onPress={scrollToEndOnPress} />}
Expand Down
11 changes: 9 additions & 2 deletions src/view/com/composer/text-input/web/EmojiPicker.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {DismissableLayer} from '@radix-ui/react-dismissable-layer'

import {textInputWebEmitter} from '#/view/com/composer/text-input/textInputWebEmitter'
import {atoms as a} from '#/alf'
import {Portal} from '#/components/Portal'

const HEIGHT_OFFSET = 40
const WIDTH_OFFSET = 100
Expand Down Expand Up @@ -47,9 +48,14 @@ interface IProps {
* the target element.
*/
pinToTop?: boolean
/**
* If `true`, renders the picker in a portal at the document root. Useful if
* the positioning is getting wacky due to other wrapping elements.
*/
portal?: boolean
}

export function EmojiPicker({state, close, pinToTop}: IProps) {
export function EmojiPicker({state, close, pinToTop, portal}: IProps) {
const {height, width} = useWindowDimensions()

const isShiftDown = React.useRef(false)
Expand Down Expand Up @@ -124,7 +130,7 @@ export function EmojiPicker({state, close, pinToTop}: IProps) {
close()
}

return (
const picker = (
<TouchableWithoutFeedback
accessibilityRole="button"
onPress={onPressBackdrop}
Expand Down Expand Up @@ -160,4 +166,5 @@ export function EmojiPicker({state, close, pinToTop}: IProps) {
</View>
</TouchableWithoutFeedback>
)
return portal ? <Portal>{picker}</Portal> : picker
}

0 comments on commit 03eb1d2

Please sign in to comment.