Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 2 back button in RTL layout

I'm going to start an Ionic 2 app, and it should be in Arabic language, so i need to use RTL layout, i chose the side menu template

configuring the app to RTL by the following line changed every thing's direction perfectly except the back button should point to the right direction

<ion-nav #content [root]="rootPage" dir="rtl"></ion-nav>

the navbar now looks like this

enter image description here

Isn't there any kind of fix until Ionic team gives attention to RTL related issues?

like image 623
Mohamed Ali Avatar asked May 26 '26 08:05

Mohamed Ali


1 Answers

Instead of setting the dir attribute in the ion-nav, you can use the platform to set the alignment to RTL (docs)

private setProperAligment(): void {

    if (this.selectedLanguage.rtl) {
        this.platform.setDir('rtl', true);
        // ...
    } else {
        this.platform.setDir('ltr', true);
        // ...
    }
}

This will add the dir="rtl" attribute to the html tag of your app. Just like you said, Ionic team is working on fixing the issue with the back button, so in the meantime, you can add this css style rule in the app.scss file:

html[dir="rtl"] {
    .back-button-icon.icon-md.back-button-icon-md.ion-md-arrow-back {
        transform: rotate(180deg);
    }

    .back-button-icon.icon-ios.back-button-icon-ios.ion-ios-arrow-back {
        transform: rotate(180deg);
        padding: 0 5px;
    }
}
like image 183
sebaferreras Avatar answered May 30 '26 04:05

sebaferreras



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!