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

Toast Message 구현 [SwiftUI] #161

Merged
merged 6 commits into from
Jul 2, 2024
Merged

Conversation

sladuf
Copy link
Contributor

@sladuf sladuf commented Jul 2, 2024

개요


구현 내용

1. ToastMessage 동작

  • UIKit에서도 한 줄만 작성하면 쉽게 Toast를 띄울 수 있습니다!
ToastMessage.shared.show(type: ToastType)

2. UIKit에서 사용 가능한 ToastMessage

  • 현재 UIKit으로 화면 구성이 되어 있어, SwiftUI View가 window로 접근하기 위해서는 hosting이 필요합니다.
  • 그래서 현재는 ToastMessage를 UIView로 만들어, ToastView를 hosting 하도록 구현했습니다.
  • SwiftUI로 전면 교체 된다면, ToastMessage만 교체 하거나 window에 바로 접근할 수 있도록 개선할 수 있습니다.
  • UIKit에서는 @observableobject의 관찰이 어려워 NotificationCenter를 추가했습니다.

4. ToastViewProtocol

  • SwiftUI는 View가 구조체로 되어 있어, 상속이 불가 하다는 단점이 있습니다.
  • 단점을 보완하기 위해 ToastView 껍데기를 만들고,
    내부에 보여질 컨텐츠는 ToastViewProtocol을 채택한 객체로 Custom할 수 있도록 구현했습니다.
  • 이를 통해, ToastView에 다양한 UI 적용이 가능합니다. (껍데기는 디자인 가이드를 따름)

5. ToastPresenter

  • Toast의 presenting을 담당하는 객체 입니다.
  • ToastView의 subview들은 superview의 presenter를 가지고 상태 변화에 대한 UI처리를 할 수 있습니다.
  • 현재는 ToastMessage에서 중복되는 Toast를 관리하기 위해 사용하고 있습니다.

ScreenShot

  • Toast는 애니메이션이 있어 영상 첨부합니다!
RPReplay_Final1719851353.mov

@sladuf sladuf added the feature 기능 추가/변경/삭제 label Jul 2, 2024
@sladuf sladuf self-assigned this Jul 2, 2024
@sladuf sladuf marked this pull request as ready for review July 2, 2024 12:00
@sladuf sladuf requested a review from minsangKang July 2, 2024 12:00
@sladuf sladuf changed the base branch from feature/date_auto_renew to feature/#152 July 2, 2024 15:13
@sladuf sladuf changed the base branch from feature/#152 to feature/date_auto_renew July 2, 2024 15:13
@sladuf sladuf merged commit 318136f into feature/date_auto_renew Jul 2, 2024
@sladuf sladuf linked an issue Jul 3, 2024 that may be closed by this pull request
Copy link
Member

@minsangKang minsangKang left a comment

Choose a reason for hiding this comment

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

수고하셨습니다! 👍

Project_Timer/Core/Localize/TLRen.swift Show resolved Hide resolved
Comment on lines +488 to +489
/// Toast Message: 기록 시작!
case Toast_Text_NewRecord
Copy link
Member

Choose a reason for hiding this comment

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

P3 (반영 고민)
TLRKey 의 주석은 한글로 어떤값인지를 나타내고 있었어요!
기존 방식이라면 "기록 시작!" 내용이여야 합니다
확인이 필요할 것 같아요!

Comment on lines +25 to +29
translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
centerXAnchor.constraint(equalTo: window.centerXAnchor),
topAnchor.constraint(equalTo: window.safeAreaLayoutGuide.topAnchor)
])
Copy link
Member

Choose a reason for hiding this comment

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

P4 (참고)

self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
    self.centerXAnchor.constraint(equalTo: window.centerXAnchor),
    self.topAnchor.constraint(equalTo: window.safeAreaLayoutGuide.topAnchor)
])

])
}

NotificationCenter.default.addObserver(forName: Notification.Name("updatedIsPresenting"), object: nil, queue: nil) { [weak self] notification in
Copy link
Member

Choose a reason for hiding this comment

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

P4 (참고)
Notification.Name 은 한곳에서 관리되면 어떨까요?
Notification+Extension 파일에 추가하는것도 고려해보면 좋을 것 같습니다!

Comment on lines +46 to +49
if presenter.isPresenting {
toast?.view.removeFromSuperview()
presenter.isPresenting = false
}
Copy link
Member

Choose a reason for hiding this comment

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

P1 (꼭 확인)
toast가 표시되어 있는데 toast를 표시하고자 하는 경우에 속하는 것 같아요
그때 기존 toast를 제거하고 표시하고자 하는 것으로 보이는데, 올바른 UX가 아닌 것 같아요!
개인 의견으로는 Toast 대기열, 또는 Toast 위에 Toast 표시 등의 방법이 더 좋을 것 같습니다
논의가 필요해 보여요!

self.toast = toast
}

guard let toastView = self.toast?.view else { return }
Copy link
Member

Choose a reason for hiding this comment

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

P1 (꼭 반영)
guard 문은 최상위로 올려주세요!
예상치 못한 경우 hostingViewController가 설정되었는데 표시가 안되는 상황이 발생할 수 있을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이해를 못했습니다
self.toast = toast를 하기전에는 guard문이 무조건 return을 하게 될텐데 의도하시는 동작이 어떤걸까요 ??

@@ -0,0 +1,22 @@
//
// ToastData.swift
Copy link
Member

Choose a reason for hiding this comment

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

P4 (참고)
ToastPresenter

@@ -27,4 +27,6 @@ enum Colors {
static let placeholderGray = UIColor(named: "placeholderGrayColor")!
static let firstBackground = UIColor(named: "firstBackgroundColor")!
static let wrongTextField = UIColor(named: "wrongTextFieldColor")!

static let ttPrimary = UIColor(named: "primary")!
Copy link
Member

Choose a reason for hiding this comment

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

P1 (꼭 확인)
Figma 상에서 앞으로 관리되는 컬러값은 프로퍼티명이 동일했으면 좋겠습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

primary는 iOS에서 제공하는 기본 컬러값이 있기 때문에 tt를 prefix로 붙였습니다
이 부분을 통일하려면 디자인 쪽에서 수정하는게 좋을것 같습니다! 회의때 얘기해보시죵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 기능 추가/변경/삭제
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toast Message 구현 [SwiftUI]
2 participants