Fix Composer not focusing on edit/reply (#17640)

This commit is contained in:
Ibrahem Khalil 2023-10-26 05:43:49 +03:00 committed by GitHub
parent c0b21aa315
commit fe2272b703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -112,7 +112,10 @@
(let [edit-text (get-in edit [:content :text]) (let [edit-text (get-in edit [:content :text])
text-value-count (count @text-value)] text-value-count (count @text-value)]
(when (and edit @input-ref) (when (and edit @input-ref)
(.focus ^js @input-ref) ;; A small setTimeout is necessary to ensure the statement is enqueued and will get executed
;; ASAP.
;; https://github.com/software-mansion/react-native-screens/issues/472
(js/setTimeout #(.focus ^js @input-ref) 250)
(.setNativeProps ^js @input-ref (clj->js {:text edit-text})) (.setNativeProps ^js @input-ref (clj->js {:text edit-text}))
(reset! text-value edit-text) (reset! text-value edit-text)
(reset! saved-cursor-position (if (zero? text-value-count) (reset! saved-cursor-position (if (zero? text-value-count)
@ -129,7 +132,7 @@
(when reply (when reply
(reanimated/animate container-opacity 1)) (reanimated/animate container-opacity 1))
(when (and reply @input-ref) (when (and reply @input-ref)
(.focus ^js @input-ref))) (js/setTimeout #(.focus ^js @input-ref) 250)))
[(:message-id reply)])) [(:message-id reply)]))
(defn edit-mentions (defn edit-mentions
@ -181,7 +184,7 @@
(+ (reanimated/get-shared-value last-height) value)))) (+ (reanimated/get-shared-value last-height) value))))
(let [curr-text @text-value] (let [curr-text @text-value]
(reset! text-value (str @text-value " ")) (reset! text-value (str @text-value " "))
(js/setTimeout #(reset! text-value curr-text) 10))) (js/setTimeout #(reset! text-value curr-text) 100)))
(reset! sending-links? link-previews?)) (reset! sending-links? link-previews?))
[link-previews?])) [link-previews?]))
@ -208,7 +211,7 @@
(+ (reanimated/get-shared-value last-height) value)))) (+ (reanimated/get-shared-value last-height) value))))
(let [curr-text @text-value] (let [curr-text @text-value]
(reset! text-value (str @text-value " ")) (reset! text-value (str @text-value " "))
(js/setTimeout #(reset! text-value curr-text) 10))) (js/setTimeout #(reset! text-value curr-text) 100)))
(reset! sending-images? (boolean (seq images)))) (reset! sending-images? (boolean (seq images))))
[(boolean (seq images))])) [(boolean (seq images))]))