|
13 | 13 | [status-im2.contexts.chat.messages.content.view :as message]
|
14 | 14 | [status-im2.contexts.chat.messages.list.state :as state]
|
15 | 15 | [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])) |
18 | 17 |
|
19 | 18 | (defonce messages-list-ref (atom nil))
|
20 | 19 |
|
|
91 | 90 |
|
92 | 91 | (defn render-fn
|
93 | 92 | [{:keys [type value deleted? deleted-for-me? content-type] :as message-data} _ _
|
94 |
| - {:keys [context keyboard-shown]}] |
| 93 | + {:keys [keyboard-shown context]}] |
95 | 94 | [rn/view {:style (when platform/android? {:scaleY -1})}
|
96 | 95 | (if (= type :datemark)
|
97 | 96 | [quo/divider-date value]
|
|
103 | 102 | [content.deleted/deleted-message message-data context]
|
104 | 103 | [message/message-with-reactions message-data context keyboard-shown])]))])
|
105 | 104 |
|
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 |
| - |
153 | 105 | (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}]])) |
0 commit comments