Skip to content

Commit a175f3d

Browse files
committed
fix: (potentially) fixing the mention not resolved during edit
1 parent cb9ae2a commit a175f3d

File tree

1 file changed

+34
-33
lines changed

1 file changed

+34
-33
lines changed

src/status_im2/contexts/chat/composer/effects.cljs

+34-33
Original file line numberDiff line numberDiff line change
@@ -107,39 +107,40 @@
107107
[{:keys [input-ref]}
108108
{:keys [text-value saved-cursor-position]}
109109
{:keys [edit input-with-mentions]}]
110-
(rn/use-effect
111-
(fn []
112-
(let [mention? (some #(= :mention (first %)) (seq input-with-mentions))
113-
mention-text (reduce (fn [acc item]
114-
(str acc (second item)))
115-
""
116-
input-with-mentions)
117-
edit-text (if mention? mention-text (get-in edit [:content :text]))
118-
text-value-count (count @text-value)
119-
inject-edit-text (fn []
120-
(reset! text-value edit-text)
121-
(reset! saved-cursor-position (if (zero? text-value-count)
122-
(count edit-text)
123-
text-value-count))
124-
(when @input-ref
125-
(let [selection-pos (count edit-text)]
126-
(.setNativeProps ^js @input-ref
127-
(clj->js {:text edit-text
128-
:selection {:start selection-pos
129-
:end selection-pos}})))))]
130-
(when (and edit @input-ref)
131-
;; NOTE: A small setTimeout is necessary to ensure the focus is enqueued and is executed
132-
;; ASAP. Check https://github.com/software-mansion/react-native-screens/issues/472
133-
;;
134-
;; The nested setTimeout is necessary to avoid both `on-focus` and `on-content-size-change`
135-
;; handlers triggering the height animation simultaneously, as this causes a jump in the
136-
;; UI. This way, `on-focus` will trigger first without changing the height, after which
137-
;; `on-content-size-change` will animate the height of the input based on the injected
138-
;; text.
139-
(js/setTimeout #(do (.focus ^js @input-ref)
140-
(js/setTimeout inject-edit-text 250))
141-
100))))
142-
[(:message-id edit)]))
110+
(let [mention? (some #(= :mention (first %)) (seq input-with-mentions))]
111+
(rn/use-effect
112+
(fn []
113+
(let [mention-text (reduce (fn [acc item]
114+
(str acc (second item)))
115+
""
116+
input-with-mentions)
117+
edit-text (if mention? mention-text (get-in edit [:content :text]))
118+
text-value-count (count @text-value)
119+
inject-edit-text (fn []
120+
(reset! text-value edit-text)
121+
(reset! saved-cursor-position (if (zero? text-value-count)
122+
(count edit-text)
123+
text-value-count))
124+
(when @input-ref
125+
(let [selection-pos (count edit-text)]
126+
(.setNativeProps ^js @input-ref
127+
(clj->js {:text edit-text
128+
:selection {:start selection-pos
129+
:end selection-pos}})))))]
130+
(when (and edit @input-ref)
131+
;; NOTE: A small setTimeout is necessary to ensure the focus is enqueued and is executed
132+
;; ASAP. Check https://github.com/software-mansion/react-native-screens/issues/472
133+
;;
134+
;; The nested setTimeout is necessary to avoid both `on-focus` and
135+
;; `on-content-size-change` handlers triggering the height animation simultaneously, as
136+
;; this causes a jump in the
137+
;; UI. This way, `on-focus` will trigger first without changing the height, after which
138+
;; `on-content-size-change` will animate the height of the input based on the injected
139+
;; text.
140+
(js/setTimeout #(do (.focus ^js @input-ref)
141+
(js/setTimeout inject-edit-text 250))
142+
100))))
143+
[(:message-id edit) mention?])))
143144

144145
(defn use-reply
145146
[{:keys [input-ref]}

0 commit comments

Comments
 (0)