Skip to content

Commit

Permalink
fix: remove sensor animation for now
Browse files Browse the repository at this point in the history
  • Loading branch information
WoLewicki committed Apr 16, 2024
1 parent ed7029b commit d15aabc
Showing 1 changed file with 3 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/pages/home/report/AnimatedEmptyStateBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import React from 'react';
import Animated, {clamp, SensorType, useAnimatedSensor, useAnimatedStyle, useReducedMotion, useSharedValue, withSpring} from 'react-native-reanimated';
import {Image} from 'react-native';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeIllustrations from '@hooks/useThemeIllustrations';
import useWindowDimensions from '@hooks/useWindowDimensions';
import variables from '@styles/variables';
import CONST from '@src/CONST';

// Maximum horizontal and vertical shift in pixels on sensor value change
const IMAGE_OFFSET_X = 30;
const IMAGE_OFFSET_Y = 20;

function AnimatedEmptyStateBackground() {
const StyleUtils = useStyleUtils();
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -18,36 +14,10 @@ function AnimatedEmptyStateBackground() {
// If window width is greater than the max background width, repeat the background image
const maxBackgroundWidth = variables.sideBarWidth + CONST.EMPTY_STATE_BACKGROUND.ASPECT_RATIO * CONST.EMPTY_STATE_BACKGROUND.WIDE_SCREEN.IMAGE_HEIGHT;

// Get data from phone rotation sensor and prep other variables for animation
const animatedSensor = useAnimatedSensor(SensorType.GYROSCOPE);
const xOffset = useSharedValue(0);
const yOffset = useSharedValue(0);
const isReducedMotionEnabled = useReducedMotion();

// Apply data to create style object
const animatedStyles = useAnimatedStyle(() => {
if (!isSmallScreenWidth || isReducedMotionEnabled) {
return {};
}
/*
* We use x and y gyroscope velocity and add it to position offset to move background based on device movements.
* Position the phone was in while entering the screen is the initial position for background image.
*/
const {x, y} = animatedSensor.sensor.value;
// The x vs y here seems wrong but is the way to make it feel right to the user
xOffset.value = clamp(xOffset.value + y * CONST.ANIMATION_GYROSCOPE_VALUE, -IMAGE_OFFSET_X, IMAGE_OFFSET_X);
yOffset.value = clamp(yOffset.value - x * CONST.ANIMATION_GYROSCOPE_VALUE, -IMAGE_OFFSET_Y, IMAGE_OFFSET_Y);
return {
// On Android, scroll view sub views gets clipped beyond container bounds. Set the top position so that image wouldn't get clipped
top: IMAGE_OFFSET_Y,
transform: [{translateX: withSpring(xOffset.value)}, {translateY: withSpring(yOffset.value, {overshootClamping: true})}, {scale: 1.15}],
};
}, [isReducedMotionEnabled]);

return (
<Animated.Image
<Image
source={illustrations.EmptyStateBackgroundImage}
style={[StyleUtils.getReportWelcomeBackgroundImageStyle(isSmallScreenWidth), animatedStyles]}
style={StyleUtils.getReportWelcomeBackgroundImageStyle(isSmallScreenWidth)}
resizeMode={windowWidth > maxBackgroundWidth ? 'repeat' : 'cover'}
/>
);
Expand Down

0 comments on commit d15aabc

Please sign in to comment.