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

feat: Toast 기능 구현 #130

Merged
merged 4 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions iOS/Layover/Layover.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
835A61A22B068115002F22A5 /* PlaybackInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A619C2B068115002F22A5 /* PlaybackInteractor.swift */; };
835A61A62B0B4DDD002F22A5 /* Dashboard-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 835A61A52B0B4DDD002F22A5 /* Dashboard-Regular.ttf */; };
835A61A92B0B5A31002F22A5 /* LoginConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A61A82B0B5A31002F22A5 /* LoginConfigurator.swift */; };
836C33872B15A29600ECAFB0 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33862B15A29600ECAFB0 /* Toast.swift */; };
83C35E1B2B108C3500D8DD5C /* PlaybackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */; };
83C35E1E2B10923C00D8DD5C /* PlaybackCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */; };
FC2511A02B045C0A004717BC /* SignUpInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = FC25119F2B045C0A004717BC /* SignUpInteractor.swift */; };
Expand Down Expand Up @@ -174,6 +175,7 @@
835A61A52B0B4DDD002F22A5 /* Dashboard-Regular.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Dashboard-Regular.ttf"; sourceTree = "<group>"; };
835A61A82B0B5A31002F22A5 /* LoginConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginConfigurator.swift; sourceTree = "<group>"; };
835A61AA2B0B85FD002F22A5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = "<group>"; };
836C33862B15A29600ECAFB0 /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = "<group>"; };
83C35E1A2B108C3500D8DD5C /* PlaybackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackView.swift; sourceTree = "<group>"; };
83C35E1D2B10923C00D8DD5C /* PlaybackCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackCell.swift; sourceTree = "<group>"; };
FC25119F2B045C0A004717BC /* SignUpInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpInteractor.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -335,6 +337,7 @@
children = (
19743C042B06940D001E405A /* PlayerView.swift */,
19E79ABF2B0A85D0009EA9ED /* LoopingPlayerView.swift */,
836C33862B15A29600ECAFB0 /* Toast.swift */,
);
path = UIComponents;
sourceTree = "<group>";
Expand Down Expand Up @@ -743,6 +746,7 @@
1972CCDF2B14C9B000C3C762 /* Notification.Name+.swift in Sources */,
FC2511AF2B04EAD9004717BC /* MapPresenter.swift in Sources */,
19AACFCA2B0F7C3B0088143E /* Response.swift in Sources */,
836C33872B15A29600ECAFB0 /* Toast.swift in Sources */,
FC767F972B1224B80088CF9B /* IntroduceDTO.swift in Sources */,
1972CCD42B138E6B00C3C762 /* SignUpRouter.swift in Sources */,
FC68E2A32B0233BC001AABFF /* NetworkError.swift in Sources */,
Expand Down
54 changes: 54 additions & 0 deletions iOS/Layover/Layover/Scenes/UIComponents/Toast.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Toast.swift
// Layover
//
// Created by 황지웅 on 11/28/23.
// Copyright © 2023 CodeBomber. All rights reserved.
//

import UIKit

final class Toast {
private let toastMessageLabel: UILabel = {
let label: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 192, height: 46))
chopmozzi marked this conversation as resolved.
Show resolved Hide resolved
// Font 추천 바람
label.font = .loFont(type: .body2Semibold)
chopmozzi marked this conversation as resolved.
Show resolved Hide resolved
label.layer.cornerRadius = 8
label.backgroundColor = .background
chopmozzi marked this conversation as resolved.
Show resolved Hide resolved
label.textColor = .layoverWhite
label.alpha = 0.0
label.textAlignment = .center
return label
}()

static let shared = Toast()

private init() {
let scenes: Set<UIScene> = UIApplication.shared.connectedScenes
let windowScene: UIWindowScene? = scenes.first as? UIWindowScene
let window: UIWindow? = windowScene?.windows.first
window?.addSubview(toastMessageLabel)
chopmozzi marked this conversation as resolved.
Show resolved Hide resolved
guard let windowWidth: CGFloat = windowScene?.screen.bounds.width else {
return
}
guard let windowHeight: CGFloat = windowScene?.screen.bounds.height else {
return
}
toastMessageLabel.frame = CGRect(
x: (windowWidth - 192) / 2,
y: (windowHeight - 46) / 2,
width: 192,
height: 46)
}

func showToast(message: String) {
toastMessageLabel.text = message
UIView.animate(withDuration: 1.0, delay: 0.1, animations: {
self.toastMessageLabel.alpha = 1.0
}, completion: { _ in
UIView.animate(withDuration: 1.0, delay: 0.1, animations: {
self.toastMessageLabel.alpha = 0.0
})
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

여기에서 delay를 주신 의미가 궁금합니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

토스트가 적절히 나타나도록 딜레이를 넣었습니다. 빼는게 나을까용?

}
chopmozzi marked this conversation as resolved.
Show resolved Hide resolved
}