-
Notifications
You must be signed in to change notification settings - Fork 991
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
[#21658] - Avatars blinking #21782
[#21658] - Avatars blinking #21782
Changes from all commits
cfd688d
9716ad8
71434e8
a3c80a8
f7f708f
6f1758d
4cb1514
53c63a1
6c6a6e0
51ce6ee
94f352d
3a60c68
5d9bca4
be72c11
54a12ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,79 @@ | ||
(ns react-native.fast-image | ||
(:require | ||
["react-native-fast-image" :as FastImage] | ||
[clojure.string :as string] | ||
[react-native.core :as rn] | ||
[reagent.core :as reagent])) | ||
[reagent.core :as reagent] | ||
[utils.transforms :as transforms])) | ||
|
||
(def fast-image-class (reagent/adapt-react-class ^js FastImage)) | ||
(defn- build-source | ||
[source] | ||
(if (string? source) | ||
{:uri source | ||
:priority :high} | ||
source)) | ||
|
||
(defn placeholder | ||
[style child] | ||
[rn/view {:style (merge style {:flex 1 :justify-content :center :align-items :center})} | ||
child]) | ||
(defn- remove-port | ||
[source] | ||
(cond | ||
(string? source) (string/replace-first source #":\d+" "") | ||
(:uri source) (some-> source | ||
:uri | ||
(string/replace-first #":\d+" "")) | ||
:else source)) | ||
|
||
(defn fast-image | ||
(defn- placeholder | ||
[{:keys [style fallback-content error? loaded?]}] | ||
[rn/view | ||
{:style (assoc style | ||
:flex 1 | ||
:justify-content :center | ||
:align-items :center)} | ||
(cond | ||
(and error? fallback-content) fallback-content | ||
error? [rn/text "X"] | ||
(not loaded?) [rn/activity-indicator {:animating true}])]) | ||
|
||
;; We cannot use hooks since `reactify-component` seems to ignore the functional compiler | ||
(defn- internal-fast-image | ||
[_] | ||
(let [loaded? (reagent/atom false) | ||
error? (reagent/atom false)] | ||
(fn [{:keys [source fallback-content] :as props}] | ||
[fast-image-class | ||
(merge | ||
props | ||
{:source (if (string? source) | ||
{:uri source | ||
:priority :high} | ||
source) | ||
:on-error (fn [e] | ||
(when-let [on-error (:on-error props)] | ||
(on-error e)) | ||
(reset! error? true)) | ||
:on-load (fn [e] | ||
(when-let [on-load (:on-load props)] | ||
(on-load e)) | ||
(reset! loaded? true) | ||
(reset! error? false))}) | ||
(let [loaded? (reagent/atom false) | ||
error? (reagent/atom false) | ||
on-image-error (fn [event on-error] | ||
(when (fn? on-error) (on-error event)) | ||
(reset! error? true)) | ||
on-image-loaded (fn [event on-load] | ||
(when (fn? on-load) (on-load event)) | ||
(reset! loaded? true) | ||
(reset! error? false))] | ||
(fn [{:keys [source fallback-content on-error on-load] :as props}] | ||
[:> FastImage | ||
(assoc props | ||
:source (build-source source) | ||
:on-error #(on-image-error % on-error) | ||
:on-load #(on-image-loaded % on-load)) | ||
(when (or @error? (not @loaded?)) | ||
[placeholder (:style props) | ||
(if @error? | ||
(or fallback-content [rn/text "X"]) | ||
(when-not @loaded? | ||
[rn/activity-indicator {:animating true}]))])]))) | ||
[placeholder | ||
{:style (js->clj (:style props)) | ||
:fallback-content fallback-content | ||
:error? @error? | ||
:loaded? @loaded?}])]))) | ||
|
||
(defn- compare-props | ||
[old-props new-props] | ||
(let [old-props-clj (transforms/js->clj old-props) | ||
new-props-clj (transforms/js->clj new-props) | ||
old-source (some-> old-props-clj | ||
:source | ||
remove-port) | ||
new-source (some-> new-props-clj | ||
:source | ||
remove-port)] | ||
(and (= old-source new-source) | ||
(= (dissoc old-props-clj :source) (dissoc new-props-clj :source))))) | ||
|
||
(def fast-image | ||
(-> internal-fast-image | ||
(reagent/reactify-component) | ||
(rn/memo compare-props) | ||
(reagent/adapt-react-class))) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
(ns status-im.common.scalable-avatar.style) | ||
|
||
(defn wrapper | ||
[{:keys [scale margin-top margin border-color]}] | ||
[{:transform [{:scale scale}] | ||
:margin-top margin-top | ||
:margin-left margin | ||
:margin-bottom margin} | ||
{:border-width 4 | ||
:border-color border-color | ||
:border-radius 100}]) | ||
[border-color scale] | ||
[{:transform-origin "bottom left" | ||
:border-width 4 | ||
:border-color border-color | ||
:border-radius 100 | ||
:transform [{:scale 1} {:translate-y 4}]} | ||
{:transform [{:scale scale} {:translate-y 4}]}]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,30 +2,14 @@ | |
(:require [quo.core :as quo] | ||
[react-native.reanimated :as reanimated] | ||
[status-im.common.scalable-avatar.style :as style])) | ||
(def scroll-animation-input-range [0 50]) | ||
(def header-extrapolation-option | ||
{:extrapolateLeft "clamp" | ||
:extrapolateRight "clamp"}) | ||
|
||
(defn f-avatar | ||
(def scroll-range #js [0 48]) | ||
(def scale-range #js [1 0.4]) | ||
|
||
(defn view | ||
[{:keys [scroll-y full-name online? profile-picture customization-color border-color]}] | ||
(let [image-scale-animation (reanimated/interpolate scroll-y | ||
scroll-animation-input-range | ||
[1 0.4] | ||
header-extrapolation-option) | ||
image-top-margin-animation (reanimated/interpolate scroll-y | ||
scroll-animation-input-range | ||
[0 20] | ||
header-extrapolation-option) | ||
image-side-margin-animation (reanimated/interpolate scroll-y | ||
scroll-animation-input-range | ||
[-4 -20] | ||
header-extrapolation-option)] | ||
[reanimated/view | ||
{:style (style/wrapper {:scale image-scale-animation | ||
:margin-top image-top-margin-animation | ||
:margin image-side-margin-animation | ||
:border-color border-color})} | ||
(let [image-scale (reanimated/interpolate scroll-y scroll-range scale-range :clamp)] | ||
[reanimated/view {:style (style/wrapper border-color image-scale)} | ||
Comment on lines
-10
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avatar animation fix |
||
[quo/user-avatar | ||
{:full-name full-name | ||
:online? online? | ||
|
@@ -34,7 +18,3 @@ | |
:ring? true | ||
:customization-color customization-color | ||
:size :big}]])) | ||
|
||
(defn view | ||
[props] | ||
[:f> f-avatar props]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,8 +62,8 @@ | |
:on-end-reached #(re-frame/dispatch [:chat/show-more-chats]) | ||
:keyboard-should-persist-taps :always | ||
:data items | ||
:render-fn (fn [item] | ||
(chat-list-item/chat-list-item item theme)) | ||
:render-data {:theme theme} | ||
:render-fn chat-list-item/chat-list-item | ||
Comment on lines
-65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix rerenders on items for this flat-list |
||
:scroll-event-throttle 8 | ||
:content-container-style {:padding-bottom | ||
shell.constants/floating-shell-button-height | ||
|
@@ -94,8 +94,7 @@ | |
{:selected-tab :tab/contacts | ||
:tab->content (empty-state-content theme)}] | ||
[rn/section-list | ||
{:ref (when (not-empty items) | ||
set-scroll-ref) | ||
{:ref (when (seq items) set-scroll-ref) | ||
:key-fn :public-key | ||
:get-item-layout get-item-layout | ||
:content-inset-adjustment-behavior :never | ||
|
@@ -108,8 +107,8 @@ | |
:sticky-section-headers-enabled false | ||
:render-section-header-fn contact-list/contacts-section-header | ||
:render-section-footer-fn contact-list/contacts-section-footer | ||
:render-fn (fn [data] | ||
(contact-item-render data theme)) | ||
:render-data {:theme theme} | ||
:render-fn contact-item-render | ||
:scroll-event-throttle 8 | ||
:on-scroll #(common.banner/set-scroll-shared-value | ||
{:scroll-input (oops/oget % "nativeEvent.contentOffset.y") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
(ns status-im.contexts.profile.settings.header.style) | ||
(ns status-im.contexts.profile.settings.header.style | ||
(:require [quo.foundations.colors :as colors] | ||
[react-native.platform :as platform])) | ||
|
||
(def avatar-row-wrapper | ||
{:display :flex | ||
:padding-left 20 | ||
{:padding-left 20 | ||
:padding-right 12 | ||
:margin-top -60 | ||
:margin-bottom -4 | ||
:margin-top -65 | ||
:align-items :flex-end | ||
:justify-content :space-between | ||
:flex-direction :row}) | ||
|
@@ -21,3 +21,9 @@ | |
{:opacity opacity-animation | ||
:flex-direction :row | ||
:justify-content :space-between}) | ||
|
||
(defn avatar-border-color | ||
[theme] | ||
(if platform/android? | ||
colors/neutral-80-opa-80 ;; Fix is not needed because Android doesn't use blur | ||
(colors/theme-colors colors/border-avatar-light colors/neutral-80-opa-80 theme))) | ||
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avatar's ring fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Worth noting that we have an issue that we can play in 2.33 to remove identity rings #21743 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ring I'm referring to is the one showed in PR's video: avatar-circle-not-matching.mp4different to the identity ring |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multiple
merge
-> multipleassoc