Skip to content

Commit

Permalink
Merge pull request #140 from DeveloperAcademy-POSTECH/feat/132-loadin…
Browse files Browse the repository at this point in the history
…g-view

[#132] 맵뷰로 넘어가기 전에 로딩 화면 제공
  • Loading branch information
dbqls200 authored Dec 4, 2024
2 parents ed5890a + 46419bd commit 74843e7
Show file tree
Hide file tree
Showing 17 changed files with 225 additions and 28 deletions.
32 changes: 32 additions & 0 deletions TMT/TMT.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
D8A1C0972CFA1B5C007D9F3F /* CaptureDark.json in Resources */ = {isa = PBXBuildFile; fileRef = D8A1C0932CFA1B5C007D9F3F /* CaptureDark.json */; };
D8A1C0982CFA1B5C007D9F3F /* IntroFinishDark.json in Resources */ = {isa = PBXBuildFile; fileRef = D8A1C0952CFA1B5C007D9F3F /* IntroFinishDark.json */; };
D8A1C0992CFA1B5C007D9F3F /* BusDotIntroDark.json in Resources */ = {isa = PBXBuildFile; fileRef = D8A1C0922CFA1B5C007D9F3F /* BusDotIntroDark.json */; };
D8C5E7322D006D31005FE865 /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C5E7312D006D31005FE865 /* LoadingView.swift */; };
D8C5E7362D006D53005FE865 /* LoadingCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8C5E7352D006D53005FE865 /* LoadingCase.swift */; };
D8D377E92CBE95C30043D103 /* BusSearchItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D377E82CBE95C30043D103 /* BusSearchItem.swift */; };
D8D377EB2CBE95CA0043D103 /* BusSearchModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8D377EA2CBE95CA0043D103 /* BusSearchModel.swift */; };
D8E054DD2CF1AF89006B1879 /* View.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8E054DC2CF1AF89006B1879 /* View.swift */; };
Expand Down Expand Up @@ -167,6 +169,8 @@
D8A1C0932CFA1B5C007D9F3F /* CaptureDark.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = CaptureDark.json; sourceTree = "<group>"; };
D8A1C0942CFA1B5C007D9F3F /* GoNaverMapDark.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = GoNaverMapDark.json; sourceTree = "<group>"; };
D8A1C0952CFA1B5C007D9F3F /* IntroFinishDark.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = IntroFinishDark.json; sourceTree = "<group>"; };
D8C5E7312D006D31005FE865 /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
D8C5E7352D006D53005FE865 /* LoadingCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingCase.swift; sourceTree = "<group>"; };
D8D377E82CBE95C30043D103 /* BusSearchItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BusSearchItem.swift; sourceTree = "<group>"; };
D8D377EA2CBE95CA0043D103 /* BusSearchModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BusSearchModel.swift; sourceTree = "<group>"; };
D8E054DC2CF1AF89006B1879 /* View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = View.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -428,6 +432,7 @@
D8D377E72CBE95B80043D103 /* BusSearch */,
5B2D9A0E2CCA14FB001FF6CC /* BusJourneyScanned */,
5BCE456F2CC389FE00CF38CE /* Map */,
D8C5E7302D006D22005FE865 /* Loading */,
D844BCD82CC1472E0059E31F /* Utils */,
D826488D2CD3553B000A448D /* UIComponent */,
D81D9E982CE47F02004F2024 /* Extension */,
Expand Down Expand Up @@ -496,6 +501,31 @@
path = DarkMode;
sourceTree = "<group>";
};
D8C5E7302D006D22005FE865 /* Loading */ = {
isa = PBXGroup;
children = (
D8C5E7332D006D35005FE865 /* Models */,
D8C5E7342D006D3C005FE865 /* Views */,
);
path = Loading;
sourceTree = "<group>";
};
D8C5E7332D006D35005FE865 /* Models */ = {
isa = PBXGroup;
children = (
D8C5E7352D006D53005FE865 /* LoadingCase.swift */,
);
path = Models;
sourceTree = "<group>";
};
D8C5E7342D006D3C005FE865 /* Views */ = {
isa = PBXGroup;
children = (
D8C5E7312D006D31005FE865 /* LoadingView.swift */,
);
path = Views;
sourceTree = "<group>";
};
D8D377E42CBE548F0043D103 /* Resource */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -700,6 +730,7 @@
5B85B1C22CD91CC000469D03 /* HomeView.swift in Sources */,
5B0C4AF42CD52E1800031147 /* StopStatusEnum.swift in Sources */,
5B347FCE2CF49DEA00A1E852 /* BusStopArrivalView.swift in Sources */,
D8C5E7362D006D53005FE865 /* LoadingCase.swift in Sources */,
5B347FD02CF4F72400A1E852 /* AppDelegate.swift in Sources */,
5B6DA5B82CBE551400613ACB /* MapView.swift in Sources */,
5B6DA5BA2CBE6F8C00613ACB /* LocationManager.swift in Sources */,
Expand All @@ -713,6 +744,7 @@
5BE1BF082CF867590082648D /* NotificationManager.swift in Sources */,
D801A1BA2CF2213C00AD0D64 /* BusDataMock.swift in Sources */,
D876BF312CECE89E0098B68E /* OnboardingView.swift in Sources */,
D8C5E7322D006D31005FE865 /* LoadingView.swift in Sources */,
5B64AF952CCF823D0083CA23 /* BusInfoEnum.swift in Sources */,
D82CB2342CFE103800A93217 /* UIApplication.swift in Sources */,
5BA06D4A2CF38E5400834BBD /* TappedStopView.swift in Sources */,
Expand Down
6 changes: 6 additions & 0 deletions TMT/TMT/Assets.xcassets/Image/Loading/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "loading2_1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "loading2_2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "loading2_3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "loading1_1x.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "loading1_2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "loading1_3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 34 additions & 24 deletions TMT/TMT/BusJourneyScanned/Views/ScannedJourneyInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ struct ScannedJourneyInfoView: View {
@EnvironmentObject var searchModel: BusSearchModel
@EnvironmentObject var journeyModel: JourneySettingModel
@EnvironmentObject var activityManager: LiveActivityManager

@State private var tag: Int? = nil

@State private var showingAlert: Bool = false
@State private var showingPhotosPicker: Bool = false
@State private var isShowingInformation = false
@State private var isLoading = false

@State private var showingPhotosPicker: Bool = false
@State private var pickedItem: PhotosPickerItem? = nil

@Binding var path: [String]

var body: some View {
ZStack {
Color.brandBackground
Expand All @@ -34,14 +37,14 @@ struct ScannedJourneyInfoView: View {
} else {
UploadedPhotoView(selectedImage: .constant(nil))
}

VStack(alignment: .leading) {
uploadedInfoBox(title: "Bus Number", scannedInfo: $imageHandler.scannedJourneyInfo.busNumber)
uploadedInfoBox(title: "Departure Stop", scannedInfo: $imageHandler.scannedJourneyInfo.startStop)
uploadedInfoBox(title: "Arrival Stop", scannedInfo: $imageHandler.scannedJourneyInfo.endStop)
}
}

if imageHandler.showAlertText {
HStack {
VStack {
Expand All @@ -59,7 +62,7 @@ struct ScannedJourneyInfoView: View {
.frame(height: 42)
.foregroundStyle(.red600)
}

HStack(spacing: 0) {
Group {
if imageHandler.showAlertText {
Expand All @@ -84,7 +87,7 @@ struct ScannedJourneyInfoView: View {
Text("Cancel")
.foregroundStyle(.blue)
}

Button {
showingAlert = false
showingPhotosPicker = true
Expand All @@ -97,23 +100,22 @@ struct ScannedJourneyInfoView: View {
} message: {
Text("The previously uploaded image information will disappear. Do you want to proceed?")
}

PhotosPicker(selection: $pickedItem, matching: .screenshots) {
EmptyView()
}
.onChange(of: pickedItem) {
imageHandler.loadImageByPhotosPickerItem(from: pickedItem, viewCategory: "ScannedJourneyInfoView", completion: {})
}
.photosPicker(isPresented: $showingPhotosPicker, selection: $pickedItem, matching: .screenshots)

NavigationLink(destination: MapView(path: $path), tag: 1, selection: $tag) {
EmptyView()
}

FilledButton(
title: "Start",
fillColor: imageHandler.showAlertText ? .grey100 : .brandPrimary
) {

FilledButton(title: "Start",
fillColor: imageHandler.showAlertText ? .grey100 : .brandPrimary) {
isLoading = true
Task {
await NotificationManager.shared.requestNotificationPermission()
if !imageHandler.showAlertText {
Expand All @@ -122,26 +124,34 @@ struct ScannedJourneyInfoView: View {
startStopString: imageHandler.scannedJourneyInfo.startStop,
endStopString: imageHandler.scannedJourneyInfo.endStop
)

guard let startStop = journeyModel.journeyStops.first else { return }
guard let endStop = journeyModel.journeyStops.last else { return }

activityManager.startLiveActivity(startBusStop: startStop, endBusStop: endStop, remainingStops: locationManager.remainingStops)
tag = 1
path.append("BusStop")

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
isLoading = false
tag = 1
path.append("BusStop")
}
}
}
}
.disabled(imageHandler.showAlertText)
.disabled(imageHandler.showAlertText)
}
.frame(height: 52)
.padding(.vertical, 12.5)
}
.padding(.horizontal, 16)

if isShowingInformation {
InformationModalView(isShowingInformation: $isShowingInformation)
}

if isLoading {
LoadingView()
}
}
.onTapGesture {
UIApplication.shared.endEditing()
Expand All @@ -157,15 +167,15 @@ struct ScannedJourneyInfoView: View {
}
.disabled(isShowingInformation)
}

}

private func uploadedInfoBox(title: String, scannedInfo: Binding<String>) -> some View {
VStack(alignment: .leading) {
Text("\(title)")
.foregroundStyle(.grey300)
.font(.system(size: 14, weight: .medium))

TextField("\(scannedInfo.wrappedValue)", text: scannedInfo)
.foregroundStyle(.textDefault)
.font(.system(size: 20, weight: .bold))
Expand Down
25 changes: 25 additions & 0 deletions TMT/TMT/Loading/Models/LoadingCase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// LoadingViewEnum.swift
// TMT
//
// Created by 김유빈 on 12/4/24.
//

enum Loading: CaseIterable {
case loadingDynamic
case loadingCompare

var description: String {
switch self {
case .loadingDynamic: return "Match with\nDynamic Island"
case .loadingCompare: return "Compare\nRomanization"
}
}

var loadingImage: String {
switch self {
case .loadingDynamic: return "LoadingDynamic"
case .loadingCompare: return "LoadingCompare"
}
}
}
70 changes: 70 additions & 0 deletions TMT/TMT/Loading/Views/LoadingView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// LoadingView.swift
// TMT
//
// Created by 김유빈 on 12/4/24.
//

import SwiftUI

struct LoadingView: View {
@State private var currentLoading: Loading = .loadingDynamic
@State private var timer: Timer? = nil

var body: some View {
VStack(spacing: 0) {
HStack {
Text(currentLoading.description)
.foregroundStyle(.textDefault)
.font(.system(size: 28, weight: .bold))

Spacer()
}
.padding(.horizontal, 16)
.padding(.top, 150)

Spacer()

Image(currentLoading.loadingImage)

}
.background {
Color.brandBackground
}
.ignoresSafeArea(.all)
.onAppear {
startAlternating()
}
.onDisappear {
stopAlternating()
}
}

private func startAlternating() {
timer = Timer.scheduledTimer(withTimeInterval: 1.5, repeats: true) { _ in
withAnimation {
switchToNextLoading()
}
}
}

private func stopAlternating() {
timer?.invalidate()
timer = nil
}

private func switchToNextLoading() {
if let currentIndex = Loading.allCases.firstIndex(of: currentLoading) {
let nextIndex = (currentIndex + 1) % Loading.allCases.count
currentLoading = Loading.allCases[nextIndex]
}
}
}

#Preview {
LoadingView()
}

#Preview {
LoadingView()
}
4 changes: 3 additions & 1 deletion TMT/TMT/TMT.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array/>
<array>
<string>group.twomanythinking.TMT</string>
</array>
</dict>
</plist>
4 changes: 3 additions & 1 deletion TMT/TMT/TMTRelease.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array/>
<array>
<string>group.twomanythinking.TMT</string>
</array>
</dict>
</plist>
Loading

0 comments on commit 74843e7

Please sign in to comment.