marcosgriselli / SwipeableTabBarController

UITabBarController with swipe interaction between its tabs.
MIT License
1.54k stars 107 forks source link

setSwipeTabBarEnabled(enabled: Bool) conflicts with UIGesture #19

Closed HackShitUp closed 6 years ago

HackShitUp commented 7 years ago

Is it possible to traverse this protocol for a UIView instead of a UIViewController? I have a UITableViewCell with a horizontal scrolling UICollectionView in it and it seems to conflict with the UIPangesture (I'm assuming) so it swipes between the UITabBarController's view controllers instead of scrolling through the UICollectionView in the UITableViewCell.

marcosgriselli commented 7 years ago

@HackShitUp do you have a sample project I can check out? I might have a solution to test on this particular case but I don't have the time to build a demo example.

marcosgriselli commented 7 years ago

@HackShitUp any update?

HackShitUp commented 7 years ago

@marcosgriselli Sorry for the late response, I've been busy starting up. I'll try to share a sample project as soon as I can, and post the Git URL here.

HackShitUp commented 7 years ago

@marcosgriselli https://github.com/HackShitUp/SwipeIssue

marcosgriselli commented 7 years ago

I checked it out and this quick fix will be good until I come back home in a couple days.

On your extension TableViewController: UICollectionViewDataSource, UICollectionViewDelegate add

    override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        setTabBarSwipe(enabled: false)
    }

    override func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
        setTabBarSwipe(enabled: true)
    }

This will disable the SwipeableTabBarController interaction when using a UIScrollView and reactivate it when you finish using it.

I'll come up with a solution integrated to the library next week.

HackShitUp commented 7 years ago

@marcosgriselli Perfect, I completely forgot about the scroll view delegate methods. Thank you!

moazkh60 commented 6 years ago

@marcosgriselli I tried your solution and it sometimes work and sometimes doesn't. After a certain time the app gets stuck and the views start overlapping.

HackShitUp commented 6 years ago

@moazkh60 Are you customizing the tabBar?

moazkh60 commented 6 years ago

No but I have two collection view in my screen, one is horizontal and one is vertical, so I need to disable the swipe when my horizontal collection view is being scrolled. When I do this using the above mentioned methods of scrollView it works the first time and as soon as I lift the finger up and try again it's stuck. If I try to move to some other tab and come back the screen starts to overlap.

marcosgriselli commented 6 years ago

@moazkh60 Can you expand on the 'it's stuck' part? Do you mind building a simple demo project?

moazkh60 commented 6 years ago

Stuck like I can't scroll the collection view anymore or click on any item in the collection view but I am able to click other tabs at the tab bar and move to some other screen when I return back the swipe able controller starts to overlap the screens and now the screen that got stuck is just plain white because the view of that screen is now overlapped to some other screen. Ok I will try to replicate the issue in a sample project and let you know.

moazkh60 commented 6 years ago

@marcosgriselli I have replicated the issue. Please check my replicated issue project on GitHub using this link SwipeableTabBarController screen overLap issue replicated

marcosgriselli commented 6 years ago

Thanks @moazkh60. I'll be checking this tonight.

moazkh60 commented 6 years ago

Thanks. I will be waiting for your response.

moazkh60 commented 6 years ago

@marcosgriselli did you check?

marcosgriselli commented 6 years ago

@moazkh60 I was just checking it, the app crashes when trying to move to the second viewController on the SwipeableTabBar, there's something wrong with the Storyboard outlets. Can you fix them and push?

moazkh60 commented 6 years ago

@marcosgriselli I just cloned the repo and tried again the app is crashing on second screen because you forgot to install the pods. Please install the pods using pod Install and open the project using xcworkspace not xcproj

Thanks.

moazkh60 commented 6 years ago

I think you didn't download properly. Here is the link https://github.com/moazkh60/SwipeableTabBarController-ReplicatedIssue/blob/master/SwipeableTabBarController-ReplicatedIssue/SecondTabVC.swift

marcosgriselli commented 6 years ago

Got it, not sure why it wasn't appearing on the project. Ok so found a solution 🎉. Check it out:

img_2356 trim-3

I'll be updating the library during the next weekend when I have some extra time to work out a generic solution so I don't introduce any 'hacky fixes'.

Just as an exception you could edit the pod's SwipeInteractor's UIGestureRecognizerDelegate to look like this:

// MARK: - UIGestureRecognizerDelegate
extension SwipeInteractor: UIGestureRecognizerDelegate {

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
        if let collectionView = otherGestureRecognizer.view as? UICollectionView {
            if let flowLayout = collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
                if flowLayout.scrollDirection == .horizontal {
                    return false
                }
            }
        }
        if gestureRecognizer == panRecognizer {
            if let point = panRecognizer?.translation(in: panRecognizer?.view?.superview) {
                return fabs(point.x) < InteractionConstants.xTranslationForRecognition
            }
        }
        return true
    }
}
moazkh60 commented 6 years ago

The issue is resolved to some extent but it's still there. I think when I swipe fast then the screen starts to overlap. Try installing the issue app on mobile and do some stress testing moving horizontal scrolling on second screen and then moving between all the tabs using swipe gesture a bit fast. You will see the issue.

marcosgriselli commented 6 years ago

@moazkh60 You are right. This will need deeper revision as it's a complicated issue. It's triggered by UIPercentDrivenTransition calling a start transition method again before finishing the previous one. I'll go over it in the weekend.

moazkh60 commented 6 years ago

Thanks @marcosgriselli I will be waiting.

moazkh60 commented 6 years ago

@marcosgriselli any updates?

moazkh60 commented 6 years ago

@marcosgriselli did you resolve the issue yet ? Let me know if it gets resolved soon otherwise I would have no other option but to remove the library from my project.

marcosgriselli commented 6 years ago

Hi @moazkh60, I've been super busy with work and another library I released. I haven't had the time to look into this yet. I plan to fix this but I don't have an approximate milestone date. I'll keep the issue open to keep you or anyone else interested posted.

moazkh60 commented 6 years ago

@marcosgriselli I am still waiting for your update I am dependent on your library now. I know you might be busy but please try to find some time to resolve this issue. I would really appreciate it. Thanks for the effort and thanks for the awesome library.

umarhussain15 commented 6 years ago

When will you resolve this issue. I'm stuck in my development of app due to this issue. I have to disable several features. Kindly provide the fix. @marcosgriselli

moazkh60 commented 6 years ago

@marcosgriselli thanks for the update finally 👍. Now the issue is resolved to some extent. Whenever I run the app the first time and try to swipe immediately same issue of white screen occurs. But on the second run it works fine. Kindly look into that thanks.

marcosgriselli commented 6 years ago

@moazkh60 second run meaning you close the app and run it again? I have an idea to solve this. Are you convining version 1.0.10 and the code for supporting horizontal UICollectionView's from above?

moazkh60 commented 6 years ago

@marcosgriselli yes I close the app and run it again. No I am on a different page when my app starts, so horizontal UICollectionView is not above. Few points to be noted

  1. It happens if I run the app and immediately start to swipe. The screen get stuck and then suddenly the white screen appears just like before but this time all screens are white.
  2. If I click on the bottom tabs first and move through all the tabs. After that I start swiping the problem doesn't appear.
  3. I think that it's taking a bit of time to adjust with the layout that's why if I click on tabs and then swipe it works fine. I am not sure.
moazkh60 commented 6 years ago

@marcosgriselli any further updates?

marcosgriselli commented 6 years ago

I'm closing this issue as it drifted away from the original issue. I have more time to delicate to open source projects now so issues will be tackled a lot faster. @moazkh60 if you're still using this library feel free to create any new issue with a good description and we'll solve it :)