xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.97k stars 1.33k forks source link

When pager loads for the first time view in first childViewController leaves space from both side for the first time. #776

Open NikhilGangurde opened 4 years ago

NikhilGangurde commented 4 years ago

when pager loads tableview in the first child view controller leaves space from both sides but if I switched tabs then it acquires the screen as I wanted.

here is the screenshot of a simulator for understanding: Simulator Screen Shot - iPhone 6s - 2019-12-30 at 12 53 26

And after switching tabs and as expected: Simulator Screen Shot - iPhone 6s - 2019-12-30 at 12 56 57

my whole setup is normal tableview has nothing done in that its just a view and here is XKPager setup

    settings.style.buttonBarBackgroundColor = appBlueColor
    settings.style.buttonBarItemBackgroundColor = appBlueColor

    settings.style.selectedBarBackgroundColor = appBrownColor

    settings.style.buttonBarItemFont = UIFont.appRegularFontWith(size: 16)

    settings.style.selectedBarHeight = 4.0
    settings.style.buttonBarMinimumLineSpacing = 0

    settings.style.buttonBarItemTitleColor = .black
    settings.style.buttonBarItemsShouldFillAvailableWidth = true

    settings.style.buttonBarLeftContentInset = 0
    settings.style.buttonBarRightContentInset = 0

    changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
        guard changeCurrentIndex == true else { return }
        oldCell?.label.textColor = self?.oldCellColor
        oldCell?.label.font = UIFont.appRegularFontWith(size: 16)

        newCell?.label.textColor = .white
        newCell?.label.font = UIFont.appMediumFontWith(size: 16)
    }

   override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
    let child1 = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "childViewController1")

    let child2 = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "childViewController1")

    let child3 = UIStoryboard(name: "Home", bundle: nil).instantiateViewController(withIdentifier: "childViewController1")

    return [child1, child2, child3]
}

Xcode version: 11.2.1 swift version: 5 ios deployment target: 10.0 XLPager updated

Panchal-Harsh-98 commented 4 years ago

I also have a similar issue but in my case the view controller overflows the container.

As a temporary solution I reload the XLPager in the viewDidAppear() method using self.reloadPagerTabStripView() but this results in a repetitive API call which is very disturbing 😔😔

OmarTawashi commented 4 years ago

I also have a similar issue , and use self.reloadPagerTabStripView()

NikhilGangurde commented 4 years ago

@harshpanchal-silverwing rather than including self.reloadPagerTabStripView() in viewDidAppear() reload you pagerstripview in viewWillAppear like

override func viewWillAppear(_ animated: Bool) {
    setupNav()
    self.reloadPagerTabStripView()
}

this will solve the repetitive API call issues. Thanks for the solution.

chelvinn commented 4 years ago

Managed to solve the issue on my side by using this,

DispatchQueue.main.async { self.moveToViewController(at: 0) }