|
1 | 1 | (ns status-im2.contexts.chat.bottom-sheet-composer.mentions.view
|
2 | 2 | (:require
|
| 3 | + [react-native.platform :as platform] |
3 | 4 | [reagent.core :as reagent]
|
4 | 5 | [status-im2.contexts.chat.bottom-sheet-composer.utils :as utils]
|
5 | 6 | [utils.re-frame :as rf]
|
|
9 | 10 | [status-im2.contexts.chat.bottom-sheet-composer.mentions.style :as style]))
|
10 | 11 |
|
11 | 12 | (defn mention-item
|
12 |
| - [user] |
| 13 | + [user _ _ {:keys [cursor-position input-ref]}] |
13 | 14 | [contact-list-item/contact-list-item
|
14 |
| - {:on-press #(rf/dispatch [:chat.ui/select-mention nil user])} user]) |
| 15 | + {:on-press (fn [] |
| 16 | + (let [new-cursor-pos (+ (count (:primary-name user)) @cursor-position)] |
| 17 | + (rf/dispatch [:chat.ui/select-mention nil user]) |
| 18 | + (when platform/android? |
| 19 | + (reset! cursor-position new-cursor-pos) |
| 20 | + (reagent/next-tick #(when @input-ref |
| 21 | + (.setNativeProps ^js @input-ref |
| 22 | + (clj->js {:selection {:start new-cursor-pos |
| 23 | + :end |
| 24 | + new-cursor-pos}})))))))} |
| 25 | + user]) |
15 | 26 |
|
16 | 27 | (defn- f-view
|
17 |
| - [suggestions suggestions-atom state animations max-height cursor-pos] |
| 28 | + [suggestions suggestions-atom props state animations max-height cursor-pos] |
18 | 29 | (let [opacity (reanimated/use-shared-value (if (seq suggestions) 1 0))
|
19 | 30 | mentions-pos
|
20 | 31 | (utils/calc-suggestions-position cursor-pos state animations max-height (count suggestions))]
|
|
32 | 43 | :data (vals @suggestions-atom)
|
33 | 44 | :key-fn :key
|
34 | 45 | :render-fn mention-item
|
| 46 | + :render-data {:cursor-position (:cursor-position state) |
| 47 | + :input-ref (:input-ref props)} |
35 | 48 | :accessibility-label :mentions-list}]]))
|
36 | 49 |
|
37 | 50 | (defn view
|
38 |
| - [state animations max-height cursor-pos] |
| 51 | + [props state animations max-height cursor-pos] |
39 | 52 | (let [suggestions (rf/sub [:chat/mention-suggestions])
|
40 | 53 | suggestions-atom (reagent/atom {})]
|
41 |
| - [:f> f-view suggestions suggestions-atom state animations max-height cursor-pos])) |
| 54 | + [:f> f-view suggestions suggestions-atom props state animations max-height cursor-pos])) |
0 commit comments