Merge pull request #490 from status-im/bug/#488

Chats/Discover/Contacts tabs menu animation iOS (#488)
This commit is contained in:
Roman Volosovskyi 2016-11-27 16:19:08 +02:00 committed by GitHub
commit 83ab4b8dff
3 changed files with 19 additions and 22 deletions

View File

@ -19,9 +19,8 @@
[status-im.components.tabs.tabs :refer [tabs]] [status-im.components.tabs.tabs :refer [tabs]]
[status-im.components.tabs.styles :as st] [status-im.components.tabs.styles :as st]
[status-im.components.styles :as common-st] [status-im.components.styles :as common-st]
[status-im.i18n :refer [label]])) [status-im.i18n :refer [label]]
[taoensso.timbre :as log]))
(def window-width (:width (get-dimensions "window")))
(def tab-list (def tab-list
[{:view-id :chat-list [{:view-id :chat-list
@ -70,17 +69,20 @@
n (get-tab-index view-id)] n (get-tab-index view-id)]
(- n p))) (- n p)))
(defn on-scroll-end [swiped?] (defn on-scroll-end [swiped? dragging?]
(fn [_ state] (fn [_ state]
(when @dragging?
(reset! dragging? false)
(let [{:strs [index]} (js->clj state)] (let [{:strs [index]} (js->clj state)]
(reset! swiped? true) (reset! swiped? true)
(dispatch [:navigate-to-tab (index->tab index)])))) (dispatch [:navigate-to-tab (index->tab index)])))))
(defn main-tabs [] (defn main-tabs []
(let [view-id (subscribe [:get :view-id]) (let [view-id (subscribe [:get :view-id])
prev-view-id (subscribe [:get :prev-view-id]) prev-view-id (subscribe [:get :prev-view-id])
main-swiper (atom nil) main-swiper (r/atom nil)
swiped? (atom false)] swiped? (r/atom false)
dragging? (r/atom false)]
(r/create-class (r/create-class
{:component-will-update {:component-will-update
(fn [] (fn []
@ -101,7 +103,8 @@
{:index (get-tab-index @view-id) {:index (get-tab-index @view-id)
:loop false :loop false
:ref #(reset! main-swiper %) :ref #(reset! main-swiper %)
:on-momentum-scroll-end (on-scroll-end swiped?)}) :onScrollBeginDrag #(reset! dragging? true)
:on-momentum-scroll-end (on-scroll-end swiped? dragging?)})
[chats-list] [chats-list]
[discovery (= @view-id :discovery)] [discovery (= @view-id :discovery)]
[contact-list]] [contact-list]]

View File

@ -4,16 +4,15 @@
(def tabs-height 60) (def tabs-height 60)
(def tab-height 58) (def tab-height 58)
(defn tabs-container [hidden? animation? offset-y] (defn tabs-container [hidden?]
{:position :absolute {:position :absolute
:bottom 0 :bottom 0
:left 0 :left 0
:right 0 :right 0
:height tabs-height :height tabs-height
:backgroundColor color-white :backgroundColor color-white
:marginBottom (if (or hidden? animation?) :marginBottom (if hidden? (- tabs-height) 0)
(- tabs-height) 0) :transform [{:translateY 1}]})
:transform [{:translateY (if animation? offset-y 1)}]})
(def bottom-gradient (def bottom-gradient
{:position :absolute {:position :absolute

View File

@ -28,15 +28,10 @@
(swap! was-hidden? not) (swap! was-hidden? not)
(anim/start (anim/start
(anim/timing val {:toValue to-value (anim/timing val {:toValue to-value
:duration 300}) :duration 300})))))))
(fn [e]
;; if to-value was changed, then new animation has started
(when (= to-value (if @hidden? 0 (- st/tabs-height)))
(dispatch [:set-animation :tabs-bar-animation? false])))))))))
(defn tabs-container [& children] (defn tabs-container [& children]
(let [chats-scrolled? (subscribe [:get :chats-scrolled?]) (let [chats-scrolled? (subscribe [:get :chats-scrolled?])
animation? (subscribe [:animations :tabs-bar-animation?])
tabs-bar-value (subscribe [:animations :tabs-bar-value]) tabs-bar-value (subscribe [:animations :tabs-bar-value])
context {:hidden? chats-scrolled? context {:hidden? chats-scrolled?
:val @tabs-bar-value} :val @tabs-bar-value}
@ -50,11 +45,11 @@
:reagent-render :reagent-render
(fn [& children] (fn [& children]
@chats-scrolled? @chats-scrolled?
(into [animated-view {:style (st/tabs-container @chats-scrolled? @animation? @tabs-bar-value) (into [animated-view {:style (st/tabs-container @chats-scrolled?)
:pointerEvents (if @chats-scrolled? :none :auto)}] :pointerEvents (if @chats-scrolled? :none :auto)}]
children))}))) children))})))
(defn tabs [{:keys [tab-list selected-view-id prev-view-id]}] (defn tabs [{:keys [tab-list selected-view-id prev-view-id swiper]}]
[tabs-container [tabs-container
[view st/tabs-inner-container [view st/tabs-inner-container
(doall (map-indexed #(create-tab %1 %2 selected-view-id prev-view-id) tab-list))]]) (doall (map-indexed #(create-tab %1 %2 selected-view-id prev-view-id) tab-list))]])