Fix Android composer cursor bug by removing `setTimeout` from native composer `onChangeText` (#4922)

zio/stable
Hailey 2024-08-12 08:14:02 -07:00 committed by GitHub
parent 75c19b2dc2
commit db7a744433
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 44 additions and 56 deletions

View File

@ -85,18 +85,7 @@ export const TextInput = forwardRef(function TextInputImpl(
const pastSuggestedUris = useRef(new Set<string>()) const pastSuggestedUris = useRef(new Set<string>())
const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>()) const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>())
const onChangeText = useCallback( const onChangeText = useCallback(
(newText: string) => { async (newText: string) => {
/*
* This is a hack to bump the rendering of our styled
* `textDecorated` to _after_ whatever processing is happening
* within the `PasteInput` library. Without this, the elements in
* `textDecorated` are not correctly painted to screen.
*
* NB: we tried a `0` timeout as well, but only positive values worked.
*
* @see https://github.com/bluesky-social/social-app/issues/929
*/
setTimeout(async () => {
const mayBePaste = newText.length > prevLength.current + 1 const mayBePaste = newText.length > prevLength.current + 1
const newRt = new RichText({text: newText}) const newRt = new RichText({text: newText})
@ -149,7 +138,6 @@ export const TextInput = forwardRef(function TextInputImpl(
onNewLink(suggestedUri) onNewLink(suggestedUri)
} }
prevLength.current = newText.length prevLength.current = newText.length
}, 1)
}, },
[setRichText, autocompletePrefix, onPhotoPasted, onNewLink], [setRichText, autocompletePrefix, onPhotoPasted, onNewLink],
) )