-
Notifications
You must be signed in to change notification settings - Fork 0
추천 기능 UI에 맞게 컴포넌트들을 수정 / 구현합니다. #320
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6cabad5
feat/#315: TooptipView 및 TooltipFactory 생성
pinocchio22 e288405
Merge branch 'fix/#315-Components' of github.com:Team-Maple/MLS-iOS i…
pinocchio22 71f3d25
fix/#315: 로그인유도 UI / 레벨, 직업 입력 UI 수정
pinocchio22 062f7ee
style/#315: Apply SwiftLint autocorrect
github-actions[bot] 679b0a5
fix/#315: 제미나이 피드백 반영 수정
pinocchio22 8bb48e4
Merge branch 'fix/#315-Components' of github.com:Team-Maple/MLS-iOS i…
pinocchio22 7b4aefd
style/#315: Apply SwiftLint autocorrect
github-actions[bot] c360738
fix/#315: rxGesture 추가 + 접근제어자 설정
pinocchio22 81e6cd3
Merge branch 'fix/#315-Components' of github.com:Team-Maple/MLS-iOS i…
pinocchio22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
MLS/MLSDesignSystem/Sources/MLSDesignSystem/Components/Tooltip/TooltipOverlayView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import UIKit | ||
|
|
||
| import RxCocoa | ||
| import RxGesture | ||
| import RxSwift | ||
|
|
||
| internal final class TooltipOverlayView: UIView { | ||
| // MARK: - Properties | ||
| private let disposeBag = DisposeBag() | ||
| let dismiss = PublishRelay<Void>() | ||
|
|
||
| // MARK: - Init | ||
| override init(frame: CGRect) { | ||
| super.init(frame: frame) | ||
| backgroundColor = .clear | ||
|
|
||
| rx.tapGesture() | ||
| .when(.recognized) | ||
| .map { _ in } | ||
| .bind(to: dismiss) | ||
| .disposed(by: disposeBag) | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required init?(coder: NSCoder) { fatalError() } | ||
| } |
140 changes: 140 additions & 0 deletions
140
MLS/MLSDesignSystem/Sources/MLSDesignSystem/Components/Tooltip/TooltipView.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import UIKit | ||
|
|
||
| import SnapKit | ||
|
|
||
| /// Tooltip이 뻗어나가는 방향 | ||
| public enum TooltipPosition { | ||
| case topLeading | ||
| case topTrailing | ||
| case bottomLeading | ||
| case bottomTrailing | ||
| } | ||
|
|
||
| private enum Constants { | ||
| static let arrowSize = CGSize(width: 16, height: 10) | ||
| static let cornerRadius: CGFloat = 16 | ||
| static let arrowInset: CGFloat = 28 /// arrow는 툴팁 내부에서 고정 위치 | ||
| } | ||
|
|
||
| final class TooltipView: UIView { | ||
|
|
||
| // MARK: - Properties | ||
| private let tooltipPosition: TooltipPosition | ||
| private let shapeLayer = CAShapeLayer() | ||
|
|
||
| // MARK: - Components | ||
| private let label = UILabel() | ||
|
|
||
| // MARK: - init | ||
| init(text: String, tooltipPosition: TooltipPosition) { | ||
| self.tooltipPosition = tooltipPosition | ||
| super.init(frame: .zero) | ||
| addViews() | ||
| setupConstraints() | ||
| configureUI(text: text) | ||
| } | ||
|
|
||
| @available(*, unavailable) | ||
| required init?(coder: NSCoder) { | ||
| fatalError("\(#file), \(#function) Error") | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Layout | ||
| private extension TooltipView { | ||
|
|
||
| func addViews() { | ||
| addSubview(label) | ||
| } | ||
|
|
||
| func setupConstraints() { | ||
| switch tooltipPosition { | ||
|
|
||
| /// 툴팁이 아래에 위치 | ||
| case .bottomLeading, .bottomTrailing: | ||
| label.snp.makeConstraints { make in | ||
| make.top.equalToSuperview().inset(11) | ||
| make.horizontalEdges.equalToSuperview().inset(18) | ||
| make.bottom.equalToSuperview().inset(11 + Constants.arrowSize.height) | ||
| } | ||
|
|
||
| /// 툴팁이 위에 위치 | ||
| case .topLeading, .topTrailing: | ||
| label.snp.makeConstraints { make in | ||
| make.top.equalToSuperview().inset(11 + Constants.arrowSize.height) | ||
| make.horizontalEdges.equalToSuperview().inset(18) | ||
| make.bottom.equalToSuperview().inset(11) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func configureUI(text: String) { | ||
| backgroundColor = .clear | ||
|
|
||
| label.attributedText = .makeStyledString(font: .b_s_r, text: text) | ||
| label.numberOfLines = 0 | ||
|
|
||
| layer.insertSublayer(shapeLayer, at: 0) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Draw Bubble | ||
| extension TooltipView { | ||
|
|
||
| override func layoutSubviews() { | ||
| super.layoutSubviews() | ||
| drawBubble() | ||
| } | ||
|
|
||
| /// 말풍선 + arrow path 생성 | ||
| private func drawBubble() { | ||
|
|
||
| let rect = bounds | ||
| let arrowHeight = Constants.arrowSize.height | ||
| let arrowWidth = Constants.arrowSize.width | ||
|
|
||
| /// 툴팁 상하 위치 판단 | ||
| let isTop = tooltipPosition == .bottomLeading || tooltipPosition == .bottomTrailing | ||
|
|
||
| /// 실제 툴팁 영역 | ||
| let bubbleRect = CGRect( | ||
| x: 0, | ||
| y: isTop ? 0 : arrowHeight, | ||
| width: rect.width, | ||
| height: rect.height - arrowHeight | ||
| ) | ||
|
|
||
| let bubblePath = UIBezierPath( | ||
| roundedRect: bubbleRect, | ||
| cornerRadius: Constants.cornerRadius | ||
| ) | ||
|
|
||
| let arrowX: CGFloat | ||
| switch tooltipPosition { | ||
| case .topLeading, .bottomLeading: | ||
| arrowX = Constants.arrowInset | ||
|
|
||
| case .topTrailing, .bottomTrailing: | ||
| arrowX = bubbleRect.width - Constants.arrowInset | ||
| } | ||
|
|
||
| let arrowPath = UIBezierPath() | ||
|
|
||
| if isTop { | ||
| arrowPath.move(to: CGPoint(x: arrowX - arrowWidth/2, y: bubbleRect.minY)) | ||
| arrowPath.addLine(to: CGPoint(x: arrowX, y: bubbleRect.minY - arrowHeight)) | ||
| arrowPath.addLine(to: CGPoint(x: arrowX + arrowWidth/2, y: bubbleRect.minY)) | ||
| } else { | ||
| arrowPath.move(to: CGPoint(x: arrowX - arrowWidth/2, y: bubbleRect.maxY)) | ||
| arrowPath.addLine(to: CGPoint(x: arrowX, y: bubbleRect.maxY + arrowHeight)) | ||
| arrowPath.addLine(to: CGPoint(x: arrowX + arrowWidth/2, y: bubbleRect.maxY)) | ||
| } | ||
|
|
||
| arrowPath.close() | ||
| bubblePath.append(arrowPath) | ||
|
|
||
| shapeLayer.frame = bounds | ||
| shapeLayer.path = bubblePath.cgPath | ||
| shapeLayer.fillColor = UIColor.whiteMLS.cgColor | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
MLS/MLSDesignSystem/Sources/MLSDesignSystem/Layouts/Factory/TooltipFactory.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import UIKit | ||
|
|
||
| import RxSwift | ||
| import SnapKit | ||
|
|
||
| @MainActor | ||
| public enum TooltipFactory { | ||
| // MARK: - Properties | ||
| private static let disposeBag = DisposeBag() | ||
|
|
||
| /// 현재 디바이스 최상단 Window를 지정 | ||
| static var window: UIWindow? { | ||
| UIApplication.shared | ||
| .connectedScenes | ||
| .flatMap { ($0 as? UIWindowScene)?.windows ?? [] } | ||
| .first { $0.isKeyWindow } | ||
| } | ||
|
|
||
| private static var currentTooltip: TooltipView? | ||
|
|
||
| /// 전체 터치 dismiss용 overlay | ||
| private static var overlayView: TooltipOverlayView? | ||
| } | ||
|
|
||
| public extension TooltipFactory { | ||
| /// Tooltip 노출 메소드 | ||
| static func show( | ||
| text: String, | ||
| anchorView: UIView, | ||
| tooltipPosition: TooltipPosition | ||
| ) { | ||
| currentTooltip?.removeFromSuperview() | ||
| currentTooltip = nil | ||
|
|
||
| guard let window = window else { return } | ||
|
|
||
| /// 전체 영역 터치 dismiss overlay | ||
| let overlay = TooltipOverlayView(frame: window.bounds) | ||
| window.addSubview(overlay) | ||
| overlayView = overlay | ||
|
|
||
| let tooltip = TooltipView(text: text, tooltipPosition: tooltipPosition) | ||
| overlay.addSubview(tooltip) | ||
| currentTooltip = tooltip | ||
|
|
||
| overlay.dismiss | ||
| .bind { _ in | ||
| dismiss() | ||
| } | ||
| .disposed(by: disposeBag) | ||
|
|
||
| let frame = anchorView.convert(anchorView.bounds, to: window) | ||
|
|
||
| tooltip.frame.origin = CGPoint(x: 0, y: 0) | ||
| tooltip.setNeedsLayout() | ||
| tooltip.layoutIfNeeded() | ||
|
|
||
| let tooltipSize = tooltip.systemLayoutSizeFitting( | ||
| UIView.layoutFittingCompressedSize | ||
| ) | ||
|
|
||
| /// arrow가 툴팁 내부에서 위치하는 고정 inset | ||
| let arrowInset: CGFloat = 28 | ||
| let anchorCenterX = frame.midX | ||
|
|
||
| /// 툴팁 내부 arrow 중심 위치 | ||
| let arrowCenterInTooltip: CGFloat | ||
| switch tooltipPosition { | ||
| case .topLeading, .bottomLeading: | ||
| arrowCenterInTooltip = arrowInset | ||
|
|
||
| case .topTrailing, .bottomTrailing: | ||
| arrowCenterInTooltip = tooltipSize.width - arrowInset | ||
| } | ||
|
|
||
| /// arrow 중심 = 버튼 중심 | ||
| let x = anchorCenterX - arrowCenterInTooltip | ||
|
|
||
| let y: CGFloat | ||
| switch tooltipPosition { | ||
| case .topLeading, .topTrailing: | ||
| y = frame.minY - tooltipSize.height - 8 | ||
| case .bottomLeading, .bottomTrailing: | ||
| y = frame.maxY + 8 | ||
| } | ||
|
|
||
| tooltip.frame = CGRect( | ||
| x: x, | ||
| y: y, | ||
| width: tooltipSize.width, | ||
| height: tooltipSize.height | ||
| ) | ||
|
|
||
| tooltip.alpha = 0 | ||
| UIView.animate(withDuration: 0.25) { | ||
| tooltip.alpha = 1 | ||
| } | ||
| } | ||
|
|
||
| /// 툴팁 제거 | ||
| static func dismiss() { | ||
| guard let tooltip = currentTooltip else { return } | ||
|
|
||
| UIView.animate(withDuration: 0.2, animations: { | ||
| tooltip.alpha = 0 | ||
| overlayView?.alpha = 0 | ||
| }, completion: { _ in | ||
| tooltip.removeFromSuperview() | ||
| overlayView?.removeFromSuperview() | ||
|
|
||
| currentTooltip = nil | ||
| overlayView = nil | ||
| }) | ||
| } | ||
|
pinocchio22 marked this conversation as resolved.
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
최상단
window를 찾는 로직이ToastFactory.swift와 완전히 중복되어 구현되어 있습니다. 향후 윈도우 탐색 로직이 변경될 경우 두 곳을 모두 수정해야 하는 번거로움이 있으므로,UIWindowextension 등으로 분리하여 공통으로 사용하는 것이 좋습니다.