Skip to content

Commit 1d07427

Browse files
authored
Merge pull request #13 from stepstone-tech/bugfix/issue-12
Scroll to current tab on tab selection
2 parents 80faadb + be13d98 commit 1d07427

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Quoting the [documentation](https://www.google.com/design/spec/components/steppe
1111
1212
## Download (from JCenter)
1313
```groovy
14-
compile 'com.stepstone.stepper:material-stepper:1.0.1'
14+
compile 'com.stepstone.stepper:material-stepper:1.0.2'
1515
```
1616

1717
## Supported steppers

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919

2020
POM_GROUP_ID=com.stepstone.stepper
2121
POM_ARTIFACT_ID=material-stepper
22-
POM_VERSION=1.0.1
22+
POM_VERSION=1.0.2

material-stepper/src/main/java/com/stepstone/stepper/internal/TabsContainer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import android.view.LayoutInflater;
2828
import android.view.View;
2929
import android.widget.FrameLayout;
30+
import android.widget.HorizontalScrollView;
3031
import android.widget.LinearLayout;
3132

3233
import com.stepstone.stepper.R;
@@ -68,6 +69,10 @@ public void onTabClicked(int position) {
6869

6970
private int mDividerWidth = StepperLayout.DEFAULT_TAB_DIVIDER_WIDTH;
7071

72+
private final int mContainerLateralPadding;
73+
74+
private HorizontalScrollView mTabsScrollView;
75+
7176
private LinearLayout mTabsInnerContainer;
7277

7378
private TabItemListener mListener = TabItemListener.NULL;
@@ -101,8 +106,10 @@ public TabsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
101106

102107
a.recycle();
103108
}
109+
mContainerLateralPadding = context.getResources().getDimensionPixelOffset(R.dimen.ms_tabs_container_lateral_padding);
104110

105111
mTabsInnerContainer = (LinearLayout) findViewById(R.id.ms_stepTabsInnerContainer);
112+
mTabsScrollView = (HorizontalScrollView) findViewById(R.id.ms_stepTabsScrollView);
106113
}
107114

108115
public void setUnselectedColor(@ColorInt int unselectedColor) {
@@ -146,6 +153,9 @@ public void setCurrentStep(int newStepPosition) {
146153
boolean done = i < newStepPosition;
147154
final boolean current = i == newStepPosition;
148155
childTab.updateState(done, current);
156+
if (current) {
157+
mTabsScrollView.smoothScrollTo(childTab.getLeft() - mContainerLateralPadding, 0);
158+
}
149159
}
150160
}
151161

material-stepper/src/main/res/layout/ms_tabs_container.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

55
<HorizontalScrollView
6+
android:id="@+id/ms_stepTabsScrollView"
67
android:layout_width="wrap_content"
78
android:layout_height="wrap_content"
89
android:layout_gravity="center_horizontal"

0 commit comments

Comments
 (0)