Skip to content

fix(ios): use topmost view controller for sign-in presentation#22

Open
OrkhanAlikhanov wants to merge 1 commit intosbaiahmed1:mainfrom
OrkhanAlikhanov:patch-1
Open

fix(ios): use topmost view controller for sign-in presentation#22
OrkhanAlikhanov wants to merge 1 commit intosbaiahmed1:mainfrom
OrkhanAlikhanov:patch-1

Conversation

@OrkhanAlikhanov
Copy link
Copy Markdown

@OrkhanAlikhanov OrkhanAlikhanov commented Apr 19, 2026

Problem

Google Sign-In immediately cancels when triggered from a modal screen (e.g., a login/register modal in React Navigation or Expo Router). The GIDSignIn SDK's auth view controller gets dismissed instantly because it's presented on the root view controller while a modal is already covering it.

Root Cause

getPresentingViewController() returns window.rootViewController, which may already be presenting a modal. When GIDSignIn attempts to present its authentication view controller on a view controller that is already presenting something, iOS dismisses the new presentation immediately, resulting in a GIDSignInError.canceled error.

Fix

Traverse the presentation hierarchy to find the topmost presented view controller.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue on iOS where authentication dialogs could appear in incorrect positions on the screen.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 19, 2026

📝 Walkthrough

Walkthrough

Updated the getPresentingViewController() method to traverse the view controller hierarchy and return the topmost presented UIViewController instead of just the window's root view controller, with additional safety checks for scene and window availability.

Changes

Cohort / File(s) Summary
View Controller Retrieval
ios/GoogleAuth.swift
Modified getPresentingViewController() to iterate through presented view controllers to find the topmost one in the hierarchy, replacing the previous approach of returning only the root view controller. Added guard statements to validate UIWindowScene and key window existence.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hops up the controller tree so tall,
Finding the topmost view of all,
No longer stuck at the root below,
Now reaching where the presents go! 🌳✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: finding and using the topmost view controller for sign-in presentation instead of just the root view controller.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@ios/GoogleAuth.swift`:
- Around line 438-449: Replace the use of
UIApplication.shared.connectedScenes.first (which is unordered) with a search
through UIApplication.shared.connectedScenes to find the active UIWindowScene
(e.g., filter scenes where scene.activationState == .foregroundActive and scene
is UIWindowScene), then from that scene get the key window via
scene.windows.first(where: { $0.isKeyWindow }) and traverse its
rootViewController to find the topViewController; update the block that
currently declares scene/window/topViewController (the code that uses
connectedScenes.first and topViewController) to iterate scenes, pick the
foreground active UIWindowScene, and fall back safely if none found.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 68d6273d-dd91-49bb-b34b-31ef3ee11671

📥 Commits

Reviewing files that changed from the base of the PR and between 3f5a6c8 and 78d1519.

📒 Files selected for processing (1)
  • ios/GoogleAuth.swift

Comment thread ios/GoogleAuth.swift
@OrkhanAlikhanov
Copy link
Copy Markdown
Author

OrkhanAlikhanov commented Apr 19, 2026

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.

1 participant