Skip to content

Commit

Permalink
Fix bug where accessibility change resets context (#53)
Browse files Browse the repository at this point in the history
Resolves #51

Creates and stores the context on the `AnyExhibit` model before view body calculation. This ensures that when swiftUI re-runs the body, we maintain the context for each exhibit.

![Kapture 2022-03-07 at 12 33 43](https://user-images.githubusercontent.com/609274/157113509-19ab2e95-4be8-415a-84ab-8304009915f6.gif)
  • Loading branch information
Malcolm Jarvis authored Mar 8, 2022
1 parent ed68c81 commit eced467
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Sources/Exhibition/Exhibit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public struct AnyExhibit {
let name: String
let section: String
let content: (Context) -> AnyView
let context = Context()

init<Content: View, Layout: View>(_ exhibit: Exhibit<Content>, layout: @escaping (Content) -> Layout) {
self.name = exhibit.name
Expand All @@ -59,6 +60,11 @@ struct AnyExhibitView: View {
let exhibit: AnyExhibit
@ObservedObject var context: Context

init(exhibit: AnyExhibit) {
self.exhibit = exhibit
self.context = exhibit.context
}

var body: some View {
exhibit.content(context)
}
Expand Down
5 changes: 2 additions & 3 deletions Sources/Exhibition/ExhibitListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ public struct ExhibitListView: View {
}

private func debuggable(_ exhibit: AnyExhibit) -> some View {
let context = Context()
return AnyExhibitView(exhibit: exhibit, context: context)
return AnyExhibitView(exhibit: exhibit)
.toolbar {
ToolbarItem {
Button {
Expand All @@ -92,7 +91,7 @@ public struct ExhibitListView: View {
}
.sheet(isPresented: $exhibitDebugViewPresented) {
DebugView(
context: context,
context: exhibit.context,
preferredColorScheme: $preferredColorScheme,
layoutDirection: $layoutDirection
)
Expand Down

0 comments on commit eced467

Please sign in to comment.