-
-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Web] Reset web-exclusive properties when handler is disabled. (#3041)
## Description As mentioned in [this comment](#3010 (comment)), it may be confusing that Gesture Handler blocks default events even if it is explicitly disabled. This PR adds styles reset when `enabled` property changes. Currently it changes 3 things: 1. Changes `touch-action` to default value 2. Changes `user-select` to default value 3. Re-enables context menu usage. I'm not sure if I missed something. If so, please mention it in a comment. ## Test plan Tested on newly added example.
- Loading branch information
Showing
6 changed files
with
171 additions
and
10 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,99 @@ | ||
import React, { useState } from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
import { | ||
Gesture, | ||
GestureDetector, | ||
Pressable, | ||
} from 'react-native-gesture-handler'; | ||
import Animated, { | ||
interpolateColor, | ||
useAnimatedStyle, | ||
useSharedValue, | ||
withTiming, | ||
} from 'react-native-reanimated'; | ||
|
||
const Colors = { | ||
enabled: '#32a852', | ||
disabled: '#b02525', | ||
}; | ||
|
||
const AnimationDuration = 250; | ||
|
||
export default function WebStylesResetExample() { | ||
const [enabled, setEnabled] = useState(true); | ||
const [x, setX] = useState(0); | ||
const [y, setY] = useState(0); | ||
|
||
const colorProgress = useSharedValue(0); | ||
|
||
const animatedStyles = useAnimatedStyle(() => { | ||
const backgroundColor = interpolateColor( | ||
colorProgress.value, | ||
[0, 1], | ||
[Colors.enabled, Colors.disabled] | ||
); | ||
|
||
return { backgroundColor }; | ||
}); | ||
|
||
const g = Gesture.Pan() | ||
.onUpdate((e) => { | ||
setX(e.x); | ||
setY(e.y); | ||
}) | ||
.enabled(enabled); | ||
|
||
return ( | ||
<View style={[styles.container, styles.centered]}> | ||
<GestureDetector gesture={g} enableContextMenu={false}> | ||
<Animated.View style={[styles.box, styles.centered, animatedStyles]}> | ||
<Text style={{ fontSize: 32 }}> Lorem Ipsum </Text> | ||
</Animated.View> | ||
</GestureDetector> | ||
|
||
<Pressable | ||
style={[styles.button, styles.centered]} | ||
onPress={() => { | ||
setEnabled((prev) => !prev); | ||
|
||
colorProgress.value = withTiming(enabled ? 1 : 0, { | ||
duration: AnimationDuration, | ||
}); | ||
}}> | ||
<Text style={{ fontSize: 16 }}>{enabled ? 'Disable' : 'Enable'}</Text> | ||
</Pressable> | ||
|
||
<Text style={{ fontSize: 16 }}> | ||
{' '} | ||
x: {x}, y: {y}{' '} | ||
</Text> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
centered: { | ||
display: 'flex', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
}, | ||
|
||
container: { | ||
flex: 1, | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
|
||
button: { | ||
width: 250, | ||
height: 35, | ||
backgroundColor: 'plum', | ||
borderRadius: 10, | ||
margin: 25, | ||
}, | ||
|
||
box: { | ||
width: 250, | ||
height: 250, | ||
borderRadius: 25, | ||
}, | ||
}); |
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