-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/#109 피커 실시간 변동 적용 #119
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,12 +41,28 @@ private struct PickerViewRepresentable: UIViewRepresentable { | |
| } | ||
|
|
||
| let row = selection - range.lowerBound | ||
| picker.selectRow(row, inComponent: 0, animated: true) | ||
| picker.selectRow(row, inComponent: 0, animated: false) | ||
|
|
||
| DispatchQueue.main.async { | ||
| self.findAndConnectScrollViews(in: picker, coordinator: context.coordinator) | ||
| } | ||
|
|
||
| return picker | ||
| } | ||
|
|
||
| private func findAndConnectScrollViews(in view: UIView, coordinator: Coordinator) { | ||
| for subview in view.subviews { | ||
| if let scrollView = subview as? UIScrollView { | ||
| coordinator.originalScrollViewDelegate = scrollView.delegate | ||
| scrollView.delegate = coordinator | ||
|
Comment on lines
+55
to
+57
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와이거개고능하네요 |
||
| } | ||
| findAndConnectScrollViews(in: subview, coordinator: coordinator) | ||
| } | ||
| } | ||
|
Comment on lines
+53
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 여러 UIScrollView가 존재할 경우 원본 델리게이트 손실 가능
♻️ 제안된 수정사항 private func findAndConnectScrollViews(in view: UIView, coordinator: Coordinator) {
for subview in view.subviews {
if let scrollView = subview as? UIScrollView {
coordinator.originalScrollViewDelegate = scrollView.delegate
scrollView.delegate = coordinator
+ return // 첫 번째 스크롤 뷰만 연결
}
findAndConnectScrollViews(in: subview, coordinator: coordinator)
}
}🤖 Prompt for AI Agents |
||
|
|
||
| func updateUIView(_ uiView: UIPickerView, context: Context) { | ||
| guard !context.coordinator.isScrolling else { return } | ||
|
|
||
| let row = selection - range.lowerBound | ||
| if uiView.selectedRow(inComponent: 0) != row { | ||
| uiView.selectRow(row, inComponent: 0, animated: true) | ||
|
|
@@ -59,8 +75,11 @@ private struct PickerViewRepresentable: UIViewRepresentable { | |
| } | ||
|
|
||
| extension PickerViewRepresentable { | ||
| class Coordinator: NSObject, UIPickerViewDelegate, UIPickerViewDataSource { | ||
| class Coordinator: NSObject, UIPickerViewDelegate, UIPickerViewDataSource, UIScrollViewDelegate { | ||
| var parent: PickerViewRepresentable | ||
| private let rowHeight: CGFloat = 44.adjustedH | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial 행 높이 상수 중복
♻️ 제안된 수정사항 func pickerView(_ pickerView: UIPickerView, rowHeightForComponent component: Int) -> CGFloat {
- 44.adjustedH
+ rowHeight
}🤖 Prompt for AI Agents
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 확인부탁~~ |
||
| var isScrolling: Bool = false | ||
| weak var originalScrollViewDelegate: UIScrollViewDelegate? | ||
|
|
||
| init(_ parent: PickerViewRepresentable) { | ||
| self.parent = parent | ||
|
|
@@ -75,13 +94,14 @@ extension PickerViewRepresentable { | |
| } | ||
|
|
||
| func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { | ||
| isScrolling = false | ||
| parent.selection = parent.range.lowerBound + row | ||
| } | ||
|
|
||
| func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView { | ||
| pickerView.subviews.forEach { subview in | ||
| subview.backgroundColor = .clear | ||
| } | ||
| subview.backgroundColor = .clear | ||
| } | ||
|
|
||
| let label = (view as? UILabel) ?? UILabel() | ||
| label.text = "\(parent.range.lowerBound + row)" | ||
|
|
@@ -98,5 +118,47 @@ extension PickerViewRepresentable { | |
| func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat { | ||
| 60.adjustedW | ||
| } | ||
|
|
||
| private var initialContentOffset: CGFloat = 0 | ||
| private var initialRow: Int = 0 | ||
|
|
||
| func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { | ||
| isScrolling = true | ||
| initialContentOffset = scrollView.contentOffset.y | ||
| initialRow = parent.selection - parent.range.lowerBound | ||
| originalScrollViewDelegate?.scrollViewWillBeginDragging?(scrollView) | ||
| } | ||
|
|
||
| func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) { | ||
| originalScrollViewDelegate?.scrollViewDidEndDragging?(scrollView, willDecelerate: decelerate) | ||
| } | ||
|
|
||
| func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | ||
| originalScrollViewDelegate?.scrollViewDidEndDecelerating?(scrollView) | ||
| } | ||
|
|
||
| func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 개행 한번만여 |
||
| originalScrollViewDelegate?.scrollViewWillEndDragging?(scrollView, withVelocity: velocity, targetContentOffset: targetContentOffset) | ||
| } | ||
|
|
||
| func scrollViewDidScroll(_ scrollView: UIScrollView) { | ||
| originalScrollViewDelegate?.scrollViewDidScroll?(scrollView) | ||
|
|
||
| guard isScrolling else { return } | ||
|
|
||
| let deltaOffset = scrollView.contentOffset.y - initialContentOffset | ||
| let deltaRow = Int(round(deltaOffset / rowHeight)) | ||
| let newRow = initialRow + deltaRow | ||
| let clampedRow = max(0, min(newRow, parent.range.count - 1)) | ||
| let newSelection = parent.range.lowerBound + clampedRow | ||
|
Comment on lines
+149
to
+153
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와우어렵네요 고능하다
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와우띵.. |
||
|
|
||
| if parent.selection != newSelection { | ||
| parent.selection = newSelection | ||
| } | ||
| } | ||
|
|
||
| func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView) { | ||
| originalScrollViewDelegate?.scrollViewDidEndScrollingAnimation?(scrollView) | ||
| } | ||
| } | ||
| } | ||
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.
🧹 Nitpick | 🔵 Trivial
내부 UIPickerView 구조에 의존하는 구현
UIPickerView의 내부 서브뷰 계층 구조는 비공개 API이므로, iOS 버전 업데이트 시UIScrollView를 찾지 못할 수 있습니다. 이 접근 방식은 현재 동작하지만 향후 iOS 업데이트에서 깨질 수 있으므로, 스크롤 뷰를 찾지 못하는 경우에 대한 폴백(fallback) 로직 추가를 권장합니다.🤖 Prompt for AI Agents