-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
5677c9c
Gyroscope
wojtus7 a88ddb6
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 ca0fb68
Make animations better (I think)
wojtus7 311ba60
Revert changes
wojtus7 95bc009
Add new line
wojtus7 b8dc279
Add permissions for android
wojtus7 fe804f9
Lint
wojtus7 4eb50dc
Prettier
wojtus7 fa2d7de
Return props
wojtus7 7520ffe
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 06c0786
Add mocks in reanimated patch to fix tests
wojtus7 ae0469b
Test of reanimated 3.4.2 to see if CI works
wojtus7 712c340
Use reanimated 3.4.2
wojtus7 a84745d
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 8d133f0
Improvements
wojtus7 5cf9633
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 2952c0b
Revert change of cocoapods version
wojtus7 353ac37
Remove animation boost
wojtus7 bab35a7
Create AnimatedEmptyStateBackground
wojtus7 e086a59
Remove redundant isSmallScreenWidth prop
wojtus7 4da5ddd
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 09480c1
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 9d58b64
Merge remote-tracking branch 'upstream/main' into gyroscope
wojtus7 8051ce2
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 a750eec
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 5ecaef9
Fix types
wojtus7 1289ebd
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 ded2f0b
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 0f7a852
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 d9bd159
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 bb74a0c
Merge remote-tracking branch 'origin/main' into gyroscope
wojtus7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import Animated, {SensorType, useAnimatedSensor, useAnimatedStyle, useSharedValue, withSpring} from 'react-native-reanimated'; | ||
import useWindowDimensions from '../../../hooks/useWindowDimensions'; | ||
import * as NumberUtils from '../../../libs/NumberUtils'; | ||
import EmptyStateBackgroundImage from '../../../../assets/images/empty-state_background-fade.png'; | ||
import * as StyleUtils from '../../../styles/StyleUtils'; | ||
|
||
const IMAGE_OFFSET_Y = 75; | ||
|
||
function AnimatedEmptyStateBackground() { | ||
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(() => { | ||
if (!isSmallScreenWidth) { | ||
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 = NumberUtils.clampWorklet(xOffset.value + y, -IMAGE_OFFSET_X, IMAGE_OFFSET_X); | ||
yOffset.value = NumberUtils.clampWorklet(yOffset.value - x, -IMAGE_OFFSET_Y, IMAGE_OFFSET_Y); | ||
return { | ||
transform: [{translateX: withSpring(-IMAGE_OFFSET_X - xOffset.value)}, {translateY: withSpring(yOffset.value)}], | ||
}; | ||
}); | ||
|
||
return ( | ||
<Animated.Image | ||
pointerEvents="none" | ||
source={EmptyStateBackgroundImage} | ||
style={[StyleUtils.getReportWelcomeBackgroundImageStyle(isSmallScreenWidth), animatedStyles]} | ||
/> | ||
); | ||
} | ||
|
||
AnimatedEmptyStateBackground.displayName = 'AnimatedEmptyStateBackground'; | ||
export default AnimatedEmptyStateBackground; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The addition of AnimatedEmptyStateBackground caused a scrolling issue #29038 which we fixed in #29102