-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23737 from wojtus7/gyroscope
- Loading branch information
Showing
8 changed files
with
71 additions
and
23 deletions.
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