Skip to content

Commit

Permalink
Improve JS code
Browse files Browse the repository at this point in the history
  • Loading branch information
ulisesmac committed May 14, 2024
1 parent d8822cb commit 4c2e9e4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 22 deletions.
45 changes: 27 additions & 18 deletions src/js/worklets/header_animations.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
import {
useDerivedValue,
interpolate,
interpolateColor,
Extrapolation,
useAnimatedStyle,
useDerivedValue,
interpolate,
interpolateColor,
Extrapolation,
useAnimatedStyle,
} from 'react-native-reanimated';

export function blurAmount(sharedValue) {
return useDerivedValue(() => {
return parseInt(interpolate(sharedValue.value, [0, 60], [1, 15], Extrapolation.CLAMP));
});
}
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 layerOpacity(sharedValue, from, to) {
return useAnimatedStyle(() => {
return {
flex: 1,
justifyContent: 'flex-end',
backgroundColor: interpolateColor(sharedValue.value, [0, 60], [from, to], 'RGB'),
};
});
export function useLayerOpacity(sharedValue, from, to) {
return useAnimatedStyle(() => ({
flex: 1,
justifyContent: 'flex-end',
backgroundColor: interpolateColor(sharedValue.value, [0, 60], [from, to], 'RGB')
}));
}
4 changes: 2 additions & 2 deletions src/status_im/contexts/wallet/collectible/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@

(defn animated-header
[{:keys [scroll-amount title-opacity page-nav-type picture title description theme]}]
(let [blur-amount (header-animations/blur-amount scroll-amount)
layer-opacity (header-animations/layer-opacity
(let [blur-amount (header-animations/use-blur-amount scroll-amount)
layer-opacity (header-animations/use-layer-opacity
scroll-amount
"transparent"
(colors/theme-colors colors/white-opa-50 colors/neutral-95-opa-70-blur theme))]
Expand Down
4 changes: 2 additions & 2 deletions src/utils/worklets/header_animations.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

(def worklets (js/require "../src/js/worklets/header_animations.js"))

(def blur-amount (.-blurAmount worklets))
(def use-blur-amount (.-useBlurAmount worklets))

(def layer-opacity (.-layerOpacity worklets))
(def use-layer-opacity (.-useLayerOpacity worklets))

0 comments on commit 4c2e9e4

Please sign in to comment.