Skip to content

Conversation

@gladiuscode
Copy link
Owner

@gladiuscode gladiuscode commented Jun 26, 2025

Goal

This PR introduces a new sensor that is best suited on modern devices to obtain better data needed when computing device orientation, as per documentation.

Summary by CodeRabbit

  • New Features
    • Improved device orientation detection by supporting both the rotation vector sensor and the combination of accelerometer and magnetic field sensors. The app now automatically uses the most accurate sensor available for orientation calculations.

@gladiuscode gladiuscode self-assigned this Jun 26, 2025
@gladiuscode gladiuscode added enhancement New feature or request Android Android only labels Jun 26, 2025
@gladiuscode
Copy link
Owner Author

Note: merge this PR after this one #78

@gladiuscode gladiuscode force-pushed the feat/introduce-rotation-vector-sensor branch from 338f923 to 3d89a2c Compare June 26, 2025 21:44
@coderabbitai
Copy link

coderabbitai bot commented Jun 26, 2025

Walkthrough

The code now supports device orientation calculation using the rotation vector sensor as a priority, with fallback to the accelerometer and magnetic field sensors if the rotation vector sensor is unavailable. The sensor registration logic was updated to conditionally enable the appropriate sensors, and orientation computation was modularized into distinct private methods.

Changes

File(s) Change Summary
android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt Added support for rotation vector sensor; refactored orientation computation; updated sensor registration logic; introduced helper methods for orientation calculation and callback notification.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant OrientationSensorsEventListener
    participant SensorManager
    participant RotationVectorSensor
    participant Accelerometer
    participant MagneticField

    App->>OrientationSensorsEventListener: enable()
    OrientationSensorsEventListener->>SensorManager: Check for RotationVectorSensor
    alt RotationVectorSensor available
        OrientationSensorsEventListener->>SensorManager: Register RotationVectorSensor listener
        RotationVectorSensor-->>OrientationSensorsEventListener: onSensorChanged
        OrientationSensorsEventListener->>OrientationSensorsEventListener: computeOrientationFromRotationSensor()
    else
        OrientationSensorsEventListener->>SensorManager: Register Accelerometer & MagneticField listeners
        Accelerometer-->>OrientationSensorsEventListener: onSensorChanged
        MagneticField-->>OrientationSensorsEventListener: onSensorChanged
        OrientationSensorsEventListener->>OrientationSensorsEventListener: computeOrientationFromOtherSensors()
    end
    OrientationSensorsEventListener->>App: notifyOrientationAnglesChanged()
Loading

Poem

In circuits and code, new senses awake,
Rotation or fallback, we now undertake.
Sensors align, their data combined,
Orientation revealed, precisely defined.
With every device twist and spin,
The rabbit grins—let the sensing begin! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e5f89a and 3d89a2c.

📒 Files selected for processing (1)
  • android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt (3 hunks)
🧰 Additional context used
🪛 detekt (1.23.8)
android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt

[warning] 50-50: This empty block of code can be removed.

(detekt.empty-blocks.EmptyFunctionBlock)

🔇 Additional comments (7)
android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt (7)

13-26: LGTM! Proper sensor initialization and availability checking.

The sensor initialization logic correctly prioritizes the rotation vector sensor while maintaining fallback compatibility with older devices using accelerometer and magnetic field sensors. This aligns well with the PR objective to support modern Android hardware.


42-48: LGTM! Clean sensor event routing logic.

The conditional routing based on sensor type is implemented correctly, prioritizing the rotation vector sensor as intended.


50-50: Interface compliance: Empty method is intentional.

The empty onAccuracyChanged implementation is required by the SensorEventListener interface and is intentionally left empty since accuracy changes don't need handling in this implementation.


52-78: LGTM! Proper conditional sensor registration.

The enable method correctly implements the fallback strategy: prioritizing rotation vector sensor registration, then falling back to accelerometer and magnetic field sensors if the rotation sensor is unavailable. The sensor delay parameters are appropriate for UI-responsive orientation updates.


84-92: LGTM! Correct rotation vector sensor computation.

The implementation follows Android's official documentation for rotation vector sensors, properly converting the rotation vector to a rotation matrix and then to orientation angles.


94-118: LGTM! Proper fallback sensor computation.

The fallback computation correctly handles accelerometer and magnetometer data, with appropriate validation of the rotation matrix computation before proceeding with orientation calculation.


120-127: ```shell
#!/bin/bash
rg -n "mEventManager" -A5 -B5 android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.k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bh7yoXfPaL8/F7cgXWlBYtR+kLbgW1hRkeFtUDhIuaii7MHUCUfx6szfqbJxQAtGui5svL2z8pJYK1aG1KXUtpfQb2E8SL3MeaauhTLO54BINyqUAAxbGNgGZTT9IkZqXhgiz0dUmagPwKBUFkB84V2znoWwde6puOrSXHXZTC9MYrEDVQlfVRq0q2pyvbpiuGyrZGDTVVGzVRKwV6tTAaql1zblGLNX0xQlrx7WuEayMO9qNW1GdSwEatEtWIESLmFKWqdWhq+eGrlHbAWloFRCygCbRWVRTQiyVGaWpZsnbmpVOKi2Tr7bG8t5LDXVqiFaye9LG3GMnkyixsQrGTrsZERA3TyKJGzbYqJ0guB+uOLgQNwbR0dx+ZG3d07dWzooPOpNi7U2ItXTKtFNiMU8yxRQfNqr5XqsQyWmNxK43OUPVtHaVKiolWsvzOyDkjrOVvm5PIXAqDpXOlleQgVcpqHymFEjEV/zqHrBkRA9Z/AgheHQesplnChAsgYbjABmWgawACcaAABMDAABstAACMGxYgKZkzJgALAAVliJxAzaw0BGeU4ZtYJmFMGeswwTTnESBrHk4VYq3HxK8f44J5JInaD1hsh5oAA -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---



<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=gladiuscode/react-native-orientation-director&utm_content=80):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@gladiuscode gladiuscode merged commit 7397a64 into main Jun 26, 2025
1 check passed
@gladiuscode gladiuscode deleted the feat/introduce-rotation-vector-sensor branch June 26, 2025 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android Android only enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants