-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switcher and Bottom Tabs Animations and UI Performance Improvements
- Migrated Switcher animations to Reanimated V2 - Added bottom tabs & Stacks Animations - Improved bottom tabs, tab changing performance - Polished android & IOS UI
- Loading branch information
1 parent
042ce72
commit daddb3e
Showing
24 changed files
with
337 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
(ns status-im.navigation2.stack-with-switcher | ||
(:require [status-im.switcher.switcher :as switcher])) | ||
(:require [quo.react-native :as rn] | ||
[status-im.utils.platform :as platform] | ||
[status-im.switcher.switcher :as switcher])) | ||
|
||
(defn overlap-stack [comp view-id] | ||
[:<> | ||
[rn/view {:style {:flex 1 | ||
:margin-bottom (if platform/ios? 30 0)}} | ||
[comp] | ||
[switcher/switcher view-id]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,67 @@ | ||
(ns status-im.switcher.animation | ||
(:require [quo.react-native :as rn] | ||
[reagent.core :as reagent] | ||
[status-im.switcher.constants :as constants] | ||
[status-im.ui.components.animation :as anim])) | ||
|
||
(def bottom-tabs-opacity (anim/create-value 1)) | ||
(def bottom-tabs-position (anim/create-value 0)) | ||
|
||
;; TODO(parvesh): Use 300, after using dispatch-later for opening card(otherwise pending animation issue) | ||
;; or OnAnimationEnd | ||
(def layout-animation #js {:duration 250 | ||
:create #js {:type (:ease-in-ease-out rn/layout-animation-types) | ||
:property (:scale-xy rn/layout-animation-properties)} | ||
:update #js {:type (:ease-in-ease-out rn/layout-animation-types) | ||
:property (:scale-xy rn/layout-animation-properties)} | ||
:delete #js {:type (:ease-in-ease-out rn/layout-animation-types) | ||
:property (:scale-xy rn/layout-animation-properties)}}) | ||
|
||
(defn animate-layout [show? anim-values] | ||
(let [{:keys [width height]} (constants/dimensions) | ||
target-radius (- (max width height) | ||
constants/switcher-button-radius)] | ||
(rn/configure-next layout-animation) | ||
(reset! (:switcher-screen-radius anim-values) (if show? target-radius 1)) | ||
(reagent/flush))) | ||
|
||
(defn timing-animation [property toValue] | ||
(anim/timing property {:toValue toValue | ||
:duration 300 | ||
:useNativeDriver true})) | ||
|
||
(defn animate-components [show? view-id anim-values] | ||
(anim/start | ||
(anim/parallel | ||
(into | ||
[(timing-animation (:switcher-button-opacity anim-values) (if show? 0 1)) | ||
(timing-animation (:switcher-close-button-icon-opacity anim-values) (if show? 1 0)) | ||
(timing-animation (:switcher-close-button-background-opacity anim-values) (if show? 0.2 0))] | ||
(when (= view-id :home-stack) | ||
[(timing-animation bottom-tabs-opacity (if show? 0 1)) | ||
(timing-animation bottom-tabs-position (if show? (constants/bottom-tabs-height) 0))]))))) | ||
|
||
(defn animate [show? view-id anim-values] | ||
(reagent/flush) | ||
(animate-layout show? anim-values) | ||
(animate-components show? view-id anim-values)) | ||
(:require [clojure.string :as string] | ||
[quo2.reanimated :as reanimated] | ||
[status-im.switcher.constants :as constants])) | ||
|
||
;;;; Switcher Animations | ||
|
||
;; Component Animations | ||
(defn switcher-touchable-on-press-in | ||
[touchable-scale] | ||
(reanimated/animate-shared-value-with-timing touchable-scale constants/switcher-pressed-scale 300 :easing1)) | ||
|
||
(defn switcher-touchable-on-press-out [switcher-opened? view-id shared-values] | ||
(let [{:keys [width height]} (constants/dimensions) | ||
switcher-bottom-position (constants/switcher-pressed-bottom-position view-id) | ||
switcher-target-radius (Math/hypot | ||
(/ width 2) | ||
(- height constants/switcher-pressed-radius switcher-bottom-position)) | ||
switcher-size (* 2 switcher-target-radius)] | ||
(reanimated/animate-shared-value-with-timing (:button-touchable-scale shared-values) 1 300 :easing1) | ||
(if @switcher-opened? | ||
(do | ||
(reanimated/animate-shared-value-with-timing (:switcher-button-opacity shared-values) 1 300 :easing1) | ||
(reanimated/animate-shared-value-with-timing (:switcher-screen-size shared-values) constants/switcher-pressed-size 300 :linear) | ||
(reanimated/animate-shared-value-with-timing (:switcher-container-scale shared-values) 0.9 300 :linear)) | ||
(do | ||
(reanimated/animate-shared-value-with-timing (:switcher-button-opacity shared-values) 0 300 :easing1) | ||
(reanimated/animate-shared-value-with-timing (:switcher-screen-size shared-values) switcher-size 300 :linear) | ||
(reanimated/animate-shared-value-with-timing (:switcher-container-scale shared-values) 1 300 :linear))) | ||
(swap! switcher-opened? not))) | ||
|
||
;; Derived Values | ||
|
||
(defn switcher-close-button-opacity [switcher-button-opacity] | ||
(.switcherCloseButtonOpacity ^js reanimated/worklet-factory switcher-button-opacity)) | ||
|
||
(defn switcher-screen-radius [switcher-screen-size] | ||
(.switcherScreenRadius ^js reanimated/worklet-factory switcher-screen-size)) | ||
|
||
(defn switcher-screen-bottom-position [switcher-screen-radius view-id] | ||
(.switcherScreenBottomPosition ^js reanimated/worklet-factory | ||
switcher-screen-radius | ||
constants/switcher-pressed-radius | ||
(constants/switcher-pressed-bottom-position view-id))) | ||
|
||
(defn switcher-container-bottom-position [switcher-screen-bottom] | ||
(.switcherContainerBottomPosition ^js reanimated/worklet-factory | ||
switcher-screen-bottom | ||
(+ constants/switcher-container-height-padding | ||
constants/switcher-height-offset))) | ||
|
||
|
||
;;;; Bottom Tabs & Home Stack Animations | ||
|
||
|
||
(defn bottom-tab-on-press [shared-values selected-tab-id] | ||
(let [selected-tab (get (string/split (name selected-tab-id) #"-") 0)] | ||
(doseq [tab constants/tabs] | ||
(let [selected-tab? (= tab selected-tab) | ||
tab-opacity-shared-value (get shared-values (keyword (str tab "-tab-opacity"))) | ||
stack-opacity-shared-value (get shared-values (keyword (str tab "-stack-opacity"))) | ||
stack-pointer-shared-value (get shared-values (keyword (str tab "-stack-pointer")))] | ||
(reanimated/animate-shared-value-with-timing tab-opacity-shared-value (if selected-tab? 1 0) 300 :easing3) | ||
(reanimated/set-shared-value stack-pointer-shared-value (if selected-tab? "auto" "none")) | ||
(if selected-tab? | ||
(reanimated/animate-shared-value-with-delay stack-opacity-shared-value 1 300 :easing3 150) | ||
(reanimated/animate-shared-value-with-timing stack-opacity-shared-value 0 300 :easing3)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,68 @@ | ||
(ns status-im.switcher.bottom-tabs | ||
(:require [quo.react-native :as rn] | ||
[reagent.core :as reagent] | ||
[re-frame.core :as re-frame] | ||
[quo2.reanimated :as reanimated] | ||
[status-im.switcher.styles :as styles] | ||
[status-im.switcher.animation :as animation] | ||
[status-im.ui.components.icons.icons :as icons])) | ||
|
||
(def selected-tab-id (reagent/atom :chats-stack)) | ||
(def selected-tab-id (atom :communities-stack)) | ||
|
||
(defn bottom-tab-pressed [tab-id] | ||
;; Reagent atoms used for lazily loading home screen tabs | ||
(def load-communities-tab? (reagent/atom true)) | ||
(def load-chats-tab? (reagent/atom false)) | ||
(def load-wallet-tab? (reagent/atom false)) | ||
(def load-browser-tab? (reagent/atom false)) | ||
|
||
(re-frame/reg-fx | ||
:new-ui/reset-bottom-tabs | ||
(fn [] | ||
(reset! selected-tab-id :communities-stack) | ||
(reset! load-communities-tab? true) | ||
(reset! load-chats-tab? false) | ||
(reset! load-wallet-tab? false) | ||
(reset! load-browser-tab? false))) | ||
|
||
(defn bottom-tab-on-press [shared-values tab-id] | ||
(when-not (= tab-id @selected-tab-id) | ||
(reset! selected-tab-id tab-id))) | ||
(reset! selected-tab-id tab-id) | ||
(animation/bottom-tab-on-press shared-values tab-id) | ||
(case tab-id | ||
:communities-stack (reset! load-communities-tab? true) | ||
:chats-stack (reset! load-chats-tab? true) | ||
:wallet-stack (reset! load-wallet-tab? true) | ||
:browser-stack (reset! load-browser-tab? true)))) | ||
|
||
;; TODO(parvesh) - reimplement tab with counter, once design is complete | ||
;; (implement natively, for performance improvement) | ||
(defn bottom-tab [icon tab-id] | ||
[rn/touchable-opacity {:style {:padding 15} | ||
:active-opacity 1 | ||
:on-press #(bottom-tab-pressed tab-id)} | ||
[icons/icon icon (styles/bottom-tab-icon | ||
(if (= tab-id @selected-tab-id) | ||
:bottom-tabs-selected-tab | ||
:bottom-tabs-non-selected-tab))]]) | ||
(defn bottom-tab [icon tab icons-only? shared-values] | ||
[:> | ||
(fn [] | ||
(let [tab-id (keyword (str tab "-stack")) | ||
bottom-tab-original-style {:padding 16}] | ||
(reagent/as-element | ||
(if icons-only? | ||
[rn/touchable-opacity {:active-opacity 1 | ||
:style bottom-tab-original-style | ||
:on-press #(bottom-tab-on-press shared-values tab-id)} | ||
[reanimated/view {:style (reanimated/apply-animations-to-style | ||
{:opacity (get | ||
shared-values | ||
(keyword (str tab "-tab-opacity")))} | ||
{})} | ||
[icons/icon icon (styles/bottom-tab-icon :bottom-tabs-selected-tab)]]] | ||
[rn/view {:style bottom-tab-original-style} | ||
[icons/icon icon (styles/bottom-tab-icon :bottom-tabs-non-selected-tab)]]))))]) | ||
|
||
(defn tabs [shared-values icons-only?] | ||
[rn/view {:style (styles/bottom-tabs icons-only?)} | ||
[bottom-tab :main-icons/redesign-communities "communities" icons-only? shared-values] | ||
[bottom-tab :main-icons/redesign-messages "chats" icons-only? shared-values] | ||
[rn/view {:width 50}] | ||
[bottom-tab :main-icons/redesign-wallet "wallet" icons-only? shared-values] | ||
[bottom-tab :main-icons/redesign-browser "browser" icons-only? shared-values]]) | ||
|
||
(defn bottom-tabs [] | ||
[rn/animated-view {:style (styles/bottom-tabs)} | ||
[bottom-tab :main-icons/redesign-messages :chats-stack] | ||
[bottom-tab :main-icons/communities :communities-stack] | ||
[rn/view {:width 10}] | ||
[bottom-tab :main-icons/redesign-wallet :wallet-stack] | ||
[bottom-tab :main-icons/browser :browser-stack]]) | ||
(defn bottom-tabs [shared-values] | ||
[:<> | ||
[tabs shared-values false] | ||
[tabs shared-values true]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.