Skip to content

Commit

Permalink
feat: add identifiers screen to onboarding-flow
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Son89 committed Apr 18, 2023
1 parent 05b8dd5 commit 8c6e994
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 62 deletions.
61 changes: 47 additions & 14 deletions src/status_im2/contexts/onboarding/common/background/view.cljs
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
(ns status-im2.contexts.onboarding.common.background.view
(:require [react-native.core :as rn]
[react-native.blur :as blur]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[status-im2.common.resources :as resources]
[reagent.core :as reagent]
[status-im2.contexts.onboarding.common.carousel.view :as carousel]
[status-im2.contexts.onboarding.common.background.style :as style]
[status-im2.contexts.onboarding.common.carousel.animation :as carousel.animation]))

(def header-text
[{:text (i18n/label :t/join-decentralised-communities)
:sub-text (i18n/label :t/participate-in-the-metaverse)}
{:text (i18n/label :t/chat-with-friends)
:sub-text (i18n/label :t/with-full-encryption)}
{:text (i18n/label :t/own-your-crypto)
:sub-text (i18n/label :t/use-the-multichain-wallet)}
{:text (i18n/label :t/discover-web3)
:sub-text (i18n/label :t/explore-the-decentralized-web)}])

(defn background-image
[content-width]
[rn/image
{:style {:resize-mode :stretch
:width content-width}
:source (resources/get-image :onboarding-illustration)}])

(defn view
[dark-overlay?]
[:f>
(fn []
(let [animate? (not dark-overlay?)]
(when animate? (carousel.animation/initialize-animation))
[rn/view
{:style style/background-container}
[carousel/view animate?]
(when dark-overlay?
[blur/view
{:style style/background-blur-overlay
:blur-amount 30
:blur-radius 25
:blur-type :transparent
:overlay-color :transparent}])]))])
(let [view-id (rf/sub [:view-id])
progress (reagent/atom nil)
paused (reagent/atom nil)]
[:f>
(fn []
(carousel.animation/initialize-animation progress paused)
(let [animate? (not dark-overlay?)]
(fn []
[rn/view
{:style style/background-container}
[carousel/view
{:animate? animate?
:progress progress
:paused paused
:header-text header-text
:header-background true
:content background-image
:paused? (not= view-id :intro)}]
(when dark-overlay?
[blur/view
{:style style/background-blur-overlay
:blur-amount 30
:blur-radius 25
:blur-type :transparent
:overlay-color :transparent}])])))]))

Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
[react-native.reanimated :as reanimated]
[utils.worklets.onboarding-carousel :as worklets.onboarding-carousel]))

(def progress (atom nil))
(def paused (atom nil))

(def ^:const progress-bar-animation-delay 300)
(def ^:const progress-bar-animation-duration 4000)

Expand Down Expand Up @@ -34,21 +31,21 @@
paused)))

(defn initialize-animation
[]
[progress paused]
(reset! progress (reanimated/use-shared-value 0))
(reset! paused (reanimated/use-shared-value false))
(animate-progress @progress @paused))

(defn carousel-left-position
[window-width animate?]
[window-width animate? progress]
(if animate?
(worklets.onboarding-carousel/carousel-left-position window-width @progress)
(-> (or (reanimated/get-shared-value @progress) 0)
(quot -25)
(* window-width))))

(defn dynamic-progress-bar-width
[progress-bar-width animate?]
[progress-bar-width animate? progress]
(if animate?
(worklets.onboarding-carousel/dynamic-progress-bar-width progress-bar-width @progress)
(-> (or (reanimated/get-shared-value @progress) 0)
Expand Down
9 changes: 2 additions & 7 deletions src/status_im2/contexts/onboarding/common/carousel/style.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
[react-native.reanimated :as reanimated]))

(defn header-container
[status-bar-height content-width index]
[status-bar-height content-width index header-background]
{:position :absolute
:top 0
:left (* content-width index)
:padding-top (+ 30 status-bar-height)
:width content-width
:height (+ 96 status-bar-height)
:flex-direction :row
:background-color colors/onboarding-header-black})
:background-color (when header-background colors/onboarding-header-black)})

(defn header-text-view
[window-width]
Expand All @@ -27,11 +27,6 @@
{:color colors/white
:margin-top 2})

(defn background-image
[content-width]
{:resize-mode :stretch
:width content-width})

(defn progress-bar-item
[static? end?]
{:height 2
Expand Down
49 changes: 19 additions & 30 deletions src/status_im2/contexts/onboarding/common/carousel/view.cljs
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
(ns status-im2.contexts.onboarding.common.carousel.view
(:require [quo2.core :as quo]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[react-native.core :as rn]
[react-native.navigation :as navigation]
[react-native.reanimated :as reanimated]
[status-im2.common.resources :as resources]
[status-im2.contexts.onboarding.common.carousel.style :as style]
[status-im2.contexts.onboarding.common.carousel.animation :as animation]))

(def header-text
[{:text (i18n/label :t/join-decentralised-communities)
:sub-text (i18n/label :t/participate-in-the-metaverse)}
{:text (i18n/label :t/chat-with-friends)
:sub-text (i18n/label :t/with-full-encryption)}
{:text (i18n/label :t/own-your-crypto)
:sub-text (i18n/label :t/use-the-multichain-wallet)}
{:text (i18n/label :t/discover-web3)
:sub-text (i18n/label :t/explore-the-decentralized-web)}])

(defn header-text-view
[index window-width]
[index window-width header-text]
[rn/view {:style (style/header-text-view window-width)}
[quo/text
{:style style/carousel-text
Expand All @@ -33,16 +21,14 @@
(get-in header-text [index :sub-text])]])

(defn content-view
[{:keys [window-width status-bar-height index]}]
[{:keys [window-width status-bar-height index header-text header-background]} content]
(let [content-width (* 4 window-width)]
[:<>
[rn/image
{:style (style/background-image content-width)
:source (resources/get-image :onboarding-illustration)}]
[rn/view {:style (style/header-container status-bar-height content-width index)}
(when content content)
[rn/view {:style (style/header-container status-bar-height content-width index header-background)}
(for [index (range 4)]
^{:key index}
[header-text-view index window-width])]]))
[header-text-view index window-width header-text])]]))

(defn progress-bar
[{:keys [static? progress-bar-width]}]
Expand All @@ -54,45 +40,48 @@
[rn/view {:style (style/progress-bar-item static? true)}]])

(defn dynamic-progress-bar
[progress-bar-width animate?]
[progress-bar-width animate? progress]
[:f>
(fn []
(let [width (animation/dynamic-progress-bar-width progress-bar-width animate?)
(let [width (animation/dynamic-progress-bar-width progress-bar-width animate? progress)
container-view (if animate? reanimated/view rn/view)]
[container-view {:style (style/dynamic-progress-bar width animate?)}
[progress-bar
{:static? false
:progress-bar-width progress-bar-width}]]))])

(defn view
[animate?]
[{:keys [animate? progress paused header-text content paused? header-background]}]
[:f>
(fn []
(let [window-width (rf/sub [:dimensions/window-width])
view-id (rf/sub [:view-id])
status-bar-height (:status-bar-height @navigation/constants)
progress-bar-width (- window-width 40)
carousel-left (animation/carousel-left-position window-width animate?)
carousel-left (animation/carousel-left-position window-width animate? progress)
container-view (if animate? reanimated/view rn/view)]
(when animate?
(rn/use-effect
(fn []
(reanimated/set-shared-value @animation/paused (not= view-id :intro)))
[view-id]))
(rn/use-effect
(fn []
(when animate?
(reanimated/set-shared-value paused paused?)))
[view-id])
[:<>
[container-view {:style (style/carousel-container carousel-left animate?)}
(for [index (range 2)]
^{:key index}
[content-view
{:window-width window-width
:status-bar-height status-bar-height
:index index}])]
:index index
:header-text header-text
:header-background header-background
} (when content [content (* 4 window-width)])])]
[rn/view
{:style (style/progress-bar-container
progress-bar-width
status-bar-height)}
[progress-bar
{:static? true
:progress-bar-width progress-bar-width}]
[dynamic-progress-bar progress-bar-width animate?]]]))])
[dynamic-progress-bar progress-bar-width animate? progress]]]))])

2 changes: 1 addition & 1 deletion src/status_im2/contexts/onboarding/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
constants/auth-method-biometric
(get-in db [:onboarding-2/profile :auth-method]))]

(cond-> {:dispatch [:navigate-to :enable-notifications]}
(cond-> {:dispatch [:navigate-to :identifiers]}
biometric-enabled?
(assoc :biometric/enable-and-save-password
{:key-uid key-uid
Expand Down
15 changes: 15 additions & 0 deletions src/status_im2/contexts/onboarding/identifiers/style.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(ns status-im2.contexts.onboarding.identifiers.style)

(def page-container
{:flex 1})

(def content-container
{:position :absolute
:width "100%"
:top 160
:bottom 0
:left 0})

(def card-style
{:margin-horizontal 20
:margin-bottom :auto})
62 changes: 62 additions & 0 deletions src/status_im2/contexts/onboarding/identifiers/view.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
(ns status-im2.contexts.onboarding.identifiers.view
(:require [react-native.core :as rn]
[clojure.string :as string]
[utils.i18n :as i18n]
[utils.re-frame :as rf]
[quo2.core :as quo]
[quo2.foundations.colors :as colors]
[reagent.core :as reagent]

[status-im2.contexts.onboarding.identifiers.style :as style]
[status-im2.contexts.onboarding.common.background.view :as background]
[status-im2.contexts.onboarding.common.carousel.view :as carousel]
[status-im2.contexts.onboarding.common.carousel.animation :as carousel.animation]))

(def header-text
[{:text (i18n/label :t/unique-identifiers)
:sub-text (i18n/label :t/your-identifiers)}
{:text (i18n/label :t/identicon-ring)
:sub-text (i18n/label :t/identicon-ring-explanation)}
{:text (i18n/label :t/chat-key-title)
:sub-text (i18n/label :t/chat-key-description)}
{:text (i18n/label :t/emojihash)
:sub-text (i18n/label :t/emojihash-description)}])

(defn view
[]
(let [progress (reagent/atom nil)
paused (reagent/atom nil)
{:keys [emoji-hash display-name profile-picture compressed-key]} (rf/sub [:multiaccount])
{:keys [color]} (rf/sub [:onboarding-2/profile])
emoji-string (string/join emoji-hash)]
[:f>
(fn []
(carousel.animation/initialize-animation progress paused)
(fn []
[:<>
[background/view true]
[rn/view {:style style/page-container}
[carousel/view
{:animate? true
:progress progress
:paused paused
:header-text header-text

:paused? false}]
[rn/view {:style style/content-container}
[quo/profile-card
{:profile-picture profile-picture
:name display-name
:hash compressed-key
:customization-color color
:emoji-hash emoji-string
:show-emoji-hash? true
:show-user-hash? true
:card-style style/card-style}]
[quo/button
{:accessibility-label :skip-identifiers
:on-press #(rf/dispatch [:navigate-to :enable-notifications])
:override-background-color colors/white-opa-5
:style {:justify-self :flex-end
:margin-bottom 46
:margin-horizontal 20}} (i18n/label :t/skip)]]]]))]))
5 changes: 4 additions & 1 deletion src/status_im2/navigation/screens.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
[status-im2.contexts.onboarding.create-profile.view :as create-profile]
[status-im2.contexts.onboarding.enable-biometrics.view :as enable-biometrics]
[status-im2.contexts.onboarding.enable-notifications.view :as enable-notifications]
[status-im2.contexts.onboarding.identifiers.view :as identifiers]
[status-im2.contexts.onboarding.welcome.view :as welcome]
[status-im2.contexts.onboarding.new-to-status.view :as new-to-status]
[status-im2.contexts.onboarding.sign-in.view :as sign-in]
Expand All @@ -27,7 +28,6 @@
[status-im2.contexts.syncing.view :as settings-syncing]
[status-im2.navigation.options :as options]
[status-im2.contexts.chat.group-details.view :as group-details]

[status-im.ui.screens.screens :as old-screens]
[status-im2.contexts.communities.menus.request-to-join.view :as join-menu]))

Expand Down Expand Up @@ -116,6 +116,9 @@
:popStackOnPress false}}
:component enable-notifications/enable-notifications}

{:name :identifiers
:component identifiers/view}

{:name :sign-in
:component sign-in/view}

Expand Down
Loading

0 comments on commit 8c6e994

Please sign in to comment.