|
1 | 1 | (ns status-im2.contexts.chat.bottom-sheet-composer.mentions.view
|
2 | 2 | (:require
|
| 3 | + [react-native.hooks :as hooks] |
3 | 4 | [react-native.platform :as platform]
|
| 5 | + [react-native.safe-area :as safe-area] |
4 | 6 | [reagent.core :as reagent]
|
5 | 7 | [status-im2.contexts.chat.bottom-sheet-composer.utils :as utils]
|
6 | 8 | [utils.re-frame :as rf]
|
|
9 | 11 | [status-im2.common.contact-list-item.view :as contact-list-item]
|
10 | 12 | [status-im2.contexts.chat.bottom-sheet-composer.mentions.style :as style]))
|
11 | 13 |
|
| 14 | +(defn update-cursor |
| 15 | + [user {:keys [cursor-position input-ref]}] |
| 16 | + (when platform/android? |
| 17 | + (let [new-cursor-pos (+ (count (:primary-name user)) @cursor-position)] |
| 18 | + (reset! cursor-position new-cursor-pos) |
| 19 | + (reagent/next-tick #(when @input-ref |
| 20 | + (.setNativeProps ^js @input-ref |
| 21 | + (clj->js {:selection {:start new-cursor-pos |
| 22 | + :end |
| 23 | + new-cursor-pos}}))))))) |
| 24 | + |
12 | 25 | (defn mention-item
|
13 |
| - [user _ _ {:keys [cursor-position input-ref]}] |
| 26 | + [user _ _ render-data] |
14 | 27 | [contact-list-item/contact-list-item
|
15 | 28 | {: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}})))))))} |
| 29 | + (rf/dispatch [:chat.ui/select-mention nil user]) |
| 30 | + (update-cursor user render-data))} |
25 | 31 | user])
|
26 | 32 |
|
27 | 33 | (defn- f-view
|
28 |
| - [suggestions suggestions-atom props state animations max-height cursor-pos] |
29 |
| - (let [opacity (reanimated/use-shared-value (if (seq suggestions) 1 0)) |
30 |
| - mentions-pos |
31 |
| - (utils/calc-suggestions-position cursor-pos state animations max-height (count suggestions))] |
| 34 | + [suggestions-atom props state animations max-height cursor-pos] |
| 35 | + (let [{:keys [keyboard-height]} (hooks/use-keyboard) |
| 36 | + suggestions (rf/sub [:chat/mention-suggestions]) |
| 37 | + opacity (reanimated/use-shared-value (if (seq suggestions) 1 0)) |
| 38 | + count (count suggestions) |
| 39 | + data {:keyboard-height keyboard-height |
| 40 | + :insets (safe-area/get-insets) |
| 41 | + :curr-height (reanimated/get-shared-value (:height animations)) |
| 42 | + :window-height (rf/sub [:dimensions/window-height]) |
| 43 | + :reply (rf/sub [:chats/reply-message]) |
| 44 | + :edit (rf/sub [:chats/edit-message])} |
| 45 | + mentions-pos (utils/calc-suggestions-position cursor-pos max-height count state data)] |
32 | 46 | (rn/use-effect
|
33 | 47 | (fn []
|
34 | 48 | (if (seq suggestions)
|
35 |
| - (reagent/next-tick #(reset! suggestions-atom suggestions)) |
| 49 | + (reset! suggestions-atom suggestions) |
36 | 50 | (js/setTimeout #(reset! suggestions-atom suggestions) 300))
|
37 | 51 | (reanimated/animate opacity (if (seq suggestions) 1 0)))
|
38 | 52 | [(seq suggestions)])
|
|
49 | 63 |
|
50 | 64 | (defn view
|
51 | 65 | [props state animations max-height cursor-pos]
|
52 |
| - (let [suggestions (rf/sub [:chat/mention-suggestions]) |
53 |
| - suggestions-atom (reagent/atom {})] |
54 |
| - [:f> f-view suggestions suggestions-atom props state animations max-height cursor-pos])) |
| 66 | + (let [suggestions-atom (reagent/atom {})] |
| 67 | + [:f> f-view suggestions-atom props state animations max-height cursor-pos])) |
0 commit comments