Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): Fixes TabLayout gravity when changing orientation #10687

Merged
merged 6 commits into from
Mar 25, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -6,11 +6,11 @@
*/
package ti.modules.titanium.ui.widget.tabgroup;

import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.graphics.Rect;
import android.support.design.widget.TabLayout;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

Expand Down Expand Up @@ -90,6 +90,17 @@ protected void onLayout(boolean hasChanged, int left, int top, int right, int bo
super.onLayout(hasChanged, left, top, right, bottom);
insetsProvider.setTopBasedOn(this);
}

@Override
protected void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
} else if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
mTabLayout.setTabGravity(TabLayout.GRAVITY_CENTER);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit-pick. You can get rid of the mTabLayout. part since you're overriding the TabLayout class' onConfigurationChanged() method. The rest is fine. Nice and simple solution. 👍

};
this.mTabLayout.setFitsSystemWindows(true);

Expand Down