-
[SwiftUI] NavigationLink pop push 깜빡이는 문제개발/Swift 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 }
'개발 > Swift' 카테고리의 다른 글
UIKit SwiftUI에서 자동 스크롤 (0) 2025.04.08 WKWebview 에서 post 요청하는방법 (0) 2025.04.08 SwiftUI 커스텀 팝업 노출 방법 fullScreenCover (0) 2025.03.25 TCA binding 액션 내부 타입 바인딩 @CasePathable (0) 2025.03.25 [Swift] 페이지처럼 넘어가는 스크롤 레이아웃 (Carousel Effect) (0) 2025.02.26