Skip to content

Commit 78ad0e5

Browse files
committed
review
1 parent 1456e39 commit 78ad0e5

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
(ns status-im2.contexts.chat.bottom-sheet-composer.mentions.view
22
(:require
3+
[react-native.hooks :as hooks]
34
[react-native.platform :as platform]
5+
[react-native.safe-area :as safe-area]
46
[reagent.core :as reagent]
57
[status-im2.contexts.chat.bottom-sheet-composer.utils :as utils]
68
[utils.re-frame :as rf]
@@ -9,30 +11,42 @@
911
[status-im2.common.contact-list-item.view :as contact-list-item]
1012
[status-im2.contexts.chat.bottom-sheet-composer.mentions.style :as style]))
1113

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+
1225
(defn mention-item
13-
[user _ _ {:keys [cursor-position input-ref]}]
26+
[user _ _ render-data]
1427
[contact-list-item/contact-list-item
1528
{: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))}
2531
user])
2632

2733
(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)]
3246
(rn/use-effect
3347
(fn []
3448
(if (seq suggestions)
35-
(reagent/next-tick #(reset! suggestions-atom suggestions))
49+
(reset! suggestions-atom suggestions)
3650
(js/setTimeout #(reset! suggestions-atom suggestions) 300))
3751
(reanimated/animate opacity (if (seq suggestions) 1 0)))
3852
[(seq suggestions)])
@@ -49,6 +63,5 @@
4963

5064
(defn view
5165
[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]))

src/status_im2/contexts/chat/bottom_sheet_composer/utils.cljs

+16-20
Original file line numberDiff line numberDiff line change
@@ -120,26 +120,22 @@
120120
(* sub-text-lines-in-view constants/line-height)))
121121

122122
(defn calc-suggestions-position
123-
[cursor-pos {:keys [maximized?]} {:keys [height]} max-height count]
124-
(let [{:keys [keyboard-height]} (hooks/use-keyboard)
125-
insets (safe-area/get-insets)
126-
curr-height (reanimated/get-shared-value height)
127-
window-height (rf/sub [:dimensions/window-height])
128-
reply (rf/sub [:chats/reply-message])
129-
edit (rf/sub [:chats/edit-message])
130-
base (+ constants/composer-default-height (:bottom insets) 8)
131-
base (+ base (- curr-height constants/input-height))
132-
base (if edit
133-
(+ base constants/edit-container-height)
134-
base)
135-
base (if reply
136-
(+ base constants/reply-container-height)
137-
base)
138-
view-height (- window-height keyboard-height (:top insets))
139-
container-height (bounded-val
140-
(* (/ constants/mentions-max-height 4) count)
141-
(/ constants/mentions-max-height 4)
142-
constants/mentions-max-height)]
123+
[cursor-pos max-height count
124+
{:keys [maximized?]}
125+
{:keys [insets curr-height window-height keyboard-height edit reply]}]
126+
(let [base (+ constants/composer-default-height (:bottom insets) 8)
127+
base (+ base (- curr-height constants/input-height))
128+
base (if edit
129+
(+ base constants/edit-container-height)
130+
base)
131+
base (if reply
132+
(+ base constants/reply-container-height)
133+
base)
134+
view-height (- window-height keyboard-height (:top insets))
135+
container-height (bounded-val
136+
(* (/ constants/mentions-max-height 4) count)
137+
(/ constants/mentions-max-height 4)
138+
constants/mentions-max-height)]
143139
(if @maximized?
144140
(if (< (+ cursor-pos container-height) max-height)
145141
(+ constants/actions-container-height (:bottom insets))

src/status_im2/contexts/chat/bottom_sheet_composer/view.cljs

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
max-height (utils/calc-max-height window-height
6767
kb-height
6868
insets
69-
(seq images)
69+
(boolean (seq images))
7070
reply
7171
edit)
7272
lines (utils/calc-lines @content-height)
@@ -110,7 +110,7 @@
110110
dimensions
111111
chat-input
112112
keyboard-height
113-
(seq images)
113+
(boolean (seq images))
114114
reply
115115
edit
116116
audio)
@@ -152,8 +152,8 @@
152152
:accessibility-label :chat-message-input}]
153153
[gradients/view props state animations show-bottom-gradient?]]
154154
[images/images-list]
155-
[actions/view props state animations window-height insets (seq images)]]]]))]))])
156-
155+
[actions/view props state animations window-height insets
156+
(boolean (seq images))]]]]))]))])
157157

158158
(defn f-bottom-sheet-composer
159159
[insets]

0 commit comments

Comments
 (0)