Skip to content

Commit 9efe0fc

Browse files
fix(mobile): reset Clerk navigation guard after transitions
1 parent 918b5f3 commit 9efe0fc

3 files changed

Lines changed: 39 additions & 26 deletions

File tree

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Host } from "@expo/ui/jetpack-compose";
2-
import type { ComponentProps } from "react";
2+
import { useMemo, type ComponentProps } from "react";
33
import { createNativeThemeColors } from "../../lib/nativeTheme";
44
import { useControlTheme } from "./useControlTheme";
55

@@ -8,11 +8,9 @@ export function NativeThemeHost(
88
props: Omit<ComponentProps<typeof Host>, "colorScheme" | "seedColor" | "colorOverrides">,
99
) {
1010
const { colors, colorScheme, systemColorsActive } = useControlTheme();
11-
return (
12-
<Host
13-
{...props}
14-
colorScheme={colorScheme}
15-
colorOverrides={systemColorsActive ? undefined : createNativeThemeColors(colors)}
16-
/>
11+
const colorOverrides = useMemo(
12+
() => (systemColorsActive ? undefined : createNativeThemeColors(colors)),
13+
[colors, systemColorsActive],
1714
);
15+
return <Host {...props} colorScheme={colorScheme} colorOverrides={colorOverrides} />;
1816
}

‎patches/@[email protected]‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ index 0946d68..1926024 100644
1212
+ // dependency; AGP 9 resolves the compile classpath on its own.
1313
+ implementation "androidx.savedstate:savedstate-compose:1.4.0"
1414
+ implementation "androidx.lifecycle:lifecycle-runtime-compose:2.10.0"
15-
15+
1616
testImplementation "junit:junit:4.13.2"
1717
}
1818
diff --git a/ios/ClerkAuthNativeView.swift b/ios/ClerkAuthNativeView.swift
1919
index 5f8d2ba..b170304 100644
2020
--- a/ios/ClerkAuthNativeView.swift
2121
+++ b/ios/ClerkAuthNativeView.swift
2222
@@ -111,7 +111,12 @@ public class ClerkAuthNativeView: ClerkNativeViewHost {
23-
23+
2424
override func makeHostedController() -> UIViewController? {
2525
let hostBackAction: (() -> Void)? = currentHostBackButton
2626
- ? { [weak self] in self?.onHostBack([:]) }
@@ -31,15 +31,15 @@ index 5f8d2ba..b170304 100644
3131
+ }
3232
+ }
3333
: nil
34-
34+
3535
return ClerkNativeBridge.shared.makeAuthViewController(
3636
diff --git a/ios/ClerkNativeBridge.swift b/ios/ClerkNativeBridge.swift
3737
index e9527c6..a59ee3b 100644
3838
--- a/ios/ClerkNativeBridge.swift
3939
+++ b/ios/ClerkNativeBridge.swift
4040
@@ -1557,6 +1557,8 @@ private struct ClerkReactEmbeddedUserProfileCustomPage: View {
4141
}
42-
42+
4343
private struct ClerkReactUserProfileCustomPageContent: View {
4444
+ @Environment(\.clerkTheme) private var theme
4545
+
@@ -59,23 +59,31 @@ index e9527c6..a59ee3b 100644
5959
+ .background(theme.colors.background)
6060
}
6161
}
62-
62+
6363
diff --git a/ios/ClerkNativeViewHost.swift b/ios/ClerkNativeViewHost.swift
64-
index 4e6540a..cc16c94 100644
64+
index 4e6540a..6897350 100644
6565
--- a/ios/ClerkNativeViewHost.swift
6666
+++ b/ios/ClerkNativeViewHost.swift
6767
@@ -5,6 +5,7 @@ public class ClerkNativeViewHost: ExpoView {
6868
private lazy var hostingCoordinator = ClerkNativeHostingCoordinator(containerView: self)
6969
private var hasInitialized: Bool = false
7070
private var configuredObserver: NSObjectProtocol?
7171
+ private var isPoppingHostRoute = false
72-
72+
7373
public required init(appContext: AppContext? = nil) {
7474
super.init(appContext: appContext)
75-
@@ -58,6 +59,30 @@ public class ClerkNativeViewHost: ExpoView {
76-
75+
@@ -23,6 +24,7 @@ public class ClerkNativeViewHost: ExpoView {
76+
super.didMoveToWindow()
77+
78+
guard window != nil else {
79+
+ isPoppingHostRoute = false
80+
if hasInitialized {
81+
hostedViewDidDetachFromWindow()
82+
}
83+
@@ -58,6 +60,37 @@ public class ClerkNativeViewHost: ExpoView {
84+
7785
func hostedViewDidDetachFromWindow() {}
78-
86+
7987
+ /// Pops the React Navigation route that contains this view without waiting for
8088
+ /// the JavaScript event loop. React Native Screens reports the native dismissal
8189
+ /// back to React Navigation so its state remains synchronized.
@@ -90,6 +98,13 @@ index 4e6540a..cc16c94 100644
9098
+ navigationController.viewControllers.count > 1 {
9199
+ isPoppingHostRoute = true
92100
+ if navigationController.popViewController(animated: true) != nil {
101+
+ if let coordinator = navigationController.transitionCoordinator {
102+
+ coordinator.animate(alongsideTransition: nil) { [weak self] _ in
103+
+ self?.isPoppingHostRoute = false
104+
+ }
105+
+ } else {
106+
+ isPoppingHostRoute = false
107+
+ }
93108
+ return true
94109
+ }
95110
+ isPoppingHostRoute = false
@@ -102,13 +117,13 @@ index 4e6540a..cc16c94 100644
102117
+
103118
private func addConfiguredObserver() {
104119
guard configuredObserver == nil else { return }
105-
120+
106121
diff --git a/ios/ClerkUserProfileNativeView.swift b/ios/ClerkUserProfileNativeView.swift
107122
index f2ca604..46f406d 100644
108123
--- a/ios/ClerkUserProfileNativeView.swift
109124
+++ b/ios/ClerkUserProfileNativeView.swift
110125
@@ -47,7 +47,12 @@ public class ClerkUserProfileNativeView: ClerkUserProfileCustomPageHost {
111-
126+
112127
override func makeHostedController() -> UIViewController? {
113128
let hostBackAction: (() -> Void)? = currentHostBackButton
114129
- ? { [weak self] in self?.onHostBack([:]) }
@@ -119,5 +134,5 @@ index f2ca604..46f406d 100644
119134
+ }
120135
+ }
121136
: nil
122-
137+
123138
return ClerkNativeBridge.shared.makeUserProfileViewController(

‎pnpm-lock.yaml‎

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)