Skip to content

Commit cd02c72

Browse files
authored
fix(expo-google-signin): resolve presenting view controller from the key window on iOS (#9505)
1 parent c199913 commit cd02c72

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/expo-google-signin': patch
3+
---
4+
5+
Fix iOS Google sign-in failing with `GOOGLE_SIGN_IN_ERROR` in apps with more than one window or scene. The presenting view controller is now resolved from the key window of the foreground-active scene instead of an arbitrary window, so overlays such as splash screens or windows created by other modules no longer break the sign-in flow.

packages/expo-google-signin/ios/ClerkGoogleSignInModule.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,19 @@ public class ClerkGoogleSignInModule: Module {
143143
}
144144

145145
private func getPresentingViewController() -> UIViewController? {
146-
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
147-
let window = scene.windows.first,
146+
let scenes = UIApplication.shared.connectedScenes.compactMap { $0 as? UIWindowScene }
147+
let scene = scenes.first { $0.activationState == .foregroundActive }
148+
?? scenes.first { $0.activationState == .foregroundInactive }
149+
?? scenes.first
150+
151+
guard let window = scene?.windows.first(where: { $0.isKeyWindow && !$0.isHidden && $0.rootViewController != nil })
152+
?? scene?.windows.first(where: { !$0.isHidden && $0.rootViewController != nil }),
148153
let rootVC = window.rootViewController else {
149154
return nil
150155
}
151156

152157
var topVC = rootVC
153-
while let presentedVC = topVC.presentedViewController {
158+
while let presentedVC = topVC.presentedViewController, !presentedVC.isBeingDismissed {
154159
topVC = presentedVC
155160
}
156161
return topVC

0 commit comments

Comments
 (0)