AppIntro / AppIntro

Make a cool intro for your Android app.
Apache License 2.0
10.52k stars 1.77k forks source link

RTL layout issue after changing the app language manually #1005

Closed AlirezaIvaz closed 1 year ago

AlirezaIvaz commented 2 years ago

šŸ› Describe the bug

When the default language of the system is Persian (RTL), the intro is displayed without any problems and correctly. But when the language of the system is not Persian (e.g. English) and we change the language of the app to Persian manually, the intro is still LTR and the slide shows the beginning and the end incorrectly. If you pay attention to the screenshots, you will understand better. I have tried all the old and new methods but in all of them this problem persists. Of course, there are no problems with other activities and they are displayed correctly.

šŸ’£ Steps to reproduce

Adding this code in activity:

init {
    val locale = Locale("fa", "IR")
    val configuration = Configuration()
    Locale.setDefault(locale)
    configuration.setLocale(locale)
    this.applyOverrideConfiguration(configuration)
}

This code works properly in newer versions of Android, but I does not tested it on Android N and older.

Of course, I tried many other codes, and this was the simplest code available.

šŸ“· Screenshots

This screenshot is when the language of the system itself is Persian:

02

But this screenshot is when the system language is English and I manually changed the app language to Persian

01

šŸ“± Tech info

cortinico commented 2 years ago

Thanks for reporting this. I have to look closely into this problem. If anyone has bandwidth to look into it and send a fix would be really appreaciated šŸ™

Fabi755 commented 2 years ago

I think it's similar to #926. There the configuration changes not available at the already created fragment. I will have a look and try to fix it next days.

HashirLabs commented 1 year ago

almost a year, any fixes on this would be appreciated

Fabi755 commented 1 year ago

Yes you are right! I already tried to find the problem, but not sure where the problem for this behavior is. Maybe you have any suggestion for this? If not you need to wait ;-)

cortinico commented 1 year ago

As mentioned, we're welcome to receive a PR with this fix šŸ™

HashirLabs commented 1 year ago

Hi

I had to add a hack which used to work earlier before android N, fortunately that works even now, I added below code to my activity attachBaseContext method and it all started working

 @Override
    protected void attachBaseContext(Context newBase) {

        Resources resources = getApplicationContext().getResources();
        Configuration configuration = new Configuration(resources.getConfiguration());

        Locale locale = new Locale(LocaleUtil.getLanguage(), "");
        configuration.setLocale(locale);
        getApplicationContext().getResources().updateConfiguration(configuration, getApplicationContext().getResources().getDisplayMetrics());
    }

The real problem is with the below code in AppIntroBase.kt which uses application context for locale detection while as per android, we should use base context or say Activity context to detect the locale

 internal val isRtl: Boolean
        get() = LayoutUtil.isRtl(applicationContext)

Hope this helps

Fabi755 commented 1 year ago

I think your hints are the missing thing. I will have a look again, thank you!