Skip to content

[Android] Correct Rotation handler#4079

Merged
m-bert merged 1 commit intomainfrom
@mbert/android-rotation-end
Apr 13, 2026
Merged

[Android] Correct Rotation handler#4079
m-bert merged 1 commit intomainfrom
@mbert/android-rotation-end

Conversation

@m-bert
Copy link
Copy Markdown
Contributor

@m-bert m-bert commented Apr 10, 2026

Description

Follow up for #4078

I've noticed that when Rotation does not activate, but pointers are released, onFinalize is called with true. This happens because we try to move it to END state, but our internal logic does not send onDeactivate.

Code in onHandle that I removed was effectively dead, as ACTION_UP was handled in rotation detector - the only possible branch was else statement which fails handler if only one pointer was present.

Test plan

Tested on Transformations example and the following code:
import { StyleSheet, View } from 'react-native';
import {
  GestureDetector,
  GestureHandlerRootView,
  usePinchGesture,
  useRotationGesture,
} from 'react-native-gesture-handler';

export default function App() {
  const g = useRotationGesture({
    onBegin: () => console.log('onBegin'),
    onActivate: () => console.log('onActivate'),
    onUpdate: (e) => console.log('onUpdate', e.rotation),
    onDeactivate: () => console.log('onDeactivate'),
    onFinalize: (_, s) => console.log('onFinalize', s),
  });

  return (
    <GestureHandlerRootView style={styles.container}>
      <GestureDetector gesture={g}>
        <View style={styles.box} />
      </GestureDetector>
    </GestureHandlerRootView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 200,
    height: 200,
    backgroundColor: 'blue',
    borderRadius: 12,
  },
});

Copilot AI review requested due to automatic review settings April 10, 2026 17:49
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes Android RotationGestureHandler state transitions so onFinalize receives the correct success flag when rotation never activates but pointers are released (aligning behavior with the intended gesture lifecycle).

Changes:

  • Update onRotationEnd to end() only when the handler is STATE_ACTIVE, otherwise fail().
  • Remove dead ACTION_UP handling from onHandle and keep a targeted fail path for single-pointer ACTION_UP while still in STATE_BEGAN.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@m-bert m-bert changed the title [Android] Correctly Rotation handler [Android] Correct Rotation handler Apr 13, 2026
@m-bert m-bert requested a review from j-piasecki April 13, 2026 08:00
@m-bert m-bert merged commit d3631c4 into main Apr 13, 2026
7 checks passed
@m-bert m-bert deleted the @mbert/android-rotation-end branch April 13, 2026 10:40
m-bert added a commit that referenced this pull request Apr 13, 2026
## Description

I've noticed that `Pinch` and `Rotation` behave weirdly when it comes to
ending gesture on web. I've took a look and fixed some minor issues.

> [!NOTE]
> This PR may introduce mismatch between `android` and `web` versions of
`Rotation`. I still think that this is how it is supposed to work, so we
may want to [make required changes to `android` as
well](#4079)
(or drop this PR if you prefer to).

### Pinch

I've noticed that `Pinch` is not reset when pointers are placed on view
and then released. This was because for some reason `Pinch` simply
ignored finished states if it had not activated earlier.

### Rotation 

`Rotation`, always finalized with `true`. This was because we always
tried to move it to `end` state. Our internal event handler hadn't been
sending `onDeactivate`, but `true` was still passed into `onFinalize`.

## Test plan

<details>
<summary>Tested on Transformations example and code below:</summary>

```tsx
import { StyleSheet, View } from 'react-native';
import {
  GestureDetector,
  GestureHandlerRootView,
  usePinchGesture,
  useRotationGesture,
} from 'react-native-gesture-handler';

export default function App() {
  const g = useRotationGesture({
    onBegin: () => console.log('onBegin'),
    onActivate: () => console.log('onActivate'),
    onUpdate: (e) => console.log('onUpdate', e.rotation),
    onDeactivate: () => console.log('onDeactivate'),
    onFinalize: (_, s) => console.log('onFinalize', s),
  });

  return (
    <GestureHandlerRootView style={styles.container}>
      <GestureDetector gesture={g}>
        <View style={styles.box} />
      </GestureDetector>
    </GestureHandlerRootView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  box: {
    width: 200,
    height: 200,
    backgroundColor: 'blue',
    borderRadius: 12,
  },
});
```

</details>
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.

3 participants