Skip to content
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

Fix Toolbar spacing #311

Merged
merged 4 commits into from
Sep 8, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 48 additions & 40 deletions SNUTT-2022/SNUTT/Views/Scenes/TimetableScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct TimetableScene: View, Sendable {
@State private var pushToListScene = false
@State private var isShareSheetOpened = false
@State private var screenshot: UIImage = .init()
@State private var screenSize: CGSize = .zero
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 없앨 방법이 없을까?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간표 이미지를 full-screen 사이즈로 만들게 아니라서 변수를 따로 둬야하긴해

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

그건 아는데 geometry reader의 위치를 바꾸든지 해서 직접 읽어오게 하면 좋을듯

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customToolBar height를 그냥 상수로 두게 바꿨어 커밋올림~!

@ObservedObject var viewModel: TimetableViewModel

/// Provide title for `UIActivityViewController`.
Expand All @@ -22,6 +23,7 @@ struct TimetableScene: View, Sendable {

var body: some View {
VStack(spacing: 0) {
customToolBar
if viewModel.isVacancyBannerVisible {
VacancyBanner {
viewModel.goToVacancyPage()
Expand All @@ -34,6 +36,46 @@ struct TimetableScene: View, Sendable {
let _ = debugChanges()
}

var customToolBar: some View {
HStack(spacing: 0) {
HStack {
NavBarButton(imageName: "nav.menu") {
peng-u-0807 marked this conversation as resolved.
Show resolved Hide resolved
viewModel.setIsMenuOpen(true)
}
.circleBadge(condition: viewModel.isNewCourseBookAvailable)

Text(viewModel.timetableTitle)
.font(STFont.title.font)
.minimumScaleFactor(0.9)
.lineLimit(1)

Text("(\(viewModel.totalCredit)학점)")
.font(STFont.details.font)
.foregroundColor(Color(UIColor.secondaryLabel))
}

Spacer()

HStack {
NavBarButton(imageName: "nav.list") {
pushToListScene = true
}

NavBarButton(imageName: "nav.share") {
screenshot = self.timetable.takeScreenshot(size: screenSize, preferredColorScheme: colorScheme)
isShareSheetOpened = true
}

NavBarButton(imageName: "nav.alarm.off") {
viewModel.routingState.pushToNotification = true
}
.circleBadge(condition: viewModel.unreadCount > 0)
}
}
.frame(height: 44)
.padding(.horizontal, 16)
}

var timetable: some View {
GeometryReader { reader in
TimetableZStack(current: viewModel.currentTimetable, config: viewModel.configuration)
Expand All @@ -42,53 +84,19 @@ struct TimetableScene: View, Sendable {
.background(
Group {
NavigationLink(destination: LectureListScene(viewModel: .init(container: viewModel.container)), isActive: $pushToListScene) { EmptyView() }

NavigationLink(destination: NotificationList(viewModel: .init(container: viewModel.container)),
isActive: $viewModel.routingState.pushToNotification) { EmptyView() }
}
)
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItemGroup(placement: .topBarLeading) {
HStack {
NavBarButton(imageName: "nav.menu") {
viewModel.setIsMenuOpen(true)
}
.circleBadge(condition: viewModel.isNewCourseBookAvailable)

Text(viewModel.timetableTitle)
.font(STFont.title.font)
.minimumScaleFactor(0.9)
.lineLimit(1)

Text("(\(viewModel.totalCredit)학점)")
.font(STFont.details.font)
.foregroundColor(Color(UIColor.secondaryLabel))
}
}
ToolbarItemGroup(placement: .topBarTrailing) {
HStack {
NavBarButton(imageName: "nav.list") {
pushToListScene = true
}

NavBarButton(imageName: "nav.share") {
screenshot = self.timetable.takeScreenshot(size: reader.size, preferredColorScheme: colorScheme)
isShareSheetOpened = true
}

NavBarButton(imageName: "nav.alarm.off") {
viewModel.routingState.pushToNotification = true
}
.circleBadge(condition: viewModel.unreadCount > 0)
}
}
.onAppear {
screenSize = reader.size
}
.navigationBarTitleDisplayMode(.inline)
.sheet(isPresented: $isShareSheetOpened) { [screenshot] in
ActivityViewController(activityItems: [screenshot, linkMetadata])
}
}
.background {
NavigationLink(destination: NotificationList(viewModel: .init(container: viewModel.container)),
isActive: $viewModel.routingState.pushToNotification) { EmptyView() }
}
}
}

Expand Down