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

Pare back the parallax animation on empty chats #35232

Merged
merged 9 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const CONST = {
IN: 'in',
OUT: 'out',
},
// Multiplier for gyroscope animation in order to make it a bit more subtle
ANIMATION_GYROSCOPE_VALUE: 0.4,
ARROW_HIDE_DELAY: 3000,

API_ATTACHMENT_VALIDATIONS: {
Expand Down Expand Up @@ -145,7 +147,7 @@ const CONST = {
CONTAINER_MINHEIGHT: 500,
VIEW_HEIGHT: 275,
},
MONEY_REPORT: {
MONEY_OR_TASK_REPORT: {
SMALL_SCREEN: {
IMAGE_HEIGHT: 300,
CONTAINER_MINHEIGHT: 280,
Expand Down
14 changes: 1 addition & 13 deletions src/libs/NumberUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,6 @@ function generateHexadecimalValue(num: number): string {
return result.join('').toUpperCase();
}

/**
* Clamp a number in a range.
* This is a worklet so it should be used only from UI thread.

* @returns clamped value between min and max
*/
function clampWorklet(num: number, min: number, max: number): number {
'worklet';

return Math.min(Math.max(num, min), max);
}

/**
* Generates a random integer between a and b
* It's and equivalent of _.random(a, b)
Expand All @@ -81,4 +69,4 @@ function parseFloatAnyLocale(value: string): number {
return parseFloat(value ? value.replace(',', '.') : value);
}

export {rand64, generateHexadecimalValue, generateRandomInt, clampWorklet, parseFloatAnyLocale};
export {rand64, generateHexadecimalValue, generateRandomInt, parseFloatAnyLocale};
12 changes: 6 additions & 6 deletions src/pages/home/report/AnimatedEmptyStateBackground.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
import Animated, {SensorType, useAnimatedSensor, useAnimatedStyle, useSharedValue, withSpring} from 'react-native-reanimated';
import Animated, {clamp, SensorType, useAnimatedSensor, useAnimatedStyle, useReducedMotion, useSharedValue, withSpring} from 'react-native-reanimated';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeIllustrations from '@hooks/useThemeIllustrations';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as NumberUtils from '@libs/NumberUtils';
import variables from '@styles/variables';
import CONST from '@src/CONST';

Expand All @@ -22,10 +21,11 @@ function AnimatedEmptyStateBackground() {
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) {
if (!isSmallScreenWidth || isReducedMotionEnabled) {
return {};
}
/*
Expand All @@ -34,12 +34,12 @@ function AnimatedEmptyStateBackground() {
*/
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 = NumberUtils.clampWorklet(xOffset.value + y, -IMAGE_OFFSET_X, IMAGE_OFFSET_X);
yOffset.value = NumberUtils.clampWorklet(yOffset.value - x, -IMAGE_OFFSET_Y, IMAGE_OFFSET_Y);
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 {
transform: [{translateX: withSpring(-IMAGE_OFFSET_X - xOffset.value)}, {translateY: withSpring(yOffset.value)}],
};
}, []);
}, [isReducedMotionEnabled]);

return (
<Animated.Image
Expand Down
8 changes: 4 additions & 4 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ function ReportActionItem(props) {
if (ReportUtils.isTaskReport(props.report)) {
if (ReportUtils.isCanceledTaskReport(props.report, parentReportAction)) {
return (
<>
<View style={[StyleUtils.getReportWelcomeContainerStyle(props.isSmallScreenWidth, true)]}>
Copy link
Contributor

Choose a reason for hiding this comment

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

There's regression:

Screenshot 2024-02-06 at 10 35 28 AM

<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]}>
<ReportActionItemSingle
Expand All @@ -631,19 +631,19 @@ function ReportActionItem(props) {
</ReportActionItemSingle>
<View style={styles.reportHorizontalRule} />
</View>
</>
</View>
);
}
return (
<>
<View style={[StyleUtils.getReportWelcomeContainerStyle(props.isSmallScreenWidth, true)]}>
Copy link
Contributor

Choose a reason for hiding this comment

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

The meaning of 2nd param is isMoneyReport. Why is set to true here? (this is task report)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to reuse the function in order to increase the topMargin. The task report requires it in order to move the background screen a bit higher. I can rename it to be eg. MONEY_OR_TASK_REPORT, if you wish

Copy link
Contributor

Choose a reason for hiding this comment

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

ok let's rename then

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(props.isSmallScreenWidth)]}>
<TaskView
report={props.report}
shouldShowHorizontalRule={!props.shouldHideThreadDividerLine}
/>
</View>
</>
</View>
);
}
if (ReportUtils.isExpenseReport(props.report) || ReportUtils.isIOUReport(props.report)) {
Expand Down
12 changes: 6 additions & 6 deletions src/styles/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,8 @@ function getHorizontalStackedOverlayAvatarStyle(oneAvatarSize: AvatarSize, oneAv
/**
* Gets the correct size for the empty state background image based on screen dimensions
*/
function getReportWelcomeBackgroundImageStyle(isSmallScreenWidth: boolean, isMoneyReport = false): ImageStyle {
const emptyStateBackground = isMoneyReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_REPORT : CONST.EMPTY_STATE_BACKGROUND;
function getReportWelcomeBackgroundImageStyle(isSmallScreenWidth: boolean, isMoneyOrTaskReport = false): ImageStyle {
const emptyStateBackground = isMoneyOrTaskReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_OR_TASK_REPORT : CONST.EMPTY_STATE_BACKGROUND;

if (isSmallScreenWidth) {
return {
Expand All @@ -720,8 +720,8 @@ function getReportWelcomeBackgroundImageStyle(isSmallScreenWidth: boolean, isMon
/**
* Gets the correct top margin size for the chat welcome message based on screen dimensions
*/
function getReportWelcomeTopMarginStyle(isSmallScreenWidth: boolean, isMoneyReport = false): ViewStyle {
const emptyStateBackground = isMoneyReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_REPORT : CONST.EMPTY_STATE_BACKGROUND;
function getReportWelcomeTopMarginStyle(isSmallScreenWidth: boolean, isMoneyOrTaskReport = false): ViewStyle {
const emptyStateBackground = isMoneyOrTaskReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_OR_TASK_REPORT : CONST.EMPTY_STATE_BACKGROUND;
if (isSmallScreenWidth) {
return {
marginTop: emptyStateBackground.SMALL_SCREEN.VIEW_HEIGHT,
Expand Down Expand Up @@ -754,8 +754,8 @@ function getLineHeightStyle(lineHeight: number): TextStyle {
/**
* Gets the correct size for the empty state container based on screen dimensions
*/
function getReportWelcomeContainerStyle(isSmallScreenWidth: boolean, isMoneyReport = false): ViewStyle {
const emptyStateBackground = isMoneyReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_REPORT : CONST.EMPTY_STATE_BACKGROUND;
function getReportWelcomeContainerStyle(isSmallScreenWidth: boolean, isMoneyOrTaskReport = false): ViewStyle {
const emptyStateBackground = isMoneyOrTaskReport ? CONST.EMPTY_STATE_BACKGROUND.MONEY_OR_TASK_REPORT : CONST.EMPTY_STATE_BACKGROUND;
if (isSmallScreenWidth) {
return {
minHeight: emptyStateBackground.SMALL_SCREEN.CONTAINER_MINHEIGHT,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/UnreadIndicatorsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jest.mock('react-native/Libraries/LogBox/LogBox', () => ({
jest.mock('react-native-reanimated', () => ({
...jest.requireActual('react-native-reanimated/mock'),
createAnimatedPropAdapter: jest.fn,
useReducedMotion: jest.fn,
Comment on lines 45 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI these missing mocks will be added to Reanimated in software-mansion/react-native-reanimated#5372

}));

/**
Expand Down
Loading