connectivity-status animation with native driver

This commit is contained in:
Roman Volosovskyi 2019-06-26 13:24:21 +03:00
parent ab2248f9f8
commit 2b6bfb9851
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
9 changed files with 147 additions and 84 deletions

View File

@ -11,14 +11,27 @@
(defn interpolate [anim-value config]
(.interpolate anim-value (clj->js config)))
(defn add-native-driver [{:keys [useNativeDriver] :as config}]
(assoc config
:useNativeDriver
(if (nil? useNativeDriver)
true
useNativeDriver)))
(defn timing [anim-value config]
(.timing (react/animated) anim-value (clj->js config)))
(.timing (react/animated)
anim-value
(clj->js (add-native-driver config))))
(defn spring [anim-value config]
(.spring (react/animated) anim-value (clj->js config)))
(.spring (react/animated)
anim-value
(clj->js (add-native-driver config))))
(defn decay [anim-value config]
(.decay (react/animated) anim-value (clj->js config)))
(.decay (react/animated)
anim-value
(clj->js (add-native-driver config))))
(defn anim-sequence [animations]
(.sequence (react/animated) (clj->js animations)))

View File

@ -4,7 +4,7 @@
[status-im.utils.platform :as platform]))
(defnstyle text-wrapper
[{:keys [window-width modal? height background-color opacity]}]
[{:keys [window-width height background-color opacity]}]
(cond-> {:flex-direction :row
:justify-content :center
:opacity opacity

View File

@ -6,7 +6,8 @@
[status-im.i18n :as i18n]
[status-im.ui.components.colors :as colors]
[status-im.ui.components.animation :as animation]
[status-im.utils.utils :as utils]))
[status-im.utils.utils :as utils]
[status-im.utils.platform :as platform]))
(defn easing [direction n]
{:toValue n
@ -71,12 +72,14 @@
{:toValue 0
:delay 800
:duration 150
:easing (.-ease (animation/easing))})
:easing (.-ease (animation/easing))
:useNativeDriver true})
(animation/timing anim-height
{:toValue 0
{:toValue (if platform/desktop? 0 -35)
:delay 800
:duration 150
:easing (.-ease (animation/easing))})]))
:easing (.-ease (animation/easing))
:useNativeDriver true})]))
(utils/set-timeout
#(reset! show-connected? false)
2000))
@ -86,31 +89,33 @@
[(animation/timing anim-opacity
{:toValue 1
:duration 150
:easing (.-ease (animation/easing))})
:easing (.-ease (animation/easing))
:useNativeDriver true})
(animation/timing anim-height
{:toValue 35
{:toValue (if platform/desktop? 35 0)
:duration 150
:easing (.-ease (animation/easing))})])))))
:easing (.-ease (animation/easing))
:useNativeDriver true})])))))
(defn connectivity-status
[{:keys [connected?]}]
(let [anim-opacity (animation/create-value 0)
anim-height (animation/create-value 0)]
[{:keys [connected?]} anim-translate-y]
(let [anim-translate-y (or anim-translate-y (animation/create-value 0))
anim-opacity (animation/create-value 0)]
(manage-visibility connected?
anim-opacity anim-height)
anim-opacity anim-translate-y)
(reagent/create-class
{:component-did-update
(fn [comp]
(manage-visibility (:connected? (reagent/props comp))
anim-opacity anim-height))
anim-opacity anim-translate-y))
:reagent-render
(fn [{:keys [view-id message on-press-fn
connected? connecting? loading-indicator?] :as opts}]
(when (or (not connected?)
@show-connected?)
connected? connecting?] :as opts}]
[react/animated-view {:style (styles/text-wrapper
(assoc opts
:height anim-height
:height (if platform/desktop?
anim-translate-y
35)
:background-color (if connected?
colors/green
colors/gray)
@ -129,9 +134,20 @@
(i18n/label :t/waiting-for-wifi-change)]]
[react/text {:style styles/text
:on-press on-press-fn}
(i18n/label message)])]))})))
(i18n/label message)])])})))
(defview connectivity-view []
(defn connectivity-animation-wrapper [style anim-value & content]
(vec (concat
(if platform/desktop?
[react/view {:style {:flex 1}}]
[react/animated-view
{:style
(merge {:flex 1
:transform [{:translateY anim-value}]}
style)}])
content)))
(defview connectivity-view [anim-translate-y]
(letsubs [status-properties [:connectivity/status-properties]
view-id [:view-id]
window-width [:dimensions/window-width]]
@ -142,4 +158,5 @@
[connectivity-status
(merge status-properties
{:view-id view-id
:window-width window-width})]])))
:window-width window-width})
anim-translate-y]])))

View File

@ -248,15 +248,17 @@
To render something on empty sections, use renderSectionFooter and conditionaly
render on empty data
See https://facebook.github.io/react-native/docs/sectionlist.html"
[{:keys [sections render-section-header-fn render-section-footer-fn] :as props
:or {render-section-header-fn default-render-section-header}}]
[{:keys [sections render-section-header-fn render-section-footer-fn style] :as props
:or {render-section-header-fn default-render-section-header
style {}}}]
[(section-list-class)
(merge (base-list-props props)
props
(when render-section-footer-fn
{:renderSectionFooter (wrap-render-section-header-fn render-section-footer-fn)})
{:sections (clj->js (map wrap-per-section-render-fn sections))
:renderSectionHeader (wrap-render-section-header-fn render-section-header-fn)})])
:renderSectionHeader (wrap-render-section-header-fn render-section-header-fn)
:style style})])
(defn render-action [{:keys [label subtext accessibility-label icon action disabled?]}
{:keys [action-style action-label-style action-subtext-style icon-opts]}]

View File

@ -183,11 +183,13 @@
(def message-view-preview
{:flex 1
:align-items :center
:justify-content :center})
:justify-content :center
:background-color :white})
(defn message-view-animated [opacity]
{:opacity opacity
:flex 1})
:flex 1
:background-color :white})
(def empty-chat-container
{:flex 1

View File

@ -50,7 +50,7 @@
(defn chat-toolbar
[{:keys [chat-name group-chat chat-id contact]} public? modal?]
[react/view
[react/view {:style {:z-index 100}}
[status-bar/status-bar (when modal? {:type :modal-white})]
[toolbar/toolbar
{:chat? true}
@ -65,7 +65,6 @@
:icon-opts {:color :black
:accessibility-label :chat-menu-button}
:handler #(on-options chat-id chat-name group-chat public?)}]])]
[connectivity/connectivity-view]
(when (and (not group-chat)
(not (contact.db/added? contact)))
[add-contact-bar chat-id])])
@ -354,7 +353,8 @@
:input-focused? false}]))}
(let [no-messages (empty? messages)
flat-list-conf
{:data messages
{:style {:margin-bottom -35}
:data messages
:ref #(reset! messages-list-ref %)
:footer [chat-intro-header-container chat no-messages]
:key-fn #(or (:message-id %) (:value %))
@ -430,7 +430,8 @@
[:chats/current-chat]
current-chat-id [:chats/current-chat-id]
show-message-options? [:chats/current-chat-ui-prop :show-message-options?]
show-stickers? [:chats/current-chat-ui-prop :show-stickers?]]
show-stickers? [:chats/current-chat-ui-prop :show-stickers?]
anim-translate-y (animation/create-value -35)]
;; this check of current-chat-id is necessary only because in a fresh public chat creation sometimes
;; this component renders before current-chat-id is set to current chat-id. Hence further down in sub
;; components (e.g. chat-toolbar) there can be a brief visual inconsistancy like showing 'add contact'
@ -447,11 +448,15 @@
:on-layout (fn [e]
(re-frame/dispatch [:set :layout-height (-> e .-nativeEvent .-layout .-height)]))}
[chat-toolbar current-chat public? modal?]
[connectivity/connectivity-view anim-translate-y]
[connectivity/connectivity-animation-wrapper
{}
anim-translate-y
[messages-view-animation
;;TODO(kozieiev) : When FlatList in react-native-desktop become viable it should be used instead of optimized ScrollView for chat
(if platform/desktop?
[messages-view-desktop current-chat modal?]
[messages-view current-chat modal?])]
[messages-view current-chat modal?])]]
(when show-input?
[input/container])
(when show-stickers?

View File

@ -26,7 +26,8 @@
[status-im.utils.utils :as utils]
[status-im.ui.screens.desktop.main.chat.emoji :as emoji]
[status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.screens.chat.message.gap :as gap])
[status-im.ui.screens.chat.message.gap :as gap]
[status-im.ui.components.animation :as animation])
(:require-macros [status-im.utils.views :as views]))
(defn toolbar-chat-view

View File

@ -55,6 +55,7 @@
(defn show-search!
[]
(swap! search-input-state assoc :show? true)
(animation/start
(animation/timing (:height @search-input-state)
{:toValue 0
@ -69,6 +70,9 @@
(defn hide-search!
[]
(utils/set-timeout
#(swap! search-input-state assoc :show? false)
350)
(animation/start
(animation/timing (:height @search-input-state)
{:toValue (- styles/search-input-height)
@ -108,7 +112,8 @@
(defn home-filtered-items-list
[chats]
[list/section-list
{:sections [{:title :t/chats
{:style {:margin-bottom -35}
:sections [{:title :t/chats
:data chats}
{:title :t/messages
:data []}]

View File

@ -15,7 +15,8 @@
[status-im.ui.components.bottom-bar.styles :as tabs.styles]
[status-im.ui.screens.home.views.inner-item :as inner-item]
[status-im.ui.components.common.common :as components.common]
[status-im.ui.components.list-selection :as list-selection])
[status-im.ui.components.list-selection :as list-selection]
[status-im.ui.components.animation :as animation])
(:require-macros [status-im.utils.views :as views]))
(views/defview les-debug-info []
@ -65,6 +66,7 @@
[filter.views/home-filtered-items-list chats]
[react/animated-view
(merge {:style {:flex 1
:margin-bottom -35
:background-color :white
:transform [{:translateY (:height @search-input-state)}]}}
(when @scrolling-from-top?
@ -87,7 +89,8 @@
previous-position)))
(filter.views/show-search!)))
false)}))
[list/flat-list {:data all-home-items
[list/flat-list {:style {:margin-bottom (- styles/search-input-height)}
:data all-home-items
:key-fn first
:footer [react/view
{:style {:height tabs.styles/tabs-diff
@ -99,7 +102,10 @@
(zero? (.-y (.-contentOffset (.-nativeEvent e))))))
:render-fn
(fn [home-item]
[inner-item/home-list-item home-item])}]]))))
[inner-item/home-list-item home-item])}]
(when (:show? @search-input-state)
[react/view {:width 1
:height styles/search-input-height}])]))))
(views/defview home-action-button []
(views/letsubs [logging-in? [:accounts/login]]
@ -113,7 +119,9 @@
[icons/icon :main-icons/add {:color :white}])]]]))
(views/defview home [loading?]
(views/letsubs [{:keys [search-filter chats all-home-items]} [:home-items]]
(views/letsubs
[anim-translate-y (animation/create-value -35)
{:keys [search-filter chats all-home-items]} [:home-items]]
{:component-did-mount (fn [this]
(let [[_ loading?] (.. this -props -argv)]
(when loading? (utils/set-timeout #(re-frame/dispatch [:init-rest-of-chats]) 100))))}
@ -133,18 +141,28 @@
[react/view {:style {:flex 1
:justify-content :center
:align-items :center}}
[connectivity/connectivity-view]
[connectivity/connectivity-view anim-translate-y]
[connectivity/connectivity-animation-wrapper
{}
anim-translate-y
[react/activity-indicator {:flex 1
:animating true}]]
:animating true}]]]
:else
[react/view {:style {:flex 1}}
[connectivity/connectivity-view]
[connectivity/connectivity-view anim-translate-y]
[connectivity/connectivity-animation-wrapper
{}
anim-translate-y
[filter.views/search-input-wrapper search-filter]
(if (and (not search-filter)
(empty? all-home-items))
[home-empty-view]
[home-items-view search-filter chats all-home-items filter.views/search-input-state])])]
[home-items-view
search-filter
chats
all-home-items
filter.views/search-input-state])]])]
[home-action-button]]]))
(views/defview home-wrapper []