-
-
Notifications
You must be signed in to change notification settings - Fork 983
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description This PR adds more information about `stylus` to event. `Pan` and `Hover` events now have `stylusData` field, which contains the following information: - `tiltX` - `tiltY` - `altitudeAngle` - `azimuthAngle` - `pressure` >[!IMPORTANT] > Because we receive only one set of data (either `tiltX/tiltY` or `altitudeAngle/azimuthAngle`, we use [this conversion algorithm](https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle) to calculate second set. >[!NOTE] > This PR adds `stylusData` only on web, native platforms will be handled in another PRs ## Test plan Tested on newly added example.
- Loading branch information
Showing
12 changed files
with
355 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React from 'react'; | ||
import { StyleSheet, View, Image } from 'react-native'; | ||
import { Gesture, GestureDetector } from 'react-native-gesture-handler'; | ||
import Animated, { | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withTiming, | ||
} from 'react-native-reanimated'; | ||
|
||
const GH = require('../../new_api/hoverable_icons/gh.png'); | ||
|
||
export default function StylusData() { | ||
const scaleFactor = useSharedValue(0); | ||
const rotationXFactor = useSharedValue(0); | ||
const rotationYFactor = useSharedValue(0); | ||
|
||
const pan = Gesture.Pan() | ||
.onBegin((e) => { | ||
if (!e.stylusData) { | ||
return; | ||
} | ||
|
||
scaleFactor.value = e.stylusData.pressure; | ||
rotationYFactor.value = e.stylusData.tiltX; | ||
rotationXFactor.value = e.stylusData.tiltY; | ||
}) | ||
.onStart(() => {}) | ||
.onChange((e) => { | ||
if (!e.stylusData) { | ||
return; | ||
} | ||
|
||
scaleFactor.value = e.stylusData.pressure; | ||
rotationYFactor.value = e.stylusData.tiltX; | ||
rotationXFactor.value = e.stylusData.tiltY; | ||
}) | ||
.onFinalize((e) => { | ||
if (!e.stylusData) { | ||
return; | ||
} | ||
|
||
scaleFactor.value = withTiming(0, { duration: 250 }); | ||
rotationXFactor.value = withTiming(0, { duration: 250 }); | ||
rotationYFactor.value = withTiming(0, { duration: 250 }); | ||
}) | ||
.minDistance(0); | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
return { | ||
transform: [ | ||
{ scale: 1 + scaleFactor.value }, | ||
{ rotateY: `${rotationYFactor.value}deg` }, | ||
{ rotateX: `${rotationXFactor.value}deg` }, | ||
], | ||
}; | ||
}); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<GestureDetector gesture={pan}> | ||
<Animated.View style={[styles.ball, animatedStyle]}> | ||
<Image | ||
source={GH} | ||
// @ts-ignore pointerEvents exists | ||
style={{ width: 180, height: 180, pointerEvents: 'none' }} | ||
/> | ||
</Animated.View> | ||
</GestureDetector> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
|
||
ball: { | ||
width: 200, | ||
height: 200, | ||
borderWidth: 2, | ||
borderRadius: 100, | ||
backgroundColor: '#c8e3f7', | ||
|
||
display: 'flex', | ||
justifyContent: 'space-around', | ||
alignItems: 'center', | ||
}, | ||
}); |
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
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
Oops, something went wrong.