about summary refs log tree commit diff
path: root/src/view/com/composer/text-input
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-08-12 08:14:02 -0700
committerGitHub <noreply@github.com>2024-08-12 08:14:02 -0700
commitdb7a744433dba4430bc2045ab00a4b5dec0a10b2 (patch)
tree124bd46daa461fa3be2e119ee415c3652335219f /src/view/com/composer/text-input
parent75c19b2dc21ddc3338a9d7ea590bb3e0e999610f (diff)
downloadvoidsky-db7a744433dba4430bc2045ab00a4b5dec0a10b2.tar.zst
Fix Android composer cursor bug by removing `setTimeout` from native composer `onChangeText` (#4922)
Diffstat (limited to 'src/view/com/composer/text-input')
-rw-r--r--src/view/com/composer/text-input/TextInput.tsx102
1 files changed, 45 insertions, 57 deletions
diff --git a/src/view/com/composer/text-input/TextInput.tsx b/src/view/com/composer/text-input/TextInput.tsx
index cb16e3c66..f69c89569 100644
--- a/src/view/com/composer/text-input/TextInput.tsx
+++ b/src/view/com/composer/text-input/TextInput.tsx
@@ -85,71 +85,59 @@ export const TextInput = forwardRef(function TextInputImpl(
   const pastSuggestedUris = useRef(new Set<string>())
   const prevDetectedUris = useRef(new Map<string, LinkFacetMatch>())
   const onChangeText = useCallback(
-    (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
+    async (newText: string) => {
+      const mayBePaste = newText.length > prevLength.current + 1
 
-        const newRt = new RichText({text: newText})
-        newRt.detectFacetsWithoutResolution()
-        setRichText(newRt)
+      const newRt = new RichText({text: newText})
+      newRt.detectFacetsWithoutResolution()
+      setRichText(newRt)
 
-        const prefix = getMentionAt(
-          newText,
-          textInputSelection.current?.start || 0,
-        )
-        if (prefix) {
-          setAutocompletePrefix(prefix.value)
-        } else if (autocompletePrefix) {
-          setAutocompletePrefix('')
-        }
-
-        const nextDetectedUris = new Map<string, LinkFacetMatch>()
-        if (newRt.facets) {
-          for (const facet of newRt.facets) {
-            for (const feature of facet.features) {
-              if (AppBskyRichtextFacet.isLink(feature)) {
-                if (isUriImage(feature.uri)) {
-                  const res = await downloadAndResize({
-                    uri: feature.uri,
-                    width: POST_IMG_MAX.width,
-                    height: POST_IMG_MAX.height,
-                    mode: 'contain',
-                    maxSize: POST_IMG_MAX.size,
-                    timeout: 15e3,
-                  })
+      const prefix = getMentionAt(
+        newText,
+        textInputSelection.current?.start || 0,
+      )
+      if (prefix) {
+        setAutocompletePrefix(prefix.value)
+      } else if (autocompletePrefix) {
+        setAutocompletePrefix('')
+      }
 
-                  if (res !== undefined) {
-                    onPhotoPasted(res.path)
-                  }
-                } else {
-                  nextDetectedUris.set(feature.uri, {facet, rt: newRt})
+      const nextDetectedUris = new Map<string, LinkFacetMatch>()
+      if (newRt.facets) {
+        for (const facet of newRt.facets) {
+          for (const feature of facet.features) {
+            if (AppBskyRichtextFacet.isLink(feature)) {
+              if (isUriImage(feature.uri)) {
+                const res = await downloadAndResize({
+                  uri: feature.uri,
+                  width: POST_IMG_MAX.width,
+                  height: POST_IMG_MAX.height,
+                  mode: 'contain',
+                  maxSize: POST_IMG_MAX.size,
+                  timeout: 15e3,
+                })
+
+                if (res !== undefined) {
+                  onPhotoPasted(res.path)
                 }
+              } else {
+                nextDetectedUris.set(feature.uri, {facet, rt: newRt})
               }
             }
           }
         }
-        const suggestedUri = suggestLinkCardUri(
-          mayBePaste,
-          nextDetectedUris,
-          prevDetectedUris.current,
-          pastSuggestedUris.current,
-        )
-        prevDetectedUris.current = nextDetectedUris
-        if (suggestedUri) {
-          onNewLink(suggestedUri)
-        }
-        prevLength.current = newText.length
-      }, 1)
+      }
+      const suggestedUri = suggestLinkCardUri(
+        mayBePaste,
+        nextDetectedUris,
+        prevDetectedUris.current,
+        pastSuggestedUris.current,
+      )
+      prevDetectedUris.current = nextDetectedUris
+      if (suggestedUri) {
+        onNewLink(suggestedUri)
+      }
+      prevLength.current = newText.length
     },
     [setRichText, autocompletePrefix, onPhotoPasted, onNewLink],
   )