Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collectible header #19783

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/js/worklets/header_animations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {
useDerivedValue,
interpolate,
interpolateColor,
Extrapolation,
useAnimatedStyle,
} from 'react-native-reanimated';

const CLAMP_MIN = 0;
const CLAMP_MAX = 60;
const BLUR_MIN = 1;
const BLUR_MAX = 15;

export const useBlurAmount = (sharedValue) =>
useDerivedValue(() =>
parseInt(interpolate(sharedValue.value, [CLAMP_MIN, CLAMP_MAX], [BLUR_MIN, BLUR_MAX], Extrapolation.CLAMP)),
);

export function useLayerOpacity(sharedValue, from, to) {
return useAnimatedStyle(() => ({
flex: 1,
justifyContent: 'flex-end',
backgroundColor: interpolateColor(sharedValue.value, [0, 60], [from, to], 'RGB'),
Comment on lines +20 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach has few drawbacks.

  1. I am not sure if situation is changed, but changes in js code were not visible until app restarted
  2. Also for consistency we should stick to a single approach. If we use this approach everywhere we will have three files, view, simple style, and animated style, for all animations and we have several animations.

}));
}
1 change: 1 addition & 0 deletions src/mocks/js_dependencies.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@
"../src/js/worklets/parallax.js" #js {}
"../src/js/worklets/profile_header.js" #js {}
"../src/js/worklets/identifiers_highlighting.js" #js {}
"../src/js/worklets/header_animations.js" #js {}
"./fleets.js" default-fleets
"../translations/ar.json" (js/JSON.parse (slurp "./translations/ar.json"))
"../translations/de.json" (js/JSON.parse (slurp "./translations/de.json"))
Expand Down
13 changes: 5 additions & 8 deletions src/quo/components/profile/expanded_collectible/style.cljs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
(ns quo.components.profile.expanded-collectible.style
(:require [quo.foundations.colors :as colors]
[quo.foundations.shadows :as shadows]))
(:require [quo.foundations.colors :as colors]))

(defn container
[theme]
(merge (shadows/get 2 theme)
{:align-items :center
:justify-content :center
:border-radius 16}))
(def container
{:align-items :center
:justify-content :center
:border-radius 16})

(defn image
[square? aspect-ratio]
Expand Down
11 changes: 7 additions & 4 deletions src/quo/components/profile/expanded_collectible/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
label]])

(defn view-internal
[{:keys [container-style square? on-press counter image-src native-ID supported-file?]}]
[{:keys [container-style square? on-press counter image-src native-ID supported-file?
on-collectible-load]}]
(let [theme (quo.theme/use-theme)
[image-size set-image-size] (rn/use-state {})
[image-error? set-image-error] (rn/use-state false)]
Expand All @@ -48,7 +49,7 @@
[rn/pressable
{:on-press (when (and (not image-error?) supported-file?) on-press)
:accessibility-label :expanded-collectible
:style (merge container-style (style/container theme))}
:style (merge container-style style/container)}
(cond
(not supported-file?)
[fallback-view
Expand All @@ -68,7 +69,8 @@
{:style (style/image square? (:aspect-ratio image-size))
:source image-src
:native-ID native-ID
:on-error #(set-image-error true)}]
:on-error #(set-image-error true)
:on-load on-collectible-load}]
[counter-view counter]])]))

(def ?schema
Expand All @@ -82,7 +84,8 @@
[:native-ID {:optional true} [:maybe [:or string? keyword?]]]
[:square? {:optional true} [:maybe boolean?]]
[:counter {:optional true} [:maybe string?]]
[:on-press {:optional true} [:maybe fn?]]]]]
[:on-press {:optional true} [:maybe fn?]]
[:on-collectible-load {:optional true} [:maybe fn?]]]]]
:any])

(def view (schema/instrument #'view-internal ?schema))
2 changes: 1 addition & 1 deletion src/status_im/common/scroll_page/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
children]
(let [theme (quo.theme/use-theme)]
[:<>
[:f> f-scroll-page-header
[f-scroll-page-header
{:scroll-height @scroll-height
:height height
:sticky-header sticky-header
Expand Down
56 changes: 47 additions & 9 deletions src/status_im/contexts/wallet/collectible/style.cljs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
(ns status-im.contexts.wallet.collectible.style)
(ns status-im.contexts.wallet.collectible.style
(:require [quo.foundations.colors :as colors]
[react-native.core :as rn]
[react-native.platform :as platform]))

(def container
{:margin-top 100
:margin-bottom 34})
{:margin-bottom 34})

(def preview-container
{:margin-horizontal 8
:margin-top 12})

(def preview
{:width "100%"
:aspect-ratio 1
:border-radius 16})
:margin-top 12
:padding-top 100})

(def header
{:margin-horizontal 20
Expand Down Expand Up @@ -43,3 +41,43 @@
(def opensea-button
{:flex 1
:margin-left 6})

(def animated-header
{:position :absolute
:top 0
:left 0
:right 0
:height 100
:z-index 1
:overflow :hidden})

(defn scroll-view
[safe-area-top]
{:flex 1
:margin-top (when platform/ios? (- safe-area-top))})

(def gradient-layer
{:position :absolute
:top 0
:left 0
:right 0
:bottom 0
:flex 1
:align-items :center
:overflow :hidden})

(def image-background
{:height (:height (rn/get-window))
:aspect-ratio 1})

(def gradient
{:position :absolute
:top 0
:left 0
:right 0
:bottom 0})

(defn background-color
[theme]
{:flex 1
:background-color (colors/theme-colors colors/white colors/neutral-95 theme)})