Skip to content

Commit 84cda93

Browse files
Removes use of @binding on FlowNavigator
On iOS 14, @binding can trigger unwanted re-renders. Also sets environment object manually since on iOS 14, the environment is not propagated to presented views.
1 parent c20db17 commit 84cda93

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

FlowStacksApp.xcodeproj/project.pbxproj

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
/* End PBXBuildFile section */
3131

3232
/* Begin PBXFileReference section */
33+
521678E22A2FD6AE00954579 /* FlowStacks */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlowStacks; sourceTree = "<group>"; };
3334
5241BF3326AA1D3B002D6892 /* FlowStacksApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlowStacksApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
3435
5241BF3926AA1D3B002D6892 /* FlowStacksApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FlowStacksApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
3536
525C73362774BA6B009CBD67 /* NumberCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NumberCoordinator.swift; sourceTree = "<group>"; };
@@ -38,7 +39,6 @@
3839
526D9F1C26AF661F00B6B882 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3940
526D9F2226AF661F00B6B882 /* VMCoordinator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VMCoordinator.swift; sourceTree = "<group>"; };
4041
526D9F3226AF667000B6B882 /* FlowStacksApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowStacksApp.swift; sourceTree = "<group>"; };
41-
52937A3F28904C8B001B4EF3 /* FlowStacks */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlowStacks; sourceTree = "<group>"; };
4242
52C5CCDB286E5D780075ABA7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4343
52C5CCDD286EE92B0075ABA7 /* Deeplink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deeplink.swift; sourceTree = "<group>"; };
4444
77F136EC282E45DF008A6A02 /* ParentCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ParentCoordinator.swift; sourceTree = "<group>"; };
@@ -66,10 +66,18 @@
6666
/* End PBXFrameworksBuildPhase section */
6767

6868
/* Begin PBXGroup section */
69+
521678E12A2FD6AE00954579 /* Packages */ = {
70+
isa = PBXGroup;
71+
children = (
72+
521678E22A2FD6AE00954579 /* FlowStacks */,
73+
);
74+
name = Packages;
75+
sourceTree = "<group>";
76+
};
6977
5241BF2626AA1D3A002D6892 = {
7078
isa = PBXGroup;
7179
children = (
72-
52937A3E28904C8B001B4EF3 /* Packages */,
80+
521678E12A2FD6AE00954579 /* Packages */,
7381
526D9F1B26AF661F00B6B882 /* FlowStacksApp */,
7482
5241BF3426AA1D3B002D6892 /* Products */,
7583
5241BF6D26AA1E8A002D6892 /* Frameworks */,
@@ -116,14 +124,6 @@
116124
path = Shared;
117125
sourceTree = "<group>";
118126
};
119-
52937A3E28904C8B001B4EF3 /* Packages */ = {
120-
isa = PBXGroup;
121-
children = (
122-
52937A3F28904C8B001B4EF3 /* FlowStacks */,
123-
);
124-
name = Packages;
125-
sourceTree = "<group>";
126-
};
127127
/* End PBXGroup section */
128128

129129
/* Begin PBXNativeTarget section */

Sources/FlowStacks/FlowNavigator.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@ import SwiftUI
55
/// pushing, presenting and going back.
66
@MainActor
77
public class FlowNavigator<Screen>: ObservableObject {
8-
@Binding public var routes: [Route<Screen>]
8+
var routesBinding: Binding<[Route<Screen>]>
99

10-
public init(_ routes: Binding<[Route<Screen>]>) {
11-
self._routes = routes
10+
public var routes: [Route<Screen>] {
11+
get { routesBinding.wrappedValue }
12+
set { routesBinding.wrappedValue = newValue }
13+
}
14+
15+
public init(_ routesBinding: Binding<[Route<Screen>]>) {
16+
self.routesBinding = routesBinding
1217
}
1318
}

Sources/FlowStacks/View+showing.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public extension View {
5656
case .root:
5757
self
5858
case .screen(let screen):
59-
buildView(screen, index - 1)
59+
buildView(screen, index - 1).environmentObject(FlowNavigator<Screen>(routes))
6060
}
6161
}.environmentObject(FlowNavigator<Screen>(routes))
6262
}

0 commit comments

Comments
 (0)