From a98507d84960d8d34248d0125878dcd5a8ca3e27 Mon Sep 17 00:00:00 2001 From: Chris Wong <123799877+xleonx0x@users.noreply.github.com> Date: Fri, 3 Apr 2026 16:12:55 +1100 Subject: [PATCH 1/4] feat: add somewhat working swiping UI for going through days --- .../RoomViews/RoomBookingsListView.swift | 1 - .../RoomViews/RoomDetailsSheetView.swift | 84 +++++++++++++++++-- 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift index 2f2c7f0..0c29415 100644 --- a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift @@ -67,7 +67,6 @@ struct RoomBookingsListView: View { } .frame(height: hoursToDisplay * 40) } - .frame(height: hoursToDisplay * 40) .clipShape(RoundedRectangle(cornerRadius: 12)) .onAppear { let currentHour = max(dateComponent.hour ?? 0, 9) diff --git a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift index f79ad4e..1f6e9b7 100644 --- a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift @@ -13,13 +13,36 @@ import SwiftUI struct RoomDetailsSheetView: View { // MARK: Lifecycle - + @State private var scrollID: Int? = 1 + public init(dateSelect: Date = Date(), room: Room, roomViewModel: RoomViewModel, onDismiss: (() -> Void)? = nil) { self.dateSelect = dateSelect self.room = room self.roomViewModel = roomViewModel self.onDismiss = onDismiss } + + var previousDateBinding: Binding { + Binding( + get: { + dateSelect - .day + }, + set: { newPreviousDate in + dateSelect = newPreviousDate + .day + } + ) + } + + var nextDateBinding: Binding { + Binding( + get: { + dateSelect + .day + }, + set: { newPreviousDate in + dateSelect = newPreviousDate - .day + } + ) + } // MARK: Internal @@ -48,13 +71,56 @@ struct RoomDetailsSheetView: View { } // Booking Grid - ScrollView { - RoomBookingsListView( - room: room, - roomViewModel: roomViewModel, - dateSelect: $dateSelect) + if #available(iOS 18.0, *) { + ScrollView(.horizontal, showsIndicators: false) { + LazyHStack(spacing: 0) { + RoomBookingsListView( + room: room, + roomViewModel: roomViewModel, + dateSelect: previousDateBinding + ) + .containerRelativeFrame(.horizontal) + .id(0) + + RoomBookingsListView( + room: room, + roomViewModel: roomViewModel, + dateSelect: $dateSelect + ) + .containerRelativeFrame(.horizontal) + .id(1) + + RoomBookingsListView( + room: room, + roomViewModel: roomViewModel, + dateSelect: nextDateBinding + ) + .containerRelativeFrame(.horizontal) + .id(2) + } + .scrollTargetLayout() + } + .scrollTargetBehavior(.viewAligned) + .scrollPosition(id: $scrollID) + .onScrollPhaseChange { oldPhase, newPhase in + if newPhase == .idle && (scrollID == 2 || scrollID == 0) { + if scrollID == 2 { + dateSelect += .day + } else if scrollID == 0 { + dateSelect -= .day + } + scrollID = 1 + } + } + } else { + ScrollView { + RoomBookingsListView( + room: room, + roomViewModel: roomViewModel, + dateSelect: $dateSelect) + } + } } - } .padding() .overlay( RoundedRectangle(cornerRadius: 12) @@ -94,3 +160,7 @@ struct RoomDetailsSheetView: View { RoomDetailsSheetView(room: Room.exampleOne, roomViewModel: PreviewRoomViewModel()) .defaultTheme() } + +extension Double { + static let day: Double = 86_400 +} From 543529e519b787b099a8152b38e36739917b2749 Mon Sep 17 00:00:00 2001 From: Chris Wong <123799877+xleonx0x@users.noreply.github.com> Date: Sun, 5 Apr 2026 03:14:14 +1000 Subject: [PATCH 2/4] feat: changed swiping to be hard coded pages :) much smoother now --- .../RoomViews/RoomDetailsSheetView.swift | 122 +++++++----------- 1 file changed, 50 insertions(+), 72 deletions(-) diff --git a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift index 1f6e9b7..7ae5ca8 100644 --- a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift @@ -10,49 +10,25 @@ import RoomModels import RoomViewModels import SwiftUI +// MARK: - RoomDetailsSheetView + struct RoomDetailsSheetView: View { // MARK: Lifecycle - @State private var scrollID: Int? = 1 - + public init(dateSelect: Date = Date(), room: Room, roomViewModel: RoomViewModel, onDismiss: (() -> Void)? = nil) { self.dateSelect = dateSelect self.room = room self.roomViewModel = roomViewModel self.onDismiss = onDismiss } - - var previousDateBinding: Binding { - Binding( - get: { - dateSelect - .day - }, - set: { newPreviousDate in - dateSelect = newPreviousDate + .day - } - ) - } - - var nextDateBinding: Binding { - Binding( - get: { - dateSelect + .day - }, - set: { newPreviousDate in - dateSelect = newPreviousDate - .day - } - ) - } // MARK: Internal - @State var dateSelect = Date() - let room: Room var body: some View { VStack(alignment: .leading, spacing: 10) { - // List { // Booking informations RoomBookingInformationView(room: room, currentRoomRating: roomViewModel.currentRoomRating) @@ -71,56 +47,36 @@ struct RoomDetailsSheetView: View { } // Booking Grid - if #available(iOS 18.0, *) { - ScrollView(.horizontal, showsIndicators: false) { - LazyHStack(spacing: 0) { - RoomBookingsListView( - room: room, - roomViewModel: roomViewModel, - dateSelect: previousDateBinding - ) - .containerRelativeFrame(.horizontal) - .id(0) - - RoomBookingsListView( - room: room, - roomViewModel: roomViewModel, - dateSelect: $dateSelect - ) - .containerRelativeFrame(.horizontal) - .id(1) - - RoomBookingsListView( - room: room, - roomViewModel: roomViewModel, - dateSelect: nextDateBinding - ) + ScrollView(.horizontal, showsIndicators: false) { + LazyHStack(spacing: 0) { + ForEach(0.. 1 { + baseDate = newValue + scrollID = Self.middleIndex + } + } } + } .padding() .overlay( RoundedRectangle(cornerRadius: 12) @@ -146,8 +102,24 @@ struct RoomDetailsSheetView: View { }) } + func bindingFor(index: Int) -> Binding { + Binding( + get: { baseDate + (Double(index - Self.middleIndex) * .day) }, + set: { newDate in + baseDate = newDate + (Double(Self.middleIndex - index) * .day) + }) + } + // MARK: Private + // Paging is 0 <= page < middleindex * 2 + private static let maxScrollID = Self.middleIndex * 2 + private static let middleIndex = 500 + + @State private var scrollID: Int? = middleIndex + @State private var baseDate = Date() + @State private var dateSelect = Date() + @Environment(Theme.self) private var theme private let onDismiss: (() -> Void)? @@ -164,3 +136,9 @@ struct RoomDetailsSheetView: View { extension Double { static let day: Double = 86_400 } + +extension Date { + static func +(lhs: Date, rhs: Double) -> Date { + lhs.addingTimeInterval(rhs) + } +} From ca9437d1b60ebd04d0209abd5a22fa9c3105dcd0 Mon Sep 17 00:00:00 2001 From: Chris Wong <123799877+xleonx0x@users.noreply.github.com> Date: Sun, 5 Apr 2026 03:53:50 +1000 Subject: [PATCH 3/4] chore: fix buggsss --- .../Sources/RoomViews/RoomDetailsSheetView.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift index 7ae5ca8..2e8cb5d 100644 --- a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift @@ -62,18 +62,18 @@ struct RoomDetailsSheetView: View { } .scrollTargetBehavior(.paging) .scrollPosition(id: $scrollID) - .onChange(of: scrollID) { _, newValue in - if let newValue { + .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 - if var scrollID { - let expectedDate = baseDate + (Double((scrollID - Self.middleIndex) - Self.middleIndex) * .day) - if abs(newValue.timeIntervalSince(expectedDate)) > 1 { - baseDate = newValue - scrollID = Self.middleIndex - } + let currentScroll = scrollID ?? Self.middleIndex + let expectedDate = baseDate + (Double(currentScroll - Self.middleIndex) * .day) + + if abs(newValue.timeIntervalSince(expectedDate)) > 1 { + baseDate = newValue + scrollID = Self.middleIndex } } } From 8a13542b5782017d85fb7115d6bdf10d582be588 Mon Sep 17 00:00:00 2001 From: Chris Wong <123799877+xleonx0x@users.noreply.github.com> Date: Tue, 7 Apr 2026 23:29:04 +1000 Subject: [PATCH 4/4] fix: fixed when scrolling it scrolling to the bottom randomly --- ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift index 0c29415..0681d54 100644 --- a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift @@ -69,9 +69,13 @@ struct RoomBookingsListView: View { } .clipShape(RoundedRectangle(cornerRadius: 12)) .onAppear { - let currentHour = max(dateComponent.hour ?? 0, 9) - withAnimation(.easeInOut(duration: 0.5)) { - proxy.scrollTo(currentHour, anchor: .top) + 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) } } }