Maintain scroll postion after fetching gap

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Roman Volosovskyi 2019-04-24 10:52:23 +03:00 committed by Igor Mandrigin
parent e55cbc4c1f
commit 3a2d70273e
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
4 changed files with 58 additions and 39 deletions

View File

@ -112,13 +112,18 @@
(- next-whisper-timestamp next-timestamp)) (- next-whisper-timestamp next-timestamp))
120)] 120)]
(reduce (reduce
(fn [acc {:keys [from id]}] (fn [acc {:keys [from to id]}]
(if (and next-message (if (and next-message
(not ignore-next-message?) (not ignore-next-message?)
(or (or
(and (nil? previous-timestamp) (and (nil? previous-timestamp)
(< from next-whisper-timestamp)) (< from next-whisper-timestamp))
(< previous-timestamp from next-whisper-timestamp))) (and
(< previous-timestamp from)
(< to next-whisper-timestamp))
(and
(< from previous-timestamp)
(< to next-whisper-timestamp))))
(-> acc (-> acc
(update :gaps-number inc) (update :gaps-number inc)
(update-in [:gap :ids] conj id)) (update-in [:gap :ids] conj id))

View File

@ -45,24 +45,24 @@
[(view-profile chat-id) [(view-profile chat-id)
(clear-history) (clear-history)
(fetch-history chat-id) (fetch-history chat-id)
#_(fetch-history48-60 chat-id) (fetch-history48-60 chat-id)
#_(fetch-history84-96 chat-id) (fetch-history84-96 chat-id)
(delete-chat chat-id false)]) (delete-chat chat-id false)])
(defn- group-chat-actions [chat-id] (defn- group-chat-actions [chat-id]
[(group-info chat-id) [(group-info chat-id)
(clear-history) (clear-history)
(fetch-history chat-id) (fetch-history chat-id)
#_(fetch-history48-60 chat-id) (fetch-history48-60 chat-id)
#_(fetch-history84-96 chat-id) (fetch-history84-96 chat-id)
(delete-chat chat-id true)]) (delete-chat chat-id true)])
(defn- public-chat-actions [chat-id] (defn- public-chat-actions [chat-id]
[(share-chat chat-id) [(share-chat chat-id)
(clear-history) (clear-history)
(fetch-history chat-id) (fetch-history chat-id)
#_(fetch-history48-60 chat-id) (fetch-history48-60 chat-id)
#_(fetch-history84-96 chat-id) (fetch-history84-96 chat-id)
(delete-chat chat-id false)]) (delete-chat chat-id false)])
(defn actions [group-chat? chat-id public?] (defn actions [group-chat? chat-id public?]

View File

@ -70,36 +70,45 @@
[{{:keys [value]} :row}] [{{:keys [value]} :row}]
[message-datemark/chat-datemark-mobile value]) [message-datemark/chat-datemark-mobile value])
(defview gap [{:keys [ids]}] (defview gap
[ids idx list-ref in-progress? connected?]
[react/view {:align-self :stretch
:margin-top 24
:margin-bottom 24
:height 48
:align-items :center
:justify-content :center
:border-color colors/gray-light
:border-top-width 1
:border-bottom-width 1
:background-color :white}
[react/touchable-highlight
{:on-press (when (and connected? (not in-progress?))
#(do
(when @list-ref
(.scrollToIndex @list-ref #js {:index (max 0 (dec idx))
:viewOffset 20
:viewPosition 0.5}))
(re-frame/dispatch [:chat.ui/fill-gaps ids])))}
[react/view {:flex 1
:align-items :center
:justify-content :center}
(if in-progress?
[react/activity-indicator]
[react/text
{:style {:color (if connected?
colors/blue
colors/gray)}}
(i18n/label :t/fetch-messages)])]]])
(defview gap-wrapper [{:keys [ids]} idx list-ref]
(letsubs [in-progress? [:chats/fetching-gap-in-progress? ids] (letsubs [in-progress? [:chats/fetching-gap-in-progress? ids]
connected? [:mailserver/connected?]] connected? [:mailserver/connected?]]
[react/view {:align-self :stretch [gap ids idx list-ref in-progress? connected?]))
:margin-top 24
:margin-bottom 24
:height 48
:align-items :center
:justify-content :center
:border-color colors/gray-light
:border-top-width 1
:border-bottom-width 1
:background-color :white}
[react/touchable-highlight
{:on-press (when (and connected? (not in-progress?))
#(re-frame/dispatch [:chat.ui/fill-gaps ids]))}
[react/view {:flex 1
:align-items :center
:justify-content :center}
(if in-progress?
[react/activity-indicator]
[react/text
{:style {:color (if connected?
colors/blue
colors/gray)}}
(i18n/label :t/fetch-messages)])]]]))
(defmethod message-row :gap (defmethod message-row :gap
[{:keys [row]}] [{:keys [row idx list-ref]}]
[gap (:gaps row)]) [gap-wrapper (:gaps row) idx list-ref])
(defmethod message-row :default (defmethod message-row :default
[{:keys [group-chat current-public-key modal? row]}] [{:keys [group-chat current-public-key modal? row]}]
@ -247,6 +256,8 @@
(i18n/label :t/empty-chat-description-one-to-one) (i18n/label :t/empty-chat-description-one-to-one)
[{} intro-name]])]])))) [{} intro-name]])]]))))
(defonce messages-list-ref (atom nil))
(defview messages-view (defview messages-view
[{:keys [group-chat chat-id pending-invite-inviter-name] :as chat} [{:keys [group-chat chat-id pending-invite-inviter-name] :as chat}
modal?] modal?]
@ -262,14 +273,17 @@
(let [no-messages (empty? messages) (let [no-messages (empty? messages)
flat-list-conf flat-list-conf
{:data messages {:data messages
:ref #(reset! messages-list-ref %)
:footer [chat-intro-header-container chat no-messages] :footer [chat-intro-header-container chat no-messages]
:key-fn #(or (:message-id %) (:value %)) :key-fn #(or (:message-id %) (:value %))
:render-fn (fn [message] :render-fn (fn [message idx]
[message-row [message-row
{:group-chat group-chat {:group-chat group-chat
:modal? modal? :modal? modal?
:current-public-key current-public-key :current-public-key current-public-key
:row message}]) :row message
:idx idx
:list-ref messages-list-ref}])
:inverted true :inverted true
:onEndReached #(re-frame/dispatch :onEndReached #(re-frame/dispatch
[:chat.ui/load-more-messages]) [:chat.ui/load-more-messages])

View File

@ -207,6 +207,9 @@
:timestamp-str "14:00" :timestamp-str "14:00"
:user-statuses nil :user-statuses nil
:datemark "today"} :datemark "today"}
{:type :gap
:value ":gapid1"
:gaps {:ids [:gapid1]}}
{:whisper-timestamp 30 {:whisper-timestamp 30
:timestamp 30 :timestamp 30
:content nil :content nil
@ -217,9 +220,6 @@
:type :datemark :type :datemark
:whisper-timestamp 30 :whisper-timestamp 30
:timestamp 30} :timestamp 30}
{:type :gap
:value ":gapid1"
:gaps {:ids [:gapid1]}}
{:whisper-timestamp 20 {:whisper-timestamp 20
:timestamp 20 :timestamp 20
:content nil :content nil