Skip to content

Commit 80df384

Browse files
committed
review
1 parent 2e53720 commit 80df384

File tree

6 files changed

+113
-120
lines changed

6 files changed

+113
-120
lines changed

src/status_im2/constants.cljs

+2
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,5 @@
336336
(def ^:const auth-method-biometric "biometric")
337337
(def ^:const auth-method-biometric-prepare "biometric-prepare")
338338
(def ^:const auth-method-none "none")
339+
340+
(def ^:const new-composer-enabled? true)

src/status_im2/contexts/chat/bottom_sheet_composer/reply/style.cljs

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
:flex-direction :row})
88

99
(defn quoted-message
10-
[pin? in-chat-input?]
10+
[pin?]
1111
(merge {:flex-direction :row
1212
:flex 1
13-
:align-items :center
14-
:width (if in-chat-input? "100%" "45%")}
13+
:align-items :center}
1514
(when-not pin?
1615
{:left 22
1716
:margin-right 22})))
@@ -36,4 +35,9 @@
3635
:bottom 0
3736
:width "50%"})
3837

38+
(def reply-deleted-message
39+
{:text-transform :none
40+
:margin-left 4
41+
:margin-top 2})
42+
3943

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

+14-15
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

3333
(defn format-author
3434
[contact-name]
35-
(let [author (if (or (= (aget contact-name 0) "@")
35+
(let [author (if (or (= (first contact-name) "@")
3636
;; in case of replies
37-
(= (aget contact-name 1) "@"))
37+
(= (second contact-name) "@"))
3838
(or (stateofus/username contact-name)
3939
(subs contact-name 0 81))
4040
contact-name)]
@@ -57,9 +57,7 @@
5757
:size :label
5858
:weight :regular
5959
:accessibility-label :quoted-message
60-
:style {:text-transform :none
61-
:margin-left 4
62-
:margin-top 2}}
60+
:style style/reply-deleted-message}
6361
(i18n/label :t/message-deleted)]])
6462

6563
(defn reply-from
@@ -98,9 +96,9 @@
9896
:color (colors/theme-colors colors/neutral-40 colors/neutral-60)
9997
:container-style {:position :absolute :left 0 :bottom -4 :width 16 :height 16}}])
10098
(if (or deleted? deleted-for-me?)
101-
[rn/view {:style (style/quoted-message pin? in-chat-input?)}
99+
[rn/view {:style (style/quoted-message pin?)}
102100
[reply-deleted-message]]
103-
[rn/view {:style (style/quoted-message pin? in-chat-input?)}
101+
[rn/view {:style (style/quoted-message pin?)}
104102
[reply-from
105103
{:from from
106104
:identicon identicon
@@ -141,13 +139,14 @@
141139
:end {:x 0.7 :y 0}
142140
:style style/gradient}])]))
143141

144-
(defn view
142+
(defn- f-view
145143
[]
146-
[:f>
147-
(fn []
148-
(let [reply (rf/sub [:chats/reply-message])
149-
height (reanimated/use-shared-value (if reply constants/reply-container-height 0))]
150-
(rn/use-effect #(reanimated/animate height (if reply constants/reply-container-height 0)) [reply])
151-
[reanimated/view {:style (reanimated/apply-animations-to-style {:height height} {})}
152-
(when reply [reply-message reply true false false])]))])
144+
(let [reply (rf/sub [:chats/reply-message])
145+
height (reanimated/use-shared-value (if reply constants/reply-container-height 0))]
146+
(rn/use-effect #(reanimated/animate height (if reply constants/reply-container-height 0)) [reply])
147+
[reanimated/view {:style (reanimated/apply-animations-to-style {:height height} {})}
148+
(when reply [reply-message reply true false false])]))
153149

150+
(defn view
151+
[]
152+
[:f> f-view])

src/status_im2/contexts/chat/messages/list/new_temp_view.cljs

+22-17
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,27 @@
150150
{:position :absolute
151151
:bottom (+ (:bottom insets) composer.constants/composer-default-height 6)}]])))
152152

153+
(defn use-keyboard-visibility
154+
[]
155+
(let [show-listener (atom nil)
156+
hide-listener (atom nil)
157+
shown? (atom nil)]
158+
(rn/use-effect
159+
(fn []
160+
(reset! show-listener
161+
(.addListener rn/keyboard "keyboardWillShow" #(reset! shown? true)))
162+
(reset! hide-listener
163+
(.addListener rn/keyboard "keyboardWillHide" #(reset! shown? false)))
164+
(fn []
165+
(.remove ^js @show-listener)
166+
(.remove ^js @hide-listener))))
167+
{:shown? shown?}))
168+
169+
(defn- f-messages-list
170+
[chat insets]
171+
(let [{keyboard-shown? :shown?} (use-keyboard-visibility)]
172+
[messages-list-content chat insets keyboard-shown?]))
173+
153174
(defn messages-list
154175
[chat insets]
155-
[:f>
156-
(fn []
157-
(let [keyboard-show-listener (atom nil)
158-
keyboard-hide-listener (atom nil)
159-
keyboard-shown (atom false)]
160-
(rn/use-effect
161-
(fn []
162-
(reset! keyboard-show-listener (.addListener rn/keyboard
163-
"keyboardWillShow"
164-
#(reset! keyboard-shown true)))
165-
(reset! keyboard-hide-listener (.addListener rn/keyboard
166-
"keyboardWillHide"
167-
#(reset! keyboard-shown false)))
168-
(fn []
169-
(.remove ^js @keyboard-show-listener)
170-
(.remove ^js @keyboard-hide-listener))))
171-
[messages-list-content chat insets keyboard-shown]))])
176+
[:f> f-messages-list chat insets])

src/status_im2/contexts/chat/messages/list/view.cljs

+45-68
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
[status-im2.contexts.chat.messages.content.view :as message]
1414
[status-im2.contexts.chat.messages.list.state :as state]
1515
[utils.i18n :as i18n]
16-
[utils.re-frame :as rf]
17-
[status-im2.contexts.chat.bottom-sheet-composer.constants :as composer.constants]))
16+
[utils.re-frame :as rf]))
1817

1918
(defonce messages-list-ref (atom nil))
2019

@@ -91,7 +90,7 @@
9190

9291
(defn render-fn
9392
[{:keys [type value deleted? deleted-for-me? content-type] :as message-data} _ _
94-
{:keys [context keyboard-shown]}]
93+
{:keys [keyboard-shown context]}]
9594
[rn/view {:style (when platform/android? {:scaleY -1})}
9695
(if (= type :datemark)
9796
[quo/divider-date value]
@@ -103,69 +102,47 @@
103102
[content.deleted/deleted-message message-data context]
104103
[message/message-with-reactions message-data context keyboard-shown])]))])
105104

106-
(defn messages-list-content
107-
[{:keys [chat-id] :as chat} insets keyboard-shown]
108-
(fn []
109-
(let [context (rf/sub [:chats/current-chat-message-list-view-context])
110-
messages (rf/sub [:chats/raw-chat-messages-stream chat-id])]
111-
[rn/view
112-
{:style {:flex 1}}
113-
;; NOTE: DO NOT use anonymous functions for handlers
114-
[rn/flat-list
115-
{:key-fn list-key-fn
116-
:ref list-ref
117-
:header [list-header chat]
118-
:footer [list-footer chat]
119-
:data messages
120-
:render-data {:context context
121-
:keyboard-shown keyboard-shown}
122-
:render-fn render-fn
123-
:on-viewable-items-changed on-viewable-items-changed
124-
:on-end-reached list-on-end-reached
125-
:on-scroll-to-index-failed identity ; don't remove this
126-
:content-container-style {:padding-top (+ composer.constants/composer-default-height
127-
(:bottom insets)
128-
32)
129-
:padding-bottom 16}
130-
:scroll-indicator-insets {:top (+ composer.constants/composer-default-height
131-
(:bottom insets))}
132-
:keyboard-dismiss-mode :interactive
133-
:keyboard-should-persist-taps :handled
134-
:on-momentum-scroll-begin state/start-scrolling
135-
:on-momentum-scroll-end state/stop-scrolling
136-
:scroll-event-throttle 16
137-
:on-scroll on-scroll
138-
;; TODO https://github.com/facebook/react-native/issues/30034
139-
:inverted (when platform/ios? true)
140-
:style (when platform/android? {:scaleY -1})
141-
:on-layout on-messages-view-layout}]
142-
[quo/floating-shell-button
143-
(merge {:jump-to
144-
{:on-press #(do
145-
(rf/dispatch [:chat/close true])
146-
(rf/dispatch [:shell/navigate-to-jump-to]))
147-
:label (i18n/label :t/jump-to)}}
148-
(when @show-floating-scroll-down-button
149-
{:scroll-to-bottom {:on-press scroll-to-bottom}}))
150-
{:position :absolute
151-
:bottom (+ (:bottom insets) composer.constants/composer-default-height 6)}]])))
152-
153105
(defn messages-list
154-
[chat insets]
155-
[:f>
156-
(fn []
157-
(let [keyboard-show-listener (atom nil)
158-
keyboard-hide-listener (atom nil)
159-
keyboard-shown (atom false)]
160-
(rn/use-effect
161-
(fn []
162-
(reset! keyboard-show-listener (.addListener rn/keyboard
163-
"keyboardWillShow"
164-
#(reset! keyboard-shown true)))
165-
(reset! keyboard-hide-listener (.addListener rn/keyboard
166-
"keyboardWillHide"
167-
#(reset! keyboard-shown false)))
168-
(fn []
169-
(.remove ^js @keyboard-show-listener)
170-
(.remove ^js @keyboard-hide-listener))))
171-
[messages-list-content chat insets keyboard-shown]))])
106+
[{:keys [chat-id] :as chat}]
107+
(let [context (rf/sub [:chats/current-chat-message-list-view-context])
108+
messages (rf/sub [:chats/raw-chat-messages-stream chat-id])
109+
keyboard-shown (atom false)
110+
bottom-space 15]
111+
[rn/view
112+
{:style {:flex 1}}
113+
;; NOTE: DO NOT use anonymous functions for handlers
114+
[rn/flat-list
115+
{:key-fn list-key-fn
116+
:ref list-ref
117+
:header [list-header chat]
118+
:footer [list-footer chat]
119+
:data messages
120+
:render-data {:context context
121+
:keyboard-shown keyboard-shown}
122+
:render-fn render-fn
123+
:on-viewable-items-changed on-viewable-items-changed
124+
:on-end-reached list-on-end-reached
125+
:on-scroll-to-index-failed identity ; don't remove this
126+
:content-container-style {:padding-top (+ bottom-space 32)
127+
:padding-bottom 16}
128+
:scroll-indicator-insets {:top bottom-space} ; iOS only
129+
:keyboard-dismiss-mode :interactive
130+
:keyboard-should-persist-taps :handled
131+
:onMomentumScrollBegin state/start-scrolling
132+
:onMomentumScrollEnd state/stop-scrolling
133+
:scrollEventThrottle 16
134+
:on-scroll on-scroll
135+
;; TODO https://github.com/facebook/react-native/issues/30034
136+
:inverted (when platform/ios? true)
137+
:style (when platform/android? {:scaleY -1})
138+
:on-layout on-messages-view-layout}]
139+
[quo/floating-shell-button
140+
(merge {:jump-to
141+
{:on-press #(do
142+
(rf/dispatch [:chat/close true])
143+
(rf/dispatch [:shell/navigate-to-jump-to]))
144+
:label (i18n/label :t/jump-to)}}
145+
(when @show-floating-scroll-down-button
146+
{:scroll-to-bottom {:on-press scroll-to-bottom}}))
147+
{:position :absolute
148+
:bottom 6}]]))

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

+23-17
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
[reagent.core :as reagent]
77
[status-im2.constants :as constants]
88
[status-im2.contexts.chat.bottom-sheet-composer.view :as bottom-sheet-composer]
9+
[status-im2.contexts.chat.messages.composer.view :as composer]
910
[status-im2.contexts.chat.messages.contact-requests.bottom-drawer :as
1011
contact-requests.bottom-drawer]
1112
[status-im2.contexts.chat.messages.list.view :as messages.list]
13+
[status-im2.contexts.chat.messages.list.new-temp-view :as messages.list.new]
1214
[status-im2.contexts.chat.messages.pin.banner.view :as pin.banner]
1315
[status-im2.navigation.state :as navigation.state]
1416
[utils.debounce :as debounce]
@@ -28,16 +30,16 @@
2830
[]
2931
(let [{:keys [group-chat chat-id chat-name emoji
3032
chat-type]} (rf/sub [:chats/current-chat])
31-
display-name (if (= chat-type constants/one-to-one-chat-type)
32-
(first (rf/sub [:contacts/contact-two-names-by-identity chat-id]))
33-
(str emoji " " chat-name))
34-
online? (rf/sub [:visibility-status-updates/online? chat-id])
35-
contact (when-not group-chat
36-
(rf/sub [:contacts/contact-by-address chat-id]))
37-
photo-path (rf/sub [:chats/photo-path chat-id])
38-
avatar-image-key (if (seq (:images contact))
39-
:profile-picture
40-
:ring-background)]
33+
display-name (if (= chat-type constants/one-to-one-chat-type)
34+
(first (rf/sub [:contacts/contact-two-names-by-identity chat-id]))
35+
(str emoji " " chat-name))
36+
online? (rf/sub [:visibility-status-updates/online? chat-id])
37+
contact (when-not group-chat
38+
(rf/sub [:contacts/contact-by-address chat-id]))
39+
photo-path (rf/sub [:chats/photo-path chat-id])
40+
avatar-image-key (if (seq (:images contact))
41+
:profile-picture
42+
:ring-background)]
4143
[quo/page-nav
4244
{:align-mid? true
4345
:mid-section (if group-chat
@@ -75,17 +77,21 @@
7577
:keyboardVerticalOffset (- (:bottom insets))}
7678
[page-nav]
7779
[pin.banner/banner chat-id]
78-
[messages.list/messages-list chat insets]
80+
(if constants/new-composer-enabled?
81+
[messages.list.new/messages-list chat insets]
82+
[messages.list/messages-list chat insets])
7983
(if-not able-to-send-message?
8084
[contact-requests.bottom-drawer/view chat-id contact-request-state group-chat]
81-
[bottom-sheet-composer/bottom-sheet-composer insets])]))
85+
(if constants/new-composer-enabled?
86+
[bottom-sheet-composer/bottom-sheet-composer insets]
87+
[:f> composer/f-composer chat-id insets]))]))
8288

8389

8490
(defn chat
8591
[]
8692
(reagent/create-class
87-
{:component-did-mount (fn []
88-
(rn/hw-back-remove-listener navigate-back-handler)
89-
(rn/hw-back-add-listener navigate-back-handler))
90-
:component-will-unmount (fn [] (rn/hw-back-remove-listener navigate-back-handler))
91-
:reagent-render chat-render}))
93+
{:component-did-mount (fn []
94+
(rn/hw-back-remove-listener navigate-back-handler)
95+
(rn/hw-back-add-listener navigate-back-handler))
96+
:component-will-unmount (fn [] (rn/hw-back-remove-listener navigate-back-handler))
97+
:reagent-render chat-render}))

0 commit comments

Comments
 (0)