개발/Swift
[SwiftUI] NavigationLink pop push 깜빡이는 문제
덤벨로퍼
2025. 4. 8. 09:31
상황
case let .reportAction(action):
switch action {
case .report(.dismiss):
state.report = nil
case let .report(.presented(action)):
switch action {
case let .reportSuccess(contentType, id):
state.report = nil
return .concatenate(
.send(.removeAllComments),
fetchCommentsEffect(boardId: state.boardId, postId: state.postId, nextPageToken: nil),
.send(.reportAction(.disableReport(contentType: contentType, id: id))),
.send(.reportAction(.showReport(false))),
.send(.reportAction(.showReportSuccess(true))),
)
default:
return .none
}
성공시 부모뷰에서 다음 로직을 수행함
- 댓글 리스트 refresh
- 현재 페이지 안보이게 ( 현재 페이지 NavitagionLink 로 Push된 상태)
- 다음 페이지 보이게 ( 다음페이지 NavitagionLink 로 Push 해야 함)
- 현재 페이지 상태 제거
원인
NavigationLink(
destination:
IfLetStore(
store.scope(state: \\.$report, action: \\.reportAction.report)
) { CommunityReportView(store: $0) },
isActive: $store.showReport.sending(\\.reportAction.showReport),
label: {EmptyView()})
- 현재 페이지 상태제거 되면서 현재 페이지가 EmptyView로 바뀌며 네비게이션이 노출됨
- 그러고 0.1 초 후 실제 네비게이션이 돌아서 정상 노출
해결
해결은 isActive 바인딩으로 페이지를 끄지않고 (showReport 상태와 액션)
dismiss 액션으로 끄는 방법을 쓰면 됨
case let .reportAction(action):
switch action {
case .report(.dismiss): // 여기서 상태 제거됨
state.report = nil
case let .report(.presented(action)):
switch action {
case let .reportSuccess(contentType, id):
///state.report = nil 제거
return .concatenate(
.send(.removeAllComments),
fetchCommentsEffect(boardId: state.boardId, postId: state.postId, nextPageToken: nil),
.send(.reportAction(.disableReport(contentType: contentType, id: id))),
.send(.reportAction(.report(.dismiss))), // 이거로 끔
.send(.reportAction(.showReportSuccess(true)))
)
default:
return .none
}