Xlpagertabstrip: Right to left support

Created on 4 Dec 2016  路  20Comments  路  Source: xmartlabs/XLPagerTabStrip

Hi, I just added pager tab strip into one of my controllers and my app local is RTL but the scroll view does not work correctly and since tabs are populated from right to left but controllers populated from left to the right.
To test that just change app default language to one of the RTL languages such as Arabic ,Farsi or Hebrew

issue help wanted moderate

Most helpful comment

This is not a proper solution but after way too many hours trying to solve this problem, this actually solved it.
Add these lines inside viewDidLoad method in PagerTabStripViewController

    if #available(iOS 9.0, *) {
        if UIView.userInterfaceLayoutDirection(for: view.semanticContentAttribute) == .rightToLeft {
           print("arabic")
            containerView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
            for controller in viewControllers
            {
                controller.view.transform =  CGAffineTransform(rotationAngle: CGFloat(Double.pi));

            }
        }
        else
        {
            print("English")
        }
    } else {
        // Fallback on earlier versions
    }

All 20 comments

Hello I changed to espa帽ol and works perfectly, Can you share the code?

Isn't espa帽ol a LTR language? I meant for occasions where view direction changes (mirror) to right to left.

I will check for LTR Language(Arabic) and see if it works

In summary the problem is the tabs works correctly but the scroll view still populate view from left to the right so the rightmost tab show the leftmost view and so on ...

@hrsalehi Do you have time to look at it and find out a solution?

try setting your main ScrollView for PagerTabStrip i.e(container view) view semantic to : Force-Right-To-Left and see if it solves the problem
screen shot 2017-02-14 at 4 33 02 pm

Setting force Right-to-Left semantic on the containerView (UIScrollView) did not solve the issue 馃憥 Any suggestion that might fix this issue please?

@santiagofm Do you think anything could be done on this one please?

One solution is to reverse the tabs array before setting it to the controller @musbaalbaki

Hi hrsalehi,
Do you solve this issue?

Thank you

Thanks @mohammadghk, that is actually what I ended up doing. However I am still looking for a cleaner approach using the native iOS RTL support

since I am using autolayout, the tabs section automatically adjusted in RTL language. Now the problem I am facing is that the view controllers slide in from right side in Arabic which is basically opposite.

hi,
I have the same problem. Is it a solution
Thank you

This is not a proper solution but after way too many hours trying to solve this problem, this actually solved it.
Add these lines inside viewDidLoad method in PagerTabStripViewController

    if #available(iOS 9.0, *) {
        if UIView.userInterfaceLayoutDirection(for: view.semanticContentAttribute) == .rightToLeft {
           print("arabic")
            containerView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
            for controller in viewControllers
            {
                controller.view.transform =  CGAffineTransform(rotationAngle: CGFloat(Double.pi));

            }
        }
        else
        {
            print("English")
        }
    } else {
        // Fallback on earlier versions
    }

This is not a proper solution but after way too many hours trying to solve this problem, this actually solved it.
Add these lines inside viewDidLoad method in PagerTabStripViewController

    if #available(iOS 9.0, *) {
        if UIView.userInterfaceLayoutDirection(for: view.semanticContentAttribute) == .rightToLeft {
           print("arabic")
            containerView.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi))
            for controller in viewControllers
            {
                controller.view.transform =  CGAffineTransform(rotationAngle: CGFloat(Double.pi));

            }
        }
        else
        {
            print("English")
        }
    } else {
        // Fallback on earlier versions
    }

Thanks

I used @AdnanMajeed06 solution by adding the transform function in ViewDidLoad after super.viewDidLoad and without reversing the tabs array by extending UICollectionViewFlowLayout
like so:

extension UICollectionViewFlowLayout {

    override open var flipsHorizontallyInOppositeLayoutDirection: Bool {
        return true
    }

    override open var developmentLayoutDirection: UIUserInterfaceLayoutDirection {
        return UIUserInterfaceLayoutDirection.rightToLeft
    }
}

The tabs start from right to left and the scrollview direction is working like it supoosed to do in RTL

I ended up with another similar solution, which fixes the unexpected rotation if implemented using @AdnanMajeed06 solution.

My solution:

// Add at the end of `viewDidLoad` of `PagerTabStripViewController`
if UIView.userInterfaceLayoutDirection(for: view.semanticContentAttribute) == .rightToLeft {
    containerView.transform = CGAffineTransform(scaleX: -1, y: 1)
    for controller in viewControllers {
        controller.view.transform = CGAffineTransform(scaleX: -1, y: 1)
    }
}

It works fine with RTL and LTR

Nothing works for me and this bug is still open, any new solution here?

Any solution for this issue

stuck in the same issue ...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexanderkhitev picture alexanderkhitev  路  4Comments

bishalg picture bishalg  路  5Comments

andrewabdalla picture andrewabdalla  路  6Comments

pramodshukla1011 picture pramodshukla1011  路  3Comments

emrecanozturk picture emrecanozturk  路  5Comments