Skip to content

Commit

Permalink
Implement animations for discover communities screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Parveshdhull committed Oct 9, 2023
1 parent b432aab commit 0f8bf3c
Show file tree
Hide file tree
Showing 12 changed files with 163 additions and 115 deletions.
10 changes: 6 additions & 4 deletions src/js/worklets/shell/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export const OPEN_WITH_ANIMATION = 3;
// Floating Screen States
export const CLOSE_SCREEN_WITHOUT_ANIMATION = 0;
export const OPEN_SCREEN_WITHOUT_ANIMATION = 1;
export const CLOSE_SCREEN_WITH_SLIDE_ANIMATION = 2;
export const OPEN_SCREEN_WITH_SLIDE_ANIMATION = 3;
export const CLOSE_SCREEN_WITH_SHELL_ANIMATION = 4;
export const OPEN_SCREEN_WITH_SHELL_ANIMATION = 5;
export const CLOSE_SCREEN_WITH_SHELL_ANIMATION = 2;
export const OPEN_SCREEN_WITH_SHELL_ANIMATION = 3;
export const CLOSE_SCREEN_WITH_SLIDE_TO_RIGHT_ANIMATION = 4;
export const OPEN_SCREEN_WITH_SLIDE_FROM_RIGHT_ANIMATION = 5;
export const CLOSE_SCREEN_WITH_SLIDE_TO_BOTTOM_ANIMATION = 6;
export const OPEN_SCREEN_WITH_SLIDE_FROM_BOTTOM_ANIMATION = 7;

export const SHELL_ANIMATION_TIME = 200;

Expand Down
47 changes: 36 additions & 11 deletions src/js/worklets/shell/floating_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,58 @@ export function screenLeft(screenState, screenWidth, switcherCardLeftPosition) {
return useDerivedValue(function () {
'worklet';
switch (screenState.value) {
case constants.CLOSE_SCREEN_WITH_SLIDE_ANIMATION:
return withTiming(screenWidth, constants.EASE_OUT_EASING);
case constants.OPEN_SCREEN_WITH_SLIDE_ANIMATION:
return withTiming(0, constants.EASE_OUT_EASING);
case constants.CLOSE_SCREEN_WITHOUT_ANIMATION:
return screenWidth;
case constants.OPEN_SCREEN_WITHOUT_ANIMATION:
// Note - don't use return 0; its not working in ios
// https://github.com/software-mansion/react-native-reanimated/issues/3296#issuecomment-1573900172
return withSequence(withTiming(-1, { duration: 0 }), withTiming(0, { duration: 0 }));
case constants.CLOSE_SCREEN_WITH_SHELL_ANIMATION:
return withTiming(switcherCardLeftPosition, constants.EASE_OUT_EASING);
return withSequence(
withTiming(switcherCardLeftPosition, constants.EASE_OUT_EASING),
withTiming(screenWidth, { duration: 0 }),
);
case constants.OPEN_SCREEN_WITH_SHELL_ANIMATION:
return withTiming(0, constants.EASE_OUT_EASING);
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_RIGHT_ANIMATION:
return withTiming(screenWidth, constants.EASE_OUT_EASING);
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_RIGHT_ANIMATION:
return withTiming(0, constants.EASE_OUT_EASING);
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_BOTTOM_ANIMATION:
return withDelay(constants.SHELL_ANIMATION_TIME, withTiming(screenWidth, { duration: 0 }));
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_BOTTOM_ANIMATION:
return 0;
default:
return screenWidth;
}
});
}

export function screenTop(screenState, switcherCardTopPosition) {
export function screenTop(screenState, screenHeight, switcherCardTopPosition) {
return useDerivedValue(function () {
'worklet';
switch (screenState.value) {
case constants.CLOSE_SCREEN_WITHOUT_ANIMATION:
return screenHeight;
case constants.OPEN_SCREEN_WITHOUT_ANIMATION:
return withSequence(withTiming(-1, { duration: 0 }), withTiming(0, { duration: 0 }));
case constants.CLOSE_SCREEN_WITH_SHELL_ANIMATION:
return withTiming(switcherCardTopPosition, constants.EASE_OUT_EASING);
return withSequence(
withTiming(switcherCardTopPosition, constants.EASE_OUT_EASING),
withTiming(screenHeight, { duration: 0 }),
);
case constants.OPEN_SCREEN_WITH_SHELL_ANIMATION:
return withTiming(0, constants.EASE_OUT_EASING);
default:
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_RIGHT_ANIMATION:
return withDelay(constants.SHELL_ANIMATION_TIME, withTiming(screenHeight, { duration: 0 }));
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_RIGHT_ANIMATION:
return 0;
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_BOTTOM_ANIMATION:
return withTiming(screenHeight, constants.EASE_OUT_EASING);
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_BOTTOM_ANIMATION:
return withTiming(0, constants.EASE_OUT_EASING);
default:
return screenHeight;
}
});
}
Expand Down Expand Up @@ -79,7 +101,8 @@ export function screenZIndex(screenState) {
'worklet';
switch (screenState.value) {
case constants.CLOSE_SCREEN_WITH_SHELL_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SLIDE_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_RIGHT_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_BOTTOM_ANIMATION:
return withDelay(constants.SHELL_ANIMATION_TIME, withTiming(-1, { duration: 0 }));
case constants.CLOSE_SCREEN_WITHOUT_ANIMATION:
return -1;
Expand All @@ -95,10 +118,12 @@ export function screenBorderRadius(screenState) {
switch (screenState.value) {
case constants.OPEN_SCREEN_WITH_SHELL_ANIMATION:
return withDelay(constants.SHELL_ANIMATION_TIME, withTiming(0, { duration: 0 }));
case constants.OPEN_SCREEN_WITH_SLIDE_ANIMATION:
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_RIGHT_ANIMATION:
case constants.OPEN_SCREEN_WITH_SLIDE_FROM_BOTTOM_ANIMATION:
case constants.OPEN_SCREEN_WITHOUT_ANIMATION:
return 0;
case constants.CLOSE_SCREEN_WITH_SLIDE_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_RIGHT_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SLIDE_TO_BOTTOM_ANIMATION:
return withDelay(constants.SHELL_ANIMATION_TIME, withTiming(20, { duration: 0 }));
case constants.CLOSE_SCREEN_WITHOUT_ANIMATION:
case constants.CLOSE_SCREEN_WITH_SHELL_ANIMATION:
Expand Down
12 changes: 0 additions & 12 deletions src/status_im/communities/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -780,18 +780,6 @@
:on-success #(re-frame/dispatch [:sanitize-messages-and-process-response %])
:on-error #(log/error "failed to reorder community category" %)}]})

;; Note - dispatch is used to make sure we are opening community once `pop-to-root` is processed.
;; Don't directly merge effects using `navigation/navigate-to`, because it will work in debug and
;; release, but for e2e `pop-to-root` closes even currently opened community
;; https://github.com/status-im/status-mobile/pull/16438#issuecomment-1623954774
(rf/defn navigate-to-community
{:events [:communities/navigate-to-community]}
[cofx community-id]
(rf/merge
cofx
{:dispatch [:navigate-to :community-overview community-id]}
(navigation/pop-to-root :shell-stack)))

(rf/defn member-role-updated
{:events [:community.member/role-updated]}
[cofx response-js]
Expand Down
8 changes: 4 additions & 4 deletions src/status_im/ui/screens/chat/message/legacy_view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@
[rn/text {:style {:color quo.colors/black}} description]]]
[rn/view (style/community-view-button)
[rn/touchable-opacity
{:on-press #(do (rf/dispatch
[:communities/navigate-to-community
(:id community)])
(rf/dispatch [:chat/close]))}
{:on-press #(do
(rf/dispatch [:pop-to-root :shell-stack])
(rf/dispatch [:navigate-to :community-overview (:id community)])
(rf/dispatch [:chat/close]))}
[rn/text
{:style {:text-align :center
:color quo.colors/blue}} (i18n/label :t/view)]]]])))
Expand Down
16 changes: 11 additions & 5 deletions src/status_im2/contexts/communities/discover/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
[quo/community-card-view-item
{:community (assoc item :cover cover)
:width width
:on-press #(rf/dispatch [:communities/navigate-to-community (:id item)])}]
:on-press #(rf/dispatch [:navigate-to :community-overview (:id item)])}]
[quo/community-list-item
{:on-press (fn []
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:communities/navigate-to-community (:id item)]))
(rf/dispatch [:navigate-to :community-overview (:id item)]))
:on-long-press #(rf/dispatch
[:show-bottom-sheet
{:content (fn []
Expand Down Expand Up @@ -142,12 +142,12 @@
(if (= view-type :card-view)
[quo/community-card-view-item
{:community (assoc community :cover cover)
:on-press #(rf/dispatch [:communities/navigate-to-community (:id community)])}]
:on-press #(rf/dispatch [:navigate-to :community-overview (:id community)])}]

[quo/community-list-item
{:on-press (fn []
(rf/dispatch [:dismiss-keyboard])
(rf/dispatch [:communities/navigate-to-community (:id community)]))
(rf/dispatch [:navigate-to :community-overview (:id community)]))
:on-long-press #(js/alert "TODO: to be implemented")}
community])]))
(if communities communities communities-ids))
Expand Down Expand Up @@ -232,7 +232,13 @@
{:style (style/discover-screen-container (colors/theme-colors
colors/white
colors/neutral-95))}
[discover-screen-content featured-communities theme]]))
[discover-screen-content featured-communities theme]
[quo/floating-shell-button
{:jump-to {:on-press #(rf/dispatch [:shell/navigate-to-jump-to])
:customization-color :blue
:label (i18n/label :t/jump-to)}}
{:position :absolute
:bottom 34}]]))


(defn- internal-discover-view
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
(ns status-im2.contexts.shell.jump-to.components.floating-screens.view
(:require [utils.re-frame :as rf]
[react-native.core :as rn]
[quo2.theme :as quo.theme]
[react-native.reanimated :as reanimated]
[status-im2.contexts.chat.messages.view :as chat]
[status-im2.contexts.shell.jump-to.state :as state]
[status-im2.contexts.shell.jump-to.utils :as utils]
[status-im2.contexts.shell.jump-to.animation :as animation]
[status-im2.contexts.shell.jump-to.constants :as shell.constants]
[status-im2.contexts.communities.overview.view :as communities.overview]
[status-im2.contexts.shell.jump-to.components.floating-screens.style :as style]
[quo2.theme :as quo.theme]))
[status-im2.contexts.communities.discover.view :as communities.discover]
[status-im2.contexts.shell.jump-to.components.floating-screens.style :as style]))

(def screens-map
{shell.constants/community-screen communities.overview/overview
shell.constants/chat-screen chat/chat})
{shell.constants/chat-screen chat/chat
shell.constants/community-screen communities.overview/overview
shell.constants/discover-communities-screen communities.discover/view})

(defn f-screen
[{:keys [screen-id id animation clock] :as screen-param}]
Expand Down Expand Up @@ -45,5 +47,6 @@
(defn view
[]
[:<>
[lazy-screen shell.constants/discover-communities-screen]
[lazy-screen shell.constants/community-screen]
[lazy-screen shell.constants/chat-screen]])
15 changes: 9 additions & 6 deletions src/status_im2/contexts/shell/jump_to/constants.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,21 @@
(def ^:const communities-discover 9)

;; Floating Screens
(def ^:const community-screen :community-overview)
(def ^:const chat-screen :chat)
(def ^:const community-screen :community-overview)
(def ^:const discover-communities-screen :discover-communities)

(def ^:const floating-screens [chat-screen community-screen])
(def ^:const floating-screens [chat-screen community-screen discover-communities-screen])

;; Floating Screen states
(def ^:const close-screen-without-animation 0)
(def ^:const open-screen-without-animation 1)
(def ^:const close-screen-with-slide-animation 2)
(def ^:const open-screen-with-slide-animation 3)
(def ^:const close-screen-with-shell-animation 4)
(def ^:const open-screen-with-shell-animation 5)
(def ^:const close-screen-with-shell-animation 2)
(def ^:const open-screen-with-shell-animation 3)
(def ^:const close-screen-with-slide-to-right-animation 4)
(def ^:const open-screen-with-slide-from-right-animation 5)
(def ^:const close-screen-with-slide-to-bottom-animation 6)
(def ^:const open-screen-with-slide-from-bottom-animation 7)

;; Floating Screen gesture
(def ^:const gesture-width 30)
Expand Down
86 changes: 46 additions & 40 deletions src/status_im2/contexts/shell/jump_to/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -125,25 +125,30 @@
(rf/defn navigate-to-jump-to
{:events [:shell/navigate-to-jump-to]}
[{:keys [db]}]
(let [chat-screen-open? (shell.utils/floating-screen-open? shell.constants/chat-screen)
community-screen-open? (shell.utils/floating-screen-open? shell.constants/community-screen)]
(let [open-floating-screens (shell.utils/open-floating-screens)]
(merge
(if config/shell-navigation-disabled?
{:pop-to-root-fx :shell-stack}
{:db
(cond-> db

chat-screen-open?
(get open-floating-screens shell.constants/chat-screen)
(assoc-in [:shell/floating-screens shell.constants/chat-screen :animation]
shell.constants/close-screen-with-shell-animation)

(and chat-screen-open? community-screen-open?)
(and (get open-floating-screens shell.constants/chat-screen)
(get open-floating-screens shell.constants/community-screen))
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-without-animation)

(and (not chat-screen-open?) community-screen-open?)
(and (not (get open-floating-screens shell.constants/chat-screen))
(get open-floating-screens shell.constants/community-screen))
(assoc-in [:shell/floating-screens shell.constants/community-screen :animation]
shell.constants/close-screen-with-shell-animation))
shell.constants/close-screen-with-shell-animation)

(get open-floating-screens shell.constants/discover-communities-screen)
(assoc-in [:shell/floating-screens shell.constants/discover-communities-screen :animation]
shell.constants/close-screen-without-animation))

:dispatch [:set-view-id :shell]})
{:shell/navigate-to-jump-to-fx nil})))
Expand Down Expand Up @@ -171,11 +176,17 @@
:community-id community-id
:hidden-screen? hidden-screen?
:clock now
:animation (or animation
(case current-view-id
:shell shell.constants/open-screen-with-shell-animation
:chat shell.constants/open-screen-without-animation
shell.constants/open-screen-with-slide-animation))})
:animation (or
animation
(cond
(= current-view-id :shell)
shell.constants/open-screen-with-shell-animation
(= current-view-id :chat)
shell.constants/open-screen-without-animation
(= go-to-view-id shell.constants/discover-communities-screen)
shell.constants/open-screen-with-slide-from-bottom-animation
:else
shell.constants/open-screen-with-slide-from-right-animation))})
:dispatch-n (cond-> []
(not hidden-screen?)
(conj [:set-view-id go-to-view-id])
Expand All @@ -196,31 +207,25 @@
(rf/defn shell-navigate-back
{:events [:shell/navigate-back]}
[{:keys [db]} animation]
(let [chat-screen-open? (shell.utils/floating-screen-open? shell.constants/chat-screen)
community-screen-open? (shell.utils/floating-screen-open? shell.constants/community-screen)
current-chat-id (:current-chat-id db)
current-view-id (:view-id db)
community-id (when current-chat-id
(get-in db [:chats current-chat-id :community-id]))]
(let [current-chat-id (:current-chat-id db)
current-view-id (:view-id db)
community-id (when current-chat-id
(get-in db [:chats current-chat-id :community-id]))]
(if (and (not @navigation.state/curr-modal)
(shell.utils/shell-navigation? current-view-id)
(or chat-screen-open? community-screen-open?))
{:db (assoc-in
db
[:shell/floating-screens
(if chat-screen-open? shell.constants/chat-screen shell.constants/community-screen)
:animation]
(or animation shell.constants/close-screen-with-slide-animation))
:dispatch-n (cond-> [[:set-view-id
(cond
(and chat-screen-open? community-screen-open?)
shell.constants/community-screen
community-screen-open?
:communities-stack
:else :chats-stack)]]
;; When navigating back from community chat to community, update switcher card
(and chat-screen-open? community-screen-open? community-id)
(conj [:shell/add-switcher-card shell.constants/community-screen community-id]))}
(seq (shell.utils/open-floating-screens)))
(merge
{:db (assoc-in
db
[:shell/floating-screens current-view-id :animation]
(cond
animation animation
(= current-view-id shell.constants/discover-communities-screen)
shell.constants/close-screen-with-slide-to-bottom-animation
:else
shell.constants/close-screen-with-slide-to-right-animation))}
(when (and current-chat-id community-id)
{:dispatch [:shell/add-switcher-card shell.constants/community-screen community-id]}))
{:navigate-back nil})))

(rf/defn floating-screen-opened
Expand All @@ -236,10 +241,10 @@
:dispatch [:shell/navigate-to shell.constants/community-screen
community-id shell.constants/open-screen-without-animation true]})
;; Only update switcher cards for top screen
(not hidden-screen?)
(and id (not hidden-screen?))
(conj {:ms (* 2 shell.constants/shell-animation-time)
:dispatch [:shell/add-switcher-card screen-id id]}))}
(when-not hidden-screen?
(when (and id (not hidden-screen?))
{:shell/change-tab-fx (if (or (= screen-id shell.constants/community-screen)
community-id)
:communities-stack
Expand All @@ -249,7 +254,8 @@
{:events [:shell/floating-screen-closed]}
[{:keys [db]} screen-id]
(merge
{:db (-> (update db :shell/floating-screens dissoc screen-id)
(update :shell/loaded-screens dissoc screen-id))}
(when (= screen-id shell.constants/chat-screen)
{:dispatch [:chat/close]})))
{:db (-> (update db :shell/floating-screens dissoc screen-id)
(update :shell/loaded-screens dissoc screen-id))
:dispatch-n (cond-> [[:set-view-id :shell-stack]]
(= screen-id shell.constants/chat-screen)
(conj [:chat/close]))}))
Loading

0 comments on commit 0f8bf3c

Please sign in to comment.