diff --git a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift index 2f2c7f0..0681d54 100644 --- a/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomBookingsListView.swift @@ -67,12 +67,15 @@ struct RoomBookingsListView: View { } .frame(height: hoursToDisplay * 40) } - .frame(height: hoursToDisplay * 40) .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) } } } diff --git a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift index f79ad4e..2e8cb5d 100644 --- a/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift +++ b/ios/Rooms/Sources/RoomViews/RoomDetailsSheetView.swift @@ -10,6 +10,8 @@ import RoomModels import RoomViewModels import SwiftUI +// MARK: - RoomDetailsSheetView + struct RoomDetailsSheetView: View { // MARK: Lifecycle @@ -23,13 +25,10 @@ struct RoomDetailsSheetView: View { // 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) @@ -48,11 +47,34 @@ struct RoomDetailsSheetView: View { } // Booking Grid - ScrollView { - RoomBookingsListView( - room: room, - roomViewModel: roomViewModel, - dateSelect: $dateSelect) + ScrollView(.horizontal, showsIndicators: false) { + LazyHStack(spacing: 0) { + ForEach(0.. 1 { + baseDate = newValue + scrollID = Self.middleIndex + } } } .padding() @@ -80,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)? @@ -94,3 +132,13 @@ struct RoomDetailsSheetView: View { RoomDetailsSheetView(room: Room.exampleOne, roomViewModel: PreviewRoomViewModel()) .defaultTheme() } + +extension Double { + static let day: Double = 86_400 +} + +extension Date { + static func +(lhs: Date, rhs: Double) -> Date { + lhs.addingTimeInterval(rhs) + } +}