VakhoKontridze / VComponents

VComponents is a SwiftUI collection that contains reusable UI components
MIT License
782 stars 36 forks source link

VDynamicPagerTabView problem #14

Open Cavidan998 opened 6 days ago

Cavidan998 commented 6 days ago

Hi,

when i add button inside VDynamicPagerTabView content, button's click work only after long click, i research and find that this because of changing tabs with left and right scroll

Screenshot 2024-10-01 at 09 33 28

in this case forgot password work after long press not with tap.

and i think if we have disable option for changing tabs with scroll, issue will be resolved.

VakhoKontridze commented 6 days ago

Hey,

I'm not exactly sure what the problem is. VDynamicPagerTabView is implemented using native TabView with page configuration. It shouldn't disable button clicks.

I used the following snippet to test:

private enum WeekDay: Int, Hashable, Identifiable, CaseIterable {
    case monday, tuesday, wednesday, thursday, friday, saturday, sunday

    var id: Int { rawValue }

    var title: String { .init(describing: self).capitalized }

    var color: Color {
        switch rawValue.quotientAndRemainder(dividingBy: 3).remainder {
        case 0: Color.red
        case 1: Color.green
        case 2: Color.blue
        default: fatalError()
        }
    }
}

@State private var selection: WeekDay = .thursday

var body: some View {
    VDynamicPagerTabView(
        selection: $selection,
        data: WeekDay.allCases,
        tabItemTitle: { $0.title },
        content: { tab in
            ZStack(content: {
                tab.color.opacity(0.3)

                Button(tab.title, action: {
                    print("Clicked")
                })
            })
        }
    )
}

Scrolling worked. And both, buttons taps and long presses, worked as well.

https://github.com/user-attachments/assets/667e7267-3cc5-4199-bf6c-728956d85d90

Maybe you are doing something incorrectly?

As for API for disabling the scroll, I'm not aware of any ways of doing it with TabView. It can be achieved with ScrollView in iOS 17.0. But currently, package supports 16.0. So that API will come next year.

Cavidan998 commented 5 days ago

this is interesting. In my case when i touch button , this first touch understood like scrolling left or right. But after long press on button, i saw button get clicked. Without VDynamicPagerTabView everything works fine.

Cavidan998 commented 4 days ago

VDynamicPagerTabView( uiModel: .register, selection: $viewModel.selectionTab, data: RegisterTab.allCases, tabItemTitle: { loginTab in viewModel.pagerTitleContent(loginTab: loginTab) }, content: { loginTab in pagerContent(loginTab: loginTab) .layoutPriority(1) } ) .padding(.vertical, .p16)

.layoutPriority(1) after this sometimes work and sometimes not working

VakhoKontridze commented 4 days ago

I'll look into ScrollView API over the weekend. I can probably create an alternate implementation for iOS 17.0, that exposes new functionality with isScrollEnabled property in the UI model.

Cavidan998 commented 3 days ago

Yes, i created custom pager , after you change i will uncomment my old code. Thanks)

VakhoKontridze commented 3 days ago

I've added an alternate implementation.

Check out dev branch, and try using component with the following UI model:

VDynamicPagerTabView(
    uiModel: {
        var uiModel: VDynamicPagerTabViewUIModel = .init()
        uiModel.isTabViewScrollingEnabled = false
        return uiModel
    }(),
    ...
)

Let me know if it works.