SwiftUIPager icon indicating copy to clipboard operation
SwiftUIPager copied to clipboard

[BUG] List inside Pager

Open smotched opened this issue 3 years ago • 4 comments
trafficstars

Describe the bug Lists inside the Pager can't be dragged, or two finger swiped on mac

To Reproduce Place a List inside a Pager

    Pager(page: page,
          data: items,
          id: \.self) { item in
      List {
        Text("List\(item)")
        Text("List\(item)")
      }
    }

Expected behavior

  • Swipeable with two fingers (ideal for Mac)
  • Press and drag to the next page (matches iOS)

Additional context Surprisingly arrow keys work pretty nicely (currently the only way to change pages)

smotched avatar Jul 18 '22 21:07 smotched

Hi @smotched , there are two things here:

  • Trackpad events are not natively supported in SwiftUI as far as I can see. Check out #286 for more info
  • List inside a Pager isn't working in iOS. For this, have you tried using .pagingPriority(.simultaneous)? The scenario is tricky because there are two elements here expecting a drag.

Btw, the keys do work because those are implemented differently, onMoveCommand if I remember correctly.

fermoya avatar Jul 19 '22 22:07 fermoya

Hey @fermoya , I think you meant macOS but yeah even with .pagingPriority(.simultaneous) it unfortunately doesn't work. Could it be a macOS 13 thing maybe? are you getting anything on your side with the basic example above?

sidenote: ScrollView works nicely as well.

smotched avatar Jul 20 '22 01:07 smotched

@smotched I see what you mean. Not sure why but in iOS works fine. I'll investigate to solve it.

In any case, it seems to me you're more interested in the trackpad option. It doesn't seem there's SwifUI natively built-in option to listen to this kind of event, all I find follows this approach. I'm not interested in anything that's not native. One option would be to create a view that uses that approach and then moves Pager when desired by using pageOffset modifier

fermoya avatar Jul 20 '22 10:07 fermoya

Thanks @fermoya we may have to file a feedback with Apple since like you said it works fine on iOS. I don't see why it shouldn't work if it works with ScrollView unless there's an underlying issue in how List is implemented on mac that's breaking your implementation.

Nevertheless thanks for looking into it!

smotched avatar Jul 20 '22 16:07 smotched