Skip to content

Commit

Permalink
feat: add AlimoBottomTabBar
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyoonchae committed Aug 1, 2024
1 parent ae1f2d1 commit cb68bc4
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 114 deletions.
107 changes: 55 additions & 52 deletions Projects/App/Sources/UI/Feature/Main/Bookmark/BookmarkView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SwiftUI
import ADS

struct BookmarkView: View {

Expand All @@ -25,66 +26,68 @@ struct BookmarkView: View {
var hasPost: Bool = true

var body: some View {
GeometryReader { geo in
ScrollView(showsIndicators: false) {
VStack(spacing: 0) {
AlimoLogoBar()
switch vm.flow {
case .fetching:
LazyVStack(spacing: 0) {
ForEach(0..<4, id: \.self) { _ in
NotificationCellShimmer()
}
}
.shimmer()
case .success:
LazyVStack(spacing: 0) {
ForEach(Array(vm.notificationList.enumerated()), id: \.element.uuidString) { index, notification in
VStack(spacing: 0) {
BookMarkCeil(notification: notification, onClickEmoji: {emoji in
Task{
await vm.patchEmoji(emoji:emoji,notificationId:notification.notificationId)
}
}, onClickBookmark: {
Task{
await vm.patchBookmark(notificationId:notification.notificationId)
}
}, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel(),bookMarkVm: BookmarkViewModel(),
callCount: index)
// NotificationCeil(notification: notification, onClickEmoji: { emoji in
// Task {
// await vm.patchEmoji(emoji: emoji, notificationId: notification.notificationId)
// }
// }, onClickBookmark: {
// Task {
// await vm.patchBookmark(notificationId: notification.notificationId)
// }
// }, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel())

ZStack{
GeometryReader { geo in
ScrollView(showsIndicators: false) {
VStack(spacing: 0) {
AlimoLogoBar()
switch vm.flow {
case .fetching:
LazyVStack(spacing: 0) {
ForEach(0..<4, id: \.self) { _ in
NotificationCellShimmer()
}
.onAppear {
guard let index = vm.notificationList.firstIndex(where: { $0.notificationId == notification.notificationId }) else { return }

if index % pagingInterval == (pagingInterval - 1) && index / pagingInterval == (vm.notificationList.count - 1) / pagingInterval {
Task {
await vm.fetchNotifications(isNew: false)
}
.shimmer()
case .success:
LazyVStack(spacing: 0) {
ForEach(Array(vm.notificationList.enumerated()), id: \.element.uuidString) { index, notification in
VStack(spacing: 0) {
BookMarkCeil(notification: notification, onClickEmoji: {emoji in
Task{
await vm.patchEmoji(emoji:emoji,notificationId:notification.notificationId)
}
}, onClickBookmark: {
Task{
await vm.patchBookmark(notificationId:notification.notificationId)
}
}, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel(),bookMarkVm: BookmarkViewModel(),
callCount: index)
// NotificationCeil(notification: notification, onClickEmoji: { emoji in
// Task {
// await vm.patchEmoji(emoji: emoji, notificationId: notification.notificationId)
// }
// }, onClickBookmark: {
// Task {
// await vm.patchBookmark(notificationId: notification.notificationId)
// }
// }, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel())

}
.onAppear {
guard let index = vm.notificationList.firstIndex(where: { $0.notificationId == notification.notificationId }) else { return }

if index % pagingInterval == (pagingInterval - 1) && index / pagingInterval == (vm.notificationList.count - 1) / pagingInterval {
Task {
await vm.fetchNotifications(isNew: false)
}
}
}
}
}
.padding(.bottom, 100)
case .failure:
Image(.noNotice)
.padding(.top, 115)
Text("북마크를 불러올 수 없어요")
.font(.subtitle)
.foregroundStyle(Color.gray500)
.padding(.top, 32)

}
.padding(.bottom, 100)
case .failure:
Image(.noNotice)
.padding(.top, 115)
Text("북마크를 불러올 수 없어요")
.font(.subtitle)
.foregroundStyle(Color.gray500)
.padding(.top, 32)

}
}

.alimoBackground(AlimoColor.Background.normal)
.background(
GeometryReader {
Color.clear.preference(key: ViewOffsetKey.self,
Expand Down
102 changes: 53 additions & 49 deletions Projects/App/Sources/UI/Feature/Main/Home/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Foundation
import SwiftUI
import ADS

struct HomeView: View {

Expand Down Expand Up @@ -48,70 +49,73 @@ struct HomeView: View {
.padding(.horizontal, 16)
.padding(.vertical, 12)
.frame(maxWidth: .infinity)
.background(Color.white)
.alimoBackground(AlimoColor.Background.normal)
.clipShape(RoundedCorner(radius: 8, corners: [.bottomLeft, .bottomRight]))
.showShadow(show: isSelectorReached)
}

var body: some View {
ScrollViewReader { reader in
ScrollView(showsIndicators: false) {
VStack(spacing: 0) {
AlimoLogoBar()
.id("top")
if let loudSpeaker = vm.loudSpeaker {
Notice(vm: NotificationDetailViewModel(notificationId: loudSpeaker.notificationId),homeVm: HomeViewModel(), notificationspeaketitle: Text(loudSpeaker.title), memberID: Text(loudSpeaker.name), notificationId: loudSpeaker.notificationId)
}

LazyVStack(spacing: 0, pinnedViews: [.sectionHeaders]) {
Section(header: categorySelector) {
switch vm.flow {
case .fetching:
LazyVStack(spacing: 0) {
ForEach(0..<4, id: \.self) { _ in
NotificationCellShimmer()
ZStack{
ScrollViewReader { reader in
ScrollView(showsIndicators: false) {
VStack(spacing: 0) {
AlimoLogoBar()
.id("top")
if let loudSpeaker = vm.loudSpeaker {
Notice(vm: NotificationDetailViewModel(notificationId: loudSpeaker.notificationId),homeVm: HomeViewModel(), notificationspeaketitle: Text(loudSpeaker.title), memberID: Text(loudSpeaker.name), notificationId: loudSpeaker.notificationId)
}

LazyVStack(spacing: 0, pinnedViews: [.sectionHeaders]) {
Section(header: categorySelector) {
switch vm.flow {
case .fetching:
LazyVStack(spacing: 0) {
ForEach(0..<4, id: \.self) { _ in
NotificationCellShimmer()
}
}
}
case .success:
LazyVStack(spacing: 0) {
ForEach(vm.notificationList, id: \.uuidString) { notification in
VStack(spacing: 0) {
NotificationCeil(notification: notification, onClickEmoji: { emoji in
Task {
await vm.patchEmoji(emoji: emoji, notificationId: notification.notificationId)
}
}, onClickBookmark: {
Task {
await vm.patchBookmark(notificationId: notification.notificationId)
case .success:
LazyVStack(spacing: 0) {
ForEach(vm.notificationList, id: \.uuidString) { notification in
VStack(spacing: 0) {
NotificationCeil(notification: notification, onClickEmoji: { emoji in
Task {
await vm.patchEmoji(emoji: emoji, notificationId: notification.notificationId)
}
}, onClickBookmark: {
Task {
await vm.patchBookmark(notificationId: notification.notificationId)
}
}, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel())

Divider()
.foregroundStyle(Color.gray100)
}
.task {
guard let index = vm.notificationList.firstIndex(where: { $0.notificationId == notification.notificationId }) else { return }

if index % pagingInterval == (pagingInterval - 1) && index / pagingInterval == (vm.notificationList.count - 1) / pagingInterval {
await vm.fetchNotifications(isNew: false)
}
}, vm: NotificationDetailViewModel(notificationId: notification.notificationId), homeVm: HomeViewModel())

Divider()
.foregroundStyle(Color.gray100)
}
.task {
guard let index = vm.notificationList.firstIndex(where: { $0.notificationId == notification.notificationId }) else { return }

if index % pagingInterval == (pagingInterval - 1) && index / pagingInterval == (vm.notificationList.count - 1) / pagingInterval {
await vm.fetchNotifications(isNew: false)
}
}
}
.lineLimit(3)
.padding(.bottom, 100)
case .failure:
Image(.noNotice)
.padding(.top, 115)
Text("공지를 불러올 수 없어요")
.font(.subtitle)
.foregroundStyle(Color.gray500)
.padding(.top, 32)
}
.lineLimit(3)
.padding(.bottom, 100)
case .failure:
Image(.noNotice)
.padding(.top, 115)
Text("공지를 불러올 수 없어요")
.font(.subtitle)
.foregroundStyle(Color.gray500)
.padding(.top, 32)
}
}
.shimmer(vm.flow == .fetching)
}
.shimmer(vm.flow == .fetching)
}
.alimoBackground(AlimoColor.Background.normal)
.background(
GeometryReader {
Color.clear.preference(key: ViewOffsetKey.self,
Expand Down
35 changes: 22 additions & 13 deletions Projects/App/Sources/UI/Feature/Main/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

import Foundation
import SwiftUI
import ADS

struct MainView: View {

@State private var selectedTab = BottomNavigationType.home
@State private var selectedTab = BottomTabType.Home
@StateObject private var profileVM = ProfileViewModel()
@StateObject private var homeVM = HomeViewModel()
@StateObject private var bookmarkVM = BookmarkViewModel()
Expand All @@ -22,20 +23,22 @@ struct MainView: View {
NavigationStack {
ZStack {
switch selectedTab {
case .home: HomeView(vm: homeVM)
case .bookmark: BookmarkView(vm: bookmarkVM)
case .my: ProfileView(vm: profileVM)
case .Home:
HomeView(vm: homeVM)
case .Bookmark:
BookmarkView(vm: bookmarkVM)
case .Profile:
ProfileView(vm: profileVM)
}

GeometryReader { reader in
ZStack(alignment: .bottom) {
BottomNavigation(selectedTab: $selectedTab)
VStack {
Color.white
.frame(height: reader.safeAreaInsets.top, alignment: .top)
Spacer()
Color.white
.frame(height: reader.safeAreaInsets.bottom, alignment: .bottom)
AlimoBottomTabBar(selectedTab: selectedTab, onTap: { newTab in
selectedTab = newTab
}) {
EmptyView()
}
.padding(.bottom, reader.safeAreaInsets.bottom)
.ignoresSafeArea()
}
}
Expand All @@ -45,12 +48,18 @@ struct MainView: View {
endTextEditing()
appState.fetchMember()
}
.onChange(of: appState.refreshFailure) {
if $0 {
.onChange(of: appState.refreshFailure) { newValue in
if newValue {
tm.accessToken = ""
tm.refreshToken = ""
appState.refreshFailure = false
}
}
}
}

#Preview {
MainView()
.environmentObject(AppState())
.environmentObject(TokenManager())
}

0 comments on commit cb68bc4

Please sign in to comment.