|
107 | 107 | [{:keys [input-ref]}
|
108 | 108 | {:keys [text-value saved-cursor-position]}
|
109 | 109 | {: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?]))) |
143 | 144 |
|
144 | 145 | (defn use-reply
|
145 | 146 | [{:keys [input-ref]}
|
|
0 commit comments