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

Gyroscope-driven animations of empty chats #23737

Merged
merged 31 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5677c9c
Gyroscope
wojtus7 Jul 11, 2023
a88ddb6
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Jul 26, 2023
ca0fb68
Make animations better (I think)
wojtus7 Jul 27, 2023
311ba60
Revert changes
wojtus7 Jul 27, 2023
95bc009
Add new line
wojtus7 Jul 27, 2023
b8dc279
Add permissions for android
wojtus7 Jul 27, 2023
fe804f9
Lint
wojtus7 Jul 27, 2023
4eb50dc
Prettier
wojtus7 Jul 27, 2023
fa2d7de
Return props
wojtus7 Jul 27, 2023
7520ffe
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Aug 2, 2023
06c0786
Add mocks in reanimated patch to fix tests
wojtus7 Aug 2, 2023
ae0469b
Test of reanimated 3.4.2 to see if CI works
wojtus7 Aug 3, 2023
712c340
Use reanimated 3.4.2
wojtus7 Aug 4, 2023
a84745d
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Aug 4, 2023
8d133f0
Improvements
wojtus7 Aug 8, 2023
5cf9633
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Aug 8, 2023
2952c0b
Revert change of cocoapods version
wojtus7 Aug 8, 2023
353ac37
Remove animation boost
wojtus7 Aug 10, 2023
bab35a7
Create AnimatedEmptyStateBackground
wojtus7 Aug 10, 2023
e086a59
Remove redundant isSmallScreenWidth prop
wojtus7 Aug 10, 2023
4da5ddd
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Aug 11, 2023
09480c1
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Aug 23, 2023
9d58b64
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 Sep 4, 2023
8051ce2
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 12, 2023
a750eec
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 15, 2023
5ecaef9
Fix types
wojtus7 Sep 15, 2023
1289ebd
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 20, 2023
ded2f0b
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 25, 2023
0f7a852
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 25, 2023
d9bd159
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Sep 27, 2023
bb74a0c
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 Oct 3, 2023
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
1 change: 1 addition & 0 deletions android/app/src/debug/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"/>
<application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning">
<meta-data
android:name="firebase_performance_logcat_enabled"
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS"/>

<!-- android:hardwareAccelerated is essential for Android performance: https://developer.android.com/topic/performance/hardware-accel -->
<application
Expand Down
8 changes: 4 additions & 4 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ PODS:
- React-Core
- RNReactNativeHapticFeedback (1.14.0):
- React-Core
- RNReanimated (3.4.0):
- RNReanimated (3.4.2):
- DoubleConversion
- FBLazyVector
- glog
Expand Down Expand Up @@ -1222,8 +1222,8 @@ SPEC CHECKSUMS:
RNLocalize: d4b8af4e442d4bcca54e68fc687a2129b4d71a81
RNPermissions: dcdb7b99796bbeda6975a6e79ad519c41b251b1c
RNReactNativeHapticFeedback: 1e3efeca9628ff9876ee7cdd9edec1b336913f8c
RNReanimated: 020859659f64be2d30849a1fe88c821a7c3e0cbf
RNScreens: d037903436160a4b039d32606668350d2a808806
RNReanimated: 49cdb63e767bb7e743ff4c12f7d85722c0d008f2
RNScreens: 0df01424e9e0ed7827200d6ed1087ddd06c493f9
RNSVG: 53c661b76829783cdaf9b7a57258f3d3b4c28315
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
Expand All @@ -1234,4 +1234,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: bc8161c6bfffeec6e6eaf84be18de5041ddcacf6

COCOAPODS: 1.12.1
COCOAPODS: 1.11.3
wojtus7 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"react-native-plaid-link-sdk": "^10.0.0",
"react-native-qrcode-svg": "^6.2.0",
"react-native-quick-sqlite": "^8.0.0-beta.2",
"react-native-reanimated": "3.4.0",
"react-native-reanimated": "3.4.2",
"react-native-render-html": "6.3.1",
"react-native-safe-area-context": "4.4.1",
"react-native-screens": "3.21.0",
Expand Down
17 changes: 16 additions & 1 deletion src/libs/NumberUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,19 @@ function generateHexadecimalValue(num) {
.toUpperCase();
}

export {rand64, generateHexadecimalValue};
/**
* Clamp a number in a range.
* This is a worklet so it should be used only from UI thread.
*
* @param {Number} num
* @param {Number} min
* @param {Number} max
* @returns {Number}
*/
function clampWorklet(num, min, max) {
'worklet';

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

export {rand64, generateHexadecimalValue, clampWorklet};
38 changes: 35 additions & 3 deletions src/pages/home/report/ReportActionItemCreated.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, {memo} from 'react';
import {View, Image} from 'react-native';
import {View} from 'react-native';
import lodashGet from 'lodash/get';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import Animated, {useSharedValue, useAnimatedStyle, useAnimatedSensor, SensorType, withSpring} from 'react-native-reanimated';
import ONYXKEYS from '../../../ONYXKEYS';
import ReportWelcomeText from '../../../components/ReportWelcomeText';
import participantPropTypes from '../../../components/participantPropTypes';
Expand All @@ -17,8 +18,10 @@ import withWindowDimensions, {windowDimensionsPropTypes} from '../../../componen
import compose from '../../../libs/compose';
import withLocalize from '../../../components/withLocalize';
import PressableWithoutFeedback from '../../../components/Pressable/PressableWithoutFeedback';
import useWindowDimensions from '../../../hooks/useWindowDimensions';
import MultipleAvatars from '../../../components/MultipleAvatars';
import CONST from '../../../CONST';
import * as NumberUtils from '../../../libs/NumberUtils';

const propTypes = {
/** The id of the report */
Expand Down Expand Up @@ -47,7 +50,36 @@ const defaultProps = {
policy: {},
};

const IMAGE_OFFSET_Y = 75;
const ANIMATION_BOOST = 1.3;
wojtus7 marked this conversation as resolved.
Show resolved Hide resolved

function ReportActionItemCreated(props) {
const {windowWidth, isSmallScreenWidth} = useWindowDimensions();
const IMAGE_OFFSET_X = windowWidth / 2;

// 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);

// Apply data to create style object
const animatedStyles = useAnimatedStyle(() => {
/*
* 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 = NumberUtils.clampWorklet(xOffset.value - y * ANIMATION_BOOST, -IMAGE_OFFSET_X, IMAGE_OFFSET_X);
wojtus7 marked this conversation as resolved.
Show resolved Hide resolved
yOffset.value = NumberUtils.clampWorklet(yOffset.value - x * ANIMATION_BOOST, -IMAGE_OFFSET_Y, IMAGE_OFFSET_Y);
if (!isSmallScreenWidth) {
return {};
}
return {
transform: [{translateX: withSpring(-IMAGE_OFFSET_X - xOffset.value)}, {translateY: withSpring(yOffset.value)}],
};
});

if (!ReportUtils.isChatReport(props.report)) {
return null;
}
Expand All @@ -64,10 +96,10 @@ function ReportActionItemCreated(props) {
needsOffscreenAlphaCompositing
>
<View style={StyleUtils.getReportWelcomeContainerStyle(props.isSmallScreenWidth)}>
<Image
<Animated.Image
pointerEvents="none"
source={EmptyStateBackgroundImage}
style={StyleUtils.getReportWelcomeBackgroundImageStyle(props.isSmallScreenWidth)}
style={[StyleUtils.getReportWelcomeBackgroundImageStyle(props.isSmallScreenWidth), animatedStyles]}
/>
<View
accessibilityLabel={props.translate('accessibilityHints.chatWelcomeMessage')}
Expand Down
2 changes: 1 addition & 1 deletion src/styles/StyleUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ function getReportWelcomeBackgroundImageStyle(isSmallScreenWidth) {
if (isSmallScreenWidth) {
return {
height: CONST.EMPTY_STATE_BACKGROUND.SMALL_SCREEN.IMAGE_HEIGHT,
width: '100%',
width: '200%',
position: 'absolute',
};
}
Expand Down
Loading