0

I have basic tabview on my screen. TabView has 4-5 contents and a timer manage it for move the next item. There is no issue until now.

Then user can move the pages left or right when user make this reaction I need to stop timer and start again.

Drag gesture working but I can not Manuel change in tabView , kindly advise ?

 TabView(selection: $index) {
                ForEach(0..<data.count, id: \.self) { item in
                        PageContent(model: data[item])
                }
            }
            .gesture(DragGesture(minimumDistance: 0)
                .onChanged { _ in
                    print(" changing")
                }
                .onEnded { _ in  print(" end") }
            )
            .tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
Metin Atalay
  • 1,375
  • 18
  • 28

1 Answers1

0

Rather than detecting the user's drag gesture, you could observe index for changes and reset your timer whenever that happens.

TabView(selection: $index) {
  ForEach(0..<data.count, id: \.self) { item in
    PageContent(model: data[item])
  }
}
.onChangeOf(index) { _ in
  // Reset your timer here
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
EmilioPelaez
  • 18,758
  • 6
  • 46
  • 50
  • this is not good solution because if user on first page in tabView and he/she move continually left (zero) that time index not change and I can not stop timer – Metin Atalay Mar 16 '23 at 10:37
  • Right, it doesn't cover all edge cases, but `TabView` is not designed to be used that way, so there isn't a lot of flexibility. You could try using Preference Keys, or create your custom implementation of `TabView`. – EmilioPelaez Mar 16 '23 at 10:43
  • still thank you for your advice. We also had a lot of problems with RTL when we didn't use tabView. – Metin Atalay Mar 16 '23 at 10:47