-
Notifications
You must be signed in to change notification settings - Fork 0
[#193] iOS 17에서 PushNotificationListView의 내비게이션바가 inline이 안되는 현상을 해결한다 #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a931e62
ui: 볼드체 제거
opficdev 8a6a176
fix: iOS 17에서 navigationbar가 투명으로 나타나는 현상 해결
opficdev 128d476
style: 불필요 뷰 모디파이어 제거
opficdev 9920eab
style: 코드 정리
opficdev dc5b94c
fix: 스크롤 트래킹이 안되는 현상 해결
opficdev 73ff725
fix: iOS 17에서는 스크롤뷰를 제거하여 해결
opficdev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,73 +18,23 @@ struct PushNotificationListView: View { | |
|
|
||
| var body: some View { | ||
| NavigationStack(path: $router.path) { | ||
| List { | ||
| Group { | ||
| if viewModel.state.notifications.isEmpty { | ||
| HStack { | ||
| Spacer() | ||
| Text("받은 알림이 없습니다.") | ||
| .foregroundStyle(Color.gray) | ||
| Spacer() | ||
| } | ||
| .listRowSeparator(.hidden) | ||
| } else { | ||
| let notifications = viewModel.state.notifications | ||
| ForEach(Array(zip(notifications.indices, notifications)), id: \.1.id) { idx, notification in | ||
| Button { | ||
| viewModel.send(.tapNotification(notification)) | ||
| } label: { | ||
| notificationRow(notification) | ||
| .padding(.vertical, 8) | ||
| } | ||
| .buttonStyle(.plain) | ||
| .onAppear { | ||
| let lastID = viewModel.state.notifications.last?.id | ||
| if notification.id == lastID, viewModel.state.hasMore { | ||
| viewModel.send(.loadNextPage) | ||
| } | ||
| } | ||
| .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) | ||
| .overlay(alignment: .top) { | ||
| if #available(iOS 26.0, *) { | ||
| if idx == 0 { | ||
| Divider() | ||
| .padding(.horizontal, -16) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| .listSectionSeparator(.hidden, edges: .top) | ||
| .listRowBackground(Color.clear) | ||
| } | ||
| notificationList | ||
| .listStyle(.plain) | ||
| .background(NavigationBarConfigurator(.secondarySystemBackground)) | ||
| .background(NavigationBarConfigurator(.secondarySystemBackground, alwaysVisible: true)) | ||
| .onScrollOffsetChange { offset in | ||
| guard isScrollTrackingEnabled else { return } | ||
| headerOffset = max(0, -offset) | ||
| } | ||
| .safeAreaInset(edge: .top) { | ||
| VStack(spacing: 4) { | ||
| headerView | ||
| .clipped() | ||
| if #unavailable(iOS 26) { | ||
| Divider() | ||
| .padding(.horizontal, -16) | ||
| } | ||
| } | ||
| .background { | ||
| if #available(iOS 26.0, *) { | ||
| Color.clear | ||
| } else { | ||
| Color(.secondarySystemBackground) | ||
| } | ||
| .safeAreaInset(edge: .top) { safeAreaHeader } | ||
| .background(Color(.secondarySystemBackground)) | ||
| .onAppear { | ||
| viewModel.send(.fetchNotifications) | ||
| headerOffset = 0 | ||
| isScrollTrackingEnabled = false | ||
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { | ||
| isScrollTrackingEnabled = true | ||
| } | ||
| .offset(y: headerOffset) | ||
| } | ||
| .background(Color(.secondarySystemBackground)) | ||
| .onAppear { viewModel.send(.fetchNotifications) } | ||
| .refreshable { viewModel.send(.fetchNotifications) } | ||
| .navigationTitle("받은 푸시 알람") | ||
| .alert( | ||
|
|
@@ -138,77 +88,143 @@ struct PushNotificationListView: View { | |
| } | ||
| } | ||
|
|
||
| private var headerView: some View { | ||
| ScrollView(.horizontal) { | ||
| HStack(spacing: 8) { | ||
| if 0 < viewModel.appliedFilterCount { | ||
| Menu { | ||
| Text("\(viewModel.appliedFilterCount)개 필터가 적용됨") | ||
| Button(role: .destructive) { | ||
| viewModel.send(.resetFilters) | ||
| private var notificationList: some View { | ||
| List { | ||
| Group { | ||
| if viewModel.state.notifications.isEmpty { | ||
| HStack { | ||
| Spacer() | ||
| Text("받은 알림이 없습니다.") | ||
| .foregroundStyle(Color.gray) | ||
| Spacer() | ||
| } | ||
| .listRowSeparator(.hidden) | ||
| } else { | ||
| let notifications = viewModel.state.notifications | ||
| ForEach(Array(zip(notifications.indices, notifications)), id: \.1.id) { idx, notification in | ||
| Button { | ||
| viewModel.send(.tapNotification(notification)) | ||
| } label: { | ||
| Text("모든 필터 지우기") | ||
| notificationRow(notification) | ||
| .padding(.vertical, 8) | ||
| } | ||
| } label: { | ||
| HStack(spacing: 6) { | ||
| Image(systemName: "line.3.horizontal.decrease") | ||
| filterBadge | ||
| .buttonStyle(.plain) | ||
| .onAppear { | ||
| let lastID = viewModel.state.notifications.last?.id | ||
| if notification.id == lastID, viewModel.state.hasMore { | ||
| viewModel.send(.loadNextPage) | ||
| } | ||
| } | ||
| .listRowInsets(EdgeInsets(top: 0, leading: 16, bottom: 0, trailing: 16)) | ||
| .overlay(alignment: .top) { | ||
| if #available(iOS 26.0, *) { | ||
| if idx == 0 { | ||
| Divider() | ||
| .padding(.horizontal, -16) | ||
| } | ||
| } | ||
| } | ||
| .adaptiveButtonStyle() | ||
| } | ||
| } | ||
| } | ||
| .listSectionSeparator(.hidden, edges: .top) | ||
| .listRowBackground(Color.clear) | ||
| } | ||
| } | ||
|
|
||
| Button { | ||
| viewModel.send(.toggleSortOption) | ||
| } label: { | ||
| let condition = viewModel.state.query.sortOrder == .oldest | ||
| Text("정렬: \(viewModel.state.query.sortOrder.title)") | ||
| .foregroundStyle(condition ? .white : Color(.label)) | ||
| .adaptiveButtonStyle(color: condition ? .blue : .clear) | ||
| } | ||
| private var safeAreaHeader: some View { | ||
| VStack(spacing: 4) { | ||
| headerView | ||
| .clipped() | ||
| if #unavailable(iOS 26) { | ||
| Divider() | ||
| .padding(.horizontal, -16) | ||
| } | ||
| } | ||
| .background { | ||
| if #available(iOS 26.0, *) { | ||
| Color.clear | ||
| } else { | ||
| Color(.secondarySystemBackground) | ||
| } | ||
| } | ||
| .offset(y: headerOffset) | ||
| } | ||
|
|
||
| private var headerView: some View { | ||
| Group { | ||
| if #available(iOS 18, *) { | ||
| ScrollView(.horizontal) { headerContent } | ||
| .scrollIndicators(.never) | ||
| .scrollDisabled(!isScrollTrackingEnabled) | ||
| .contentMargins(.leading, 16, for: .scrollContent) | ||
| } else { | ||
| headerContent | ||
| .padding(.leading, 16) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
|
Comment on lines
+162
to
+164
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS 18 미만 버전에서 ScrollView(.horizontal) {
headerContent
.padding(.leading, 16)
}
.scrollIndicators(.never)
.scrollDisabled(!isScrollTrackingEnabled) |
||
| } | ||
| } | ||
| } | ||
|
|
||
| private var headerContent: some View { | ||
| HStack(spacing: 8) { | ||
| if 0 < viewModel.appliedFilterCount { | ||
| Menu { | ||
| Picker(selection: Binding( | ||
| get: { viewModel.state.query.timeFilter }, | ||
| set: { viewModel.send(.setTimeFilter($0)) } | ||
| )) { | ||
| ForEach(PushNotificationQuery.TimeFilter.availableOptions, id: \.self) { option in | ||
| Text(option.title).tag(option) | ||
| } | ||
| Text("\(viewModel.appliedFilterCount)개 필터가 적용됨") | ||
| Button(role: .destructive) { | ||
| viewModel.send(.resetFilters) | ||
| } label: { | ||
| Text("기간") | ||
| Text("모든 필터 지우기") | ||
| } | ||
| } label: { | ||
| let condition = viewModel.state.query.timeFilter == .none | ||
| HStack { | ||
| Text("기간") | ||
| Image(systemName: "chevron.down") | ||
| HStack(spacing: 6) { | ||
| Image(systemName: "line.3.horizontal.decrease") | ||
| filterBadge | ||
| } | ||
| .foregroundStyle(condition ? Color(.label) : .white) | ||
| .adaptiveButtonStyle(color: condition ? .clear : .blue) | ||
| .adaptiveButtonStyle() | ||
| } | ||
| } | ||
|
|
||
| Button { | ||
| viewModel.send(.toggleUnreadOnly) | ||
| Button { | ||
| viewModel.send(.toggleSortOption) | ||
| } label: { | ||
| let condition = viewModel.state.query.sortOrder == .oldest | ||
| Text("정렬: \(viewModel.state.query.sortOrder.title)") | ||
| .foregroundStyle(condition ? .white : Color(.label)) | ||
| .adaptiveButtonStyle(color: condition ? .blue : .clear) | ||
| } | ||
|
|
||
| Menu { | ||
| Picker(selection: Binding( | ||
| get: { viewModel.state.query.timeFilter }, | ||
| set: { viewModel.send(.setTimeFilter($0)) } | ||
| )) { | ||
| ForEach(PushNotificationQuery.TimeFilter.availableOptions, id: \.self) { option in | ||
| Text(option.title).tag(option) | ||
| } | ||
| } label: { | ||
| let condition = viewModel.state.query.unreadOnly | ||
| Text("읽지 않음") | ||
| .foregroundStyle(condition ? .white : Color(.label)) | ||
| .adaptiveButtonStyle(color: condition ? .blue : .clear) | ||
| Text("기간") | ||
| } | ||
| } label: { | ||
| let condition = viewModel.state.query.timeFilter == .none | ||
| HStack { | ||
| Text("기간") | ||
| Image(systemName: "chevron.down") | ||
| } | ||
| .foregroundStyle(condition ? Color(.label) : .white) | ||
| .adaptiveButtonStyle(color: condition ? .clear : .blue) | ||
| } | ||
| .frame(height: 36) | ||
| } | ||
| .scrollIndicators(.never) | ||
| .scrollDisabled(!isScrollTrackingEnabled) | ||
| .contentMargins(.leading, 16, for: .scrollContent) | ||
| .onAppear { | ||
| headerOffset = 0 | ||
| isScrollTrackingEnabled = false | ||
| DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) { | ||
| isScrollTrackingEnabled = true | ||
|
|
||
| Button { | ||
| viewModel.send(.toggleUnreadOnly) | ||
| } label: { | ||
| let condition = viewModel.state.query.unreadOnly | ||
| Text("읽지 않음") | ||
| .foregroundStyle(condition ? .white : Color(.label)) | ||
| .adaptiveButtonStyle(color: condition ? .blue : .clear) | ||
| } | ||
| } | ||
| .frame(height: 36) | ||
| } | ||
|
|
||
| private var filterBadge: some View { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0.3초 지연은 뷰가 나타날 때 초기 스크롤 위치가 잘못 계산되는 것을 막기 위한 것으로 보입니다. 이는 SwiftUI에서 종종 사용되는 해결책이지만, 특정 기기나 상황에서는 여전히 문제가 발생할 수 있습니다. 왜 이 지연이 필요한지에 대한 주석을 추가하여 코드의 의도를 명확히 하고, 향후 다른 개발자가 이 코드를 이해하는 데 도움을 주는 것이 좋겠습니다. 예를 들어,// 뷰 초기화 시 발생하는 불필요한 스크롤 이벤트 방지와 같은 주석을 추가할 수 있습니다.