Skip to content

SimultaneouslyScrollView together with ScrollView modifiers [e.g. .scrollTargetBehavior(.viewAligned)] #21

@OlegBezr

Description

@OlegBezr

Any chance this could work with ScrollView modifiers?
For example with .scrollTargetBehavior(.viewAligned).

Currently does not work well together - no view snapping when scrolling.

minimal example:

import SwiftUI

struct CalendarView: View {
  let simultaneouslyScrollViewHandler = SimultaneouslyScrollViewHandlerFactory.create()

  var body: some View {
    VStack {
      HStack {
        Text("JULY")
          .frame(width: 200)

        GeometryReader { headerGeometry in
          ScrollView(.horizontal, showsIndicators: false) {
            LazyHStack {
              Text("Monday 9th")
                .frame(width: headerGeometry.size.width)

              Text("Tuesday 10th")
                .frame(width: headerGeometry.size.width)
            }
            .scrollTargetLayout()
          }
          .scrollTargetBehavior(.viewAligned)
          .introspect(.scrollView, on: .iOS(.v17, .v18)) {
            simultaneouslyScrollViewHandler.register(scrollView: $0)
          }
        }
      }

      ScrollView(showsIndicators: false) {
        HStack {
          LazyVStack {
            Text("00:00")
            Text("01:00")
            Text("02:00")
            Text("03:00")
            Text("04:00")
            Text("05:00")
          }
          .frame(width: 200)

          GeometryReader { dayGeometry in
            ScrollView(.horizontal, showsIndicators: false) {
              LazyHStack {
                LazyVStack {
                  Text("event 1")
                  Text("event 2")
                  Text("event 3")
                  Text("event 4")
                  Text("event 5")
                }
                .frame(width: dayGeometry.size.width)

                LazyVStack {
                  Text("event 1")
                  Text("event 2")
                  Text("event 3")
                  Text("event 4")
                  Text("event 5")
                }
                .frame(width: dayGeometry.size.width)
              }
              .scrollTargetLayout()
            }
            .scrollTargetBehavior(.viewAligned)
            .introspect(.scrollView, on: .iOS(.v17, .v18)) {
              simultaneouslyScrollViewHandler.register(scrollView: $0)
            }
          }
        }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions