Skip to content

Commit b8666e1

Browse files
authored
feat: allow SwiftUI ViewEnvironment access via SPI (#357)
Restores the ability to bridge ViewEnvironment back out, which was removed in #319. This PR does it with SPI currently, but tbh I think we could safely revert the deprecation and be OK.
1 parent ab3afe8 commit b8666e1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

ViewEnvironment/Sources/EnvironmentValues+ViewEnvironment.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@ extension EnvironmentValues {
2929
}
3030
}
3131

32+
@_spi(ViewEnvironmentWiring)
33+
public struct ViewEnvironmentWrapper {
34+
public var viewEnvironment: ViewEnvironment
35+
36+
public init(_ viewEnvironment: ViewEnvironment) {
37+
self.viewEnvironment = viewEnvironment
38+
}
39+
}
40+
41+
extension EnvironmentValues {
42+
@_spi(ViewEnvironmentWiring)
43+
public var viewEnvironmentWrapper: ViewEnvironmentWrapper {
44+
get { ViewEnvironmentWrapper(self[ViewEnvironmentKey.self]) }
45+
set { self[ViewEnvironmentKey.self] = newValue.viewEnvironment }
46+
}
47+
}
48+
3249
extension Environment where Value == ViewEnvironment {
3350
@available(
3451
*,

0 commit comments

Comments
 (0)