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

[Android] Fix Hover blocking scrolling with mouse wheel #3067

Merged
merged 1 commit into from
Aug 26, 2024

Conversation

m-bert
Copy link
Contributor

@m-bert m-bert commented Aug 25, 2024

Description

This PR fixes issue in which Hover gesture blocks mouse wheel scroll. At first I thought that we should mark Hover as simultaneous with ScrollView (or to be more precise, NativeViewGestureHandler that wraps ScrollView), but it turned out that it was not the case. Instead of working simultaneous with ScrollView, we have to set this relation with RootViewGestureHandler.

Fixes #3064

Test plan

Tested on code from issue
import {
  Text,
  SafeAreaView,
  StyleSheet,
  StatusBar,
  Pressable,
} from 'react-native';
import {
  GestureHandlerRootView,
  ScrollView,
  Gesture,
  GestureDetector,
} from 'react-native-gesture-handler';
import { useSharedValue } from 'react-native-reanimated';

export default function App() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <SafeAreaView style={styles.container}>
        <StatusBar />
        <ScrollView>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>
          <Text style={{ height: 50, backgroundColor: 'red' }}>item</Text>

          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
          <Button title="Button1" />
        </ScrollView>
      </SafeAreaView>
    </GestureHandlerRootView>
  );
}

const Button = (props) => {
  const hovered = useSharedValue(false);
  const hover = Gesture.Hover()
    .onStart((e) => {
      console.log('hover start');
    })
    .onEnd((e) => {
      hovered.value = false;
      console.log('hover end');
    });

  return (
    <GestureDetector gesture={hover}>
      <Pressable {...props}>
        <Text>{props.title}</Text>
      </Pressable>
    </GestureDetector>
  );
};
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
});

@m-bert m-bert requested a review from j-piasecki August 25, 2024 13:04
@@ -70,6 +71,10 @@ class HoverGestureHandler : GestureHandler<HoverGestureHandler>() {
return true
}

if (handler is RNGestureHandlerRootHelper.RootViewGestureHandler) {
Copy link
Contributor Author

@m-bert m-bert Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also specify that pointerType has to be mouse. However, I haven't found any issue with stylus

Suggested change
if (handler is RNGestureHandlerRootHelper.RootViewGestureHandler) {
if (handler is RNGestureHandlerRootHelper.RootViewGestureHandler && pointerType == POINTER_TYPE_MOUSE) {

@proohit
Copy link

proohit commented Aug 26, 2024

I can confirm this fix works for my specific case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hover nested in ScrollView and scrolling ScrollView not working simultanously on Android
3 participants