Skip to content

Conversation

@gladiuscode
Copy link
Owner

@gladiuscode gladiuscode commented Jul 19, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency of orientation handling, ensuring the app's interface orientation aligns more closely with system settings and matches behavior across platforms.
  • Refactor

    • Simplified orientation detection and interface orientation update logic for better reliability and maintainability.

@gladiuscode gladiuscode self-assigned this Jul 19, 2025
@gladiuscode gladiuscode added bug Something isn't working Android Android only labels Jul 19, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 19, 2025

Walkthrough

The code refactors a method in the OrientationDirectorModuleImpl class, renaming and simplifying its signature and logic. The updated method now determines interface orientation based on the system's current rotation, removes the device orientation parameter, and adjusts orientation updates to align with iOS behavior. All internal calls are updated accordingly. Additionally, the orientation detection logic in Utils.kt was simplified by removing multiple helper functions and constants, replacing them with a single tolerance check to streamline device orientation determination.

Changes

File(s) Change Summary
android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt Renamed and refactored adaptInterfaceTo to checkInterfaceOrientation, simplified logic, updated all calls.
android/src/main/java/com/orientationdirector/implementation/Utils.kt Simplified convertToDeviceOrientationFrom by removing helper functions and constants; removed unused methods.

Possibly related PRs

Poem

A hop and a skip, the method’s anew,
No more device angles, just what the system knew!
Left and right now swap with glee,
Matching iOS, as neat as can be.
With every rotation, the code’s more concise—
Bunny-approved logic, precise and nice!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 7cfd1ec and 2e4868a.

📒 Files selected for processing (1)
  • android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • android/src/main/java/com/orientationdirector/implementation/OrientationDirectorModuleImpl.kt
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/broken-interface-orientation-computation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • 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 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 for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1ca4078 and 7054749.

📒 Files selected for processing (1)
  • android/src/main/java/com/orientationdirector/implementation/Utils.kt (1 hunks)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
android/src/main/java/com/orientationdirector/implementation/Utils.kt (1)

30-32: Consider extracting the tolerance constants.

The inline helper function is clean, but the tolerance values are scattered throughout the method. Consider extracting them as constants for better maintainability and consistency.

+private const val FACE_UP_DOWN_PITCH_TOLERANCE = 30f
+private const val ORIENTATION_TOLERANCE = 45f
+private const val FACE_UP_DOWN_ROLL_TOLERANCE = 30f

 fun convertToDeviceOrientationFrom(orientationAngles: FloatArray): Orientation {
   // ... existing code ...
-  val faceUpDownPitchTolerance = 30f
   
   fun isValueCloseTo(value: Float, target: Float, tolerance: Float): Boolean {
     return value in (target - tolerance)..(target + tolerance)
   }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c0dfaf3 and 4951d29.

📒 Files selected for processing (1)
  • android/src/main/java/com/orientationdirector/implementation/Utils.kt (1 hunks)
🔇 Additional comments (1)
android/src/main/java/com/orientationdirector/implementation/Utils.kt (1)

34-54: Orientation mappings and tolerances confirmed
All mappings in convertToDeviceOrientationFrom align with the expected device orientations, and the existing tests cover each principal case. While the 45° roll and 30° pitch tolerances do produce overlapping detection regions at their boundaries (for example, roll = ±45° with pitch within ±30°), the when‐branch order (face up/down → portrait → portrait-upside-down → landscape) ensures a deterministic outcome.

• File: android/src/main/java/com/orientationdirector/implementation/Utils.kt
– faceUp/down: pitch ±30°, roll ±45°
– portrait/u-down: pitch ±45° around ±90°
– landscape: roll ±45° around ±90°
– branch priority avoids ambiguity on overlaps
• Tests in UtilsTest.kt validate the central angle cases for each orientation

If you need to guarantee behavior exactly at the tolerance boundaries, you may add tests for those edge values or adjust the tolerance constants. Otherwise, no changes are required here.

@gladiuscode
Copy link
Owner Author

@coderabbitai review

@coderabbitai
Copy link

coderabbitai bot commented Jul 19, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@gladiuscode gladiuscode merged commit 26cf330 into main Jul 27, 2025
6 checks passed
@gladiuscode gladiuscode deleted the fix/broken-interface-orientation-computation branch July 27, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android Android only bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Android low end OrientationSensor is too sensitive to tilt left/rigth in landscape-right/left

2 participants