Skip to content

Swiping on calendar days#176

Open
xleonx0x wants to merge 5 commits intomainfrom
swiping_on_calendar_days
Open

Swiping on calendar days#176
xleonx0x wants to merge 5 commits intomainfrom
swiping_on_calendar_days

Conversation

@xleonx0x
Copy link
Copy Markdown
Contributor

@xleonx0x xleonx0x commented Apr 4, 2026

What

Adding paging when looking at bookings in the calendar.

Why

Suggestion from lucas and also better ux!

How

Hard coded 1000 pages and just calculated changes depending on the index to the date.

Key checks:

  • 🚩Attached screenshot or recording of the changes in related tickets
  • Code comments where needed
  • No new warnings

Automated tests:

  • 🚩Unit tests added

Manual tests:

  • Big iPhone (iPhone 17 Pro Max)
  • Small iPhone (iPhone SE)

Screenshot / Recording

output.mp4

@xleonx0x xleonx0x requested a review from Yalilix April 4, 2026 17:23
@xleonx0x xleonx0x self-assigned this Apr 4, 2026
Comment on lines +119 to +121
@State private var scrollID: Int? = middleIndex
@State private var baseDate = Date()
@State private var dateSelect = Date()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lets move all the states and logic to the view model instead, makes the view logic more testable and adhere to the architecture too

Copy link
Copy Markdown
Contributor

@DickoEvaldo DickoEvaldo left a comment

Choose a reason for hiding this comment

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

Minor changes

Comment on lines +136 to +138
extension Double {
static let day: Double = 86_400
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this might be a reusable Double extension put it in a common file instead of this view file

Comment on lines +140 to +144
extension Date {
static func +(lhs: Date, rhs: Double) -> Date {
lhs.addingTimeInterval(rhs)
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if the extension is only being used in this file use fileprivate extension Date but if might be used in othe component define the extension in the model file

Comment on lines +65 to +76
.onChange(of: scrollID) { oldValue, newValue in
if let newValue, let oldValue, abs(newValue - oldValue) == 1 {
dateSelect = baseDate + (Double(newValue - Self.middleIndex) * .day)
}
}
.onChange(of: dateSelect) { _, newValue in
let currentScroll = scrollID ?? Self.middleIndex
let expectedDate = baseDate + (Double(currentScroll - Self.middleIndex) * .day)

if abs(newValue.timeIntervalSince(expectedDate)) > 1 {
baseDate = newValue
scrollID = Self.middleIndex
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

logic in the view model so its testable

Comment on lines +72 to +78
if Calendar.current.isDateInToday(dateSelect) {
let currentHour = max(dateComponent.hour ?? 0, 9)
withAnimation(.easeInOut(duration: 0.5)) {
proxy.scrollTo(currentHour, anchor: .top)
}
} else {
proxy.scrollTo(9, anchor: .top)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

move this to a onAppear function in the viewModel

Comment on lines +73 to +78
let currentHour = max(dateComponent.hour ?? 0, 9)
withAnimation(.easeInOut(duration: 0.5)) {
proxy.scrollTo(currentHour, anchor: .top)
}
} else {
proxy.scrollTo(9, anchor: .top)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

magic number

@DickoEvaldo
Copy link
Copy Markdown
Contributor

very nice feature king

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants