Fix anchor ref placement
This commit is contained in:
@@ -69,6 +69,7 @@ export type ComposerInternalApi = {
|
|||||||
input?: ReturnType<typeof useTapper>['input']
|
input?: ReturnType<typeof useTapper>['input']
|
||||||
clear: () => void
|
clear: () => void
|
||||||
insert(text: string): void
|
insert(text: string): void
|
||||||
|
setAutocompleteAnchor: (node: View | null) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useComposerInternalApiRef() {
|
export function useComposerInternalApiRef() {
|
||||||
@@ -91,7 +92,6 @@ export type ComposerProps = Omit<
|
|||||||
> & {
|
> & {
|
||||||
label: string
|
label: string
|
||||||
ref?: React.RefObject<TextInput>
|
ref?: React.RefObject<TextInput>
|
||||||
autocompleteAnchorRef?: React.RefObject<View | null>
|
|
||||||
internalApiRef?: React.Ref<ComposerInternalApi>
|
internalApiRef?: React.Ref<ComposerInternalApi>
|
||||||
outerStyle?: ViewStyleProp['style']
|
outerStyle?: ViewStyleProp['style']
|
||||||
contentTextStyle?: TextStyleProp['style']
|
contentTextStyle?: TextStyleProp['style']
|
||||||
@@ -116,7 +116,6 @@ export function Composer({
|
|||||||
label,
|
label,
|
||||||
ref,
|
ref,
|
||||||
internalApiRef,
|
internalApiRef,
|
||||||
autocompleteAnchorRef,
|
|
||||||
outerStyle,
|
outerStyle,
|
||||||
contentTextStyle,
|
contentTextStyle,
|
||||||
contentPaddingStyle,
|
contentPaddingStyle,
|
||||||
@@ -150,7 +149,6 @@ export function Composer({
|
|||||||
placement: autocompletePlacement,
|
placement: autocompletePlacement,
|
||||||
dynamicWidth: IS_WEB,
|
dynamicWidth: IS_WEB,
|
||||||
insets,
|
insets,
|
||||||
anchorRef: autocompleteAnchorRef,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -175,8 +173,9 @@ export function Composer({
|
|||||||
inputScrollSharedValue.value = 0
|
inputScrollSharedValue.value = 0
|
||||||
},
|
},
|
||||||
insert: tapper.insert,
|
insert: tapper.insert,
|
||||||
|
setAutocompleteAnchor: sift.refs.setAnchor,
|
||||||
}),
|
}),
|
||||||
[tapper.input, tapper.insert, inputScrollSharedValue],
|
[tapper.input, tapper.insert, inputScrollSharedValue, sift.refs.setAnchor],
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {useCallback, useEffect, useRef, useState} from 'react'
|
import {useCallback, useEffect, useState} from 'react'
|
||||||
import {Pressable, View} from 'react-native'
|
import {Pressable, View} from 'react-native'
|
||||||
import {useLingui} from '@lingui/react/macro'
|
import {useLingui} from '@lingui/react/macro'
|
||||||
import {countGraphemes} from 'unicode-segmenter/grapheme'
|
import {countGraphemes} from 'unicode-segmenter/grapheme'
|
||||||
@@ -46,7 +46,6 @@ export function MessageComposer({
|
|||||||
isOpen: false,
|
isOpen: false,
|
||||||
pos: {top: 0, left: 0, right: 0, bottom: 0, nextFocusRef: null},
|
pos: {top: 0, left: 0, right: 0, bottom: 0, nextFocusRef: null},
|
||||||
})
|
})
|
||||||
const anchorRef = useRef<View>(null)
|
|
||||||
const composerInternalApiRef = useComposerInternalApiRef()
|
const composerInternalApiRef = useComposerInternalApiRef()
|
||||||
|
|
||||||
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
const {state: focused, onIn: onFocus, onOut: onBlur} = useInteractionState()
|
||||||
@@ -111,7 +110,13 @@ export function MessageComposer({
|
|||||||
|
|
||||||
<View
|
<View
|
||||||
collapsable={false}
|
collapsable={false}
|
||||||
ref={IS_WEB ? undefined : anchorRef}
|
ref={
|
||||||
|
IS_WEB
|
||||||
|
? undefined
|
||||||
|
: node => {
|
||||||
|
composerInternalApiRef.current?.setAutocompleteAnchor(node)
|
||||||
|
}
|
||||||
|
}
|
||||||
// @ts-expect-error web only
|
// @ts-expect-error web only
|
||||||
onMouseEnter={onHoverIn}
|
onMouseEnter={onHoverIn}
|
||||||
onMouseLeave={onHoverOut}
|
onMouseLeave={onHoverOut}
|
||||||
@@ -171,7 +176,6 @@ export function MessageComposer({
|
|||||||
label={l`Message input field`}
|
label={l`Message input field`}
|
||||||
placeholder={l`Write a message`}
|
placeholder={l`Write a message`}
|
||||||
autocompletePlacement="top-start"
|
autocompletePlacement="top-start"
|
||||||
autocompleteAnchorRef={anchorRef}
|
|
||||||
internalApiRef={composerInternalApiRef}
|
internalApiRef={composerInternalApiRef}
|
||||||
defaultValue={text}
|
defaultValue={text}
|
||||||
editable={editable}
|
editable={editable}
|
||||||
|
|||||||
Reference in New Issue
Block a user