-
I have this very simple app that just navigates one screen, and then on button press dismisses it. However, when the dismissal happens, the screen that is supposed to be dismissed disappears, and instead there is just a black or white background that is animated. I have found that this does not happen on iOS 16. @main
struct EntryPoint: App {
var body: some Scene {
WindowGroup {
AppRoot(store: Store(initialState: AppRootFeature.State(), reducer: {
AppRootFeature()
}))
}
}
}
struct AppRootFeature: Reducer {
struct State: Equatable {
var appFeature = AppFeature.State()
var path = StackState<Path.State>()
}
enum Action: Equatable {
case path(StackAction<Path.State, Path.Action>)
case appFeature(AppFeature.Action)
}
struct Path: Reducer {
enum State: Equatable {
case secondFeature(SecondFeature.State)
}
enum Action: Equatable {
case secondFeature(SecondFeature.Action)
}
var body: some ReducerOf<Self> {
Scope(state: /State.secondFeature, action: /Action.secondFeature) {
SecondFeature()
}
}
}
var body: some ReducerOf<Self> {
Scope(state: \.appFeature, action: /Action.appFeature) {
AppFeature()
}
Reduce { state, action in
switch action {
case .appFeature(.delegate(_)):
state.path.append(.secondFeature(.init()))
return .none
case .path(.element(id: _, action: .secondFeature(.delegate(_)))):
_ = state.path.popLast()
return .none
case .appFeature:
return .none
case .path:
return .none
}
}
.forEach(\.path, action: /Action.path) {
Path()
}
}
}
struct AppRoot: View {
let store: StoreOf<AppRootFeature>
var body: some View {
NavigationStackStore(store.scope(state: \.path, action: { .path($0) })) {
ContentView(store: self.store.scope(state: \.appFeature, action: { .appFeature($0) }))
} destination: { state in
switch state {
case .secondFeature:
CaseLet(/AppRootFeature.Path.State.secondFeature, action: AppRootFeature.Path.Action.secondFeature) { store in
SecondScreen(store: store)
}
}
}
}
}
struct AppFeature: Reducer {
enum Action: Equatable {
case navigateButtonTapped
case delegate(Delegate)
enum Delegate: Equatable {
case navigate
}
}
struct State: Equatable {}
var body: some ReducerOf<Self> {
Reduce { _, action in
switch action {
case .delegate:
return .none
case .navigateButtonTapped:
return .send(.delegate(.navigate))
}
}
}
}
struct ContentView: View {
let store: StoreOf<AppFeature>
var body: some View {
WithViewStore(store, observe: { $0 }) { vs in
VStack {
Text("First")
Button(action: {
vs.send(.navigateButtonTapped)
}, label: {
Text("Navigate")
})
}
}
}
}
struct SecondFeature: Reducer {
struct State: Equatable {}
enum Action: Equatable {
case dismissButtonTapped
case delegate(Delegate)
enum Delegate: Equatable {
case dismiss
}
}
var body: some ReducerOf<Self> {
Reduce { _, action in
switch action {
case .delegate:
return .none
case .dismissButtonTapped:
return .send(.delegate(.dismiss), animation: .default)
}
}
}
}
struct SecondScreen: View {
let store: StoreOf<SecondFeature>
var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
ZStack {
Color.red
VStack {
Text("Second")
Button(action: {
viewStore.send(.dismissButtonTapped)
}, label: {
Text("Dismiss")
})
}
}
}
}
} Simulator.Screen.Recording.-.iPhone.15.Plus.-.2023-10-31.at.16.39.49.mp4 |
Beta Was this translation helpful? Give feedback.
Answered by
mbrandonw
Oct 31, 2023
Replies: 1 comment
-
Hi @Tabonx, this is a bug in vanilla SwiftUI, and don't think there's much we can do about it. Here's a feedback we filed about it, and we recommend you do the same. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Tabonx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @Tabonx, this is a bug in vanilla SwiftUI, and don't think there's much we can do about it. Here's a feedback we filed about it, and we recommend you do the same.