fix(ios): use topmost view controller for sign-in presentation#22
fix(ios): use topmost view controller for sign-in presentation#22OrkhanAlikhanov wants to merge 1 commit intosbaiahmed1:mainfrom
Conversation
📝 WalkthroughWalkthroughUpdated the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
|
One of the other libraries used No swift equivalent but its code is similar o what's in this PR: |
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
GIDSignInSDK'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()returnswindow.rootViewController, which may already be presenting a modal. WhenGIDSignInattempts to present its authentication view controller on a view controller that is already presenting something, iOS dismisses the new presentation immediately, resulting in aGIDSignInError.cancelederror.Fix
Traverse the presentation hierarchy to find the topmost presented view controller.
Summary by CodeRabbit