Skip to content

Commit 4efc567

Browse files
Piotr Zawadzkizawadz88
authored andcommitted
Added an option to disable tab navigation (issue #73)
1 parent cb95f1f commit 4efc567

File tree

9 files changed

+81
-8
lines changed

9 files changed

+81
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,9 @@ For other examples, e.g. persisting state on rotation, displaying errors, changi
355355
| *ms_tabStepDividerWidth* | dimension or reference | The width of the horizontal tab divider used in tabs stepper type |
356356
| *ms_showBackButtonOnFirstStep* | boolean | Flag indicating if the Back (Previous step) button should be shown on the first step. False by default. |
357357
| *ms_errorColor* | color or reference | Error color in Tabs stepper |
358-
| *ms_showErrorStateEnabled* | boolean | Flag indicating whether to show the error state. Only available with 'tabs' type. False by default. |
359-
| *ms_showErrorStateOnBackEnabled*| boolean | Flag indicating whether to keep showing the error state when user moves back. Only available with 'tabs' type. False by default. |
358+
| *ms_showErrorStateEnabled* | boolean | Flag indicating whether to show the error state. Only applicable for 'tabs' type. False by default. |
359+
| *ms_showErrorStateOnBackEnabled*| boolean | Flag indicating whether to keep showing the error state when user moves back. Only applicable for 'tabs' type. False by default. |
360+
| *ms_tabNavigationEnabled* | boolean | Flag indicating whether step navigation is possible by clicking on the tabs directly. Only applicable for 'tabs' type. True by default. |
360361
| *ms_stepperLayoutTheme* | reference | Theme to use for even more custom styling of the stepper layout. It is recommended that it should extend @style/MSDefaultStepperLayoutTheme, which is the default theme used. |
361362

362363
### StepperLayout style attributes

material-stepper/src/main/java/com/stepstone/stepper/StepperLayout.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public void goToPrevStep() {
222222

223223
private boolean mShowErrorStateOnBackEnabled;
224224

225+
private boolean mTabNavigationEnabled;
226+
225227
@StyleRes
226228
private int mStepperLayoutTheme;
227229

@@ -337,10 +339,12 @@ public int getTabStepDividerWidth() {
337339
@Override
338340
@UiThread
339341
public void onTabClicked(int position) {
340-
if (position > mCurrentStepPosition) {
341-
onNext();
342-
} else if (position < mCurrentStepPosition) {
343-
setCurrentStepPosition(position);
342+
if (mTabNavigationEnabled) {
343+
if (position > mCurrentStepPosition) {
344+
onNext();
345+
} else if (position < mCurrentStepPosition) {
346+
setCurrentStepPosition(position);
347+
}
344348
}
345349
}
346350

@@ -436,6 +440,21 @@ public boolean isShowErrorStateOnBackEnabled() {
436440
return mShowErrorStateOnBackEnabled;
437441
}
438442

443+
/**
444+
* @return true if step navigation is possible by clicking on the tabs directly, false otherwise
445+
*/
446+
public boolean isTabNavigationEnabled() {
447+
return mTabNavigationEnabled;
448+
}
449+
450+
/**
451+
* Sets whether step navigation is possible by clicking on the tabs directly. Only applicable for 'tabs' type.
452+
* @param tabNavigationEnabled true if step navigation is possible by clicking on the tabs directly, false otherwise
453+
*/
454+
public void setTabNavigationEnabled(boolean tabNavigationEnabled) {
455+
mTabNavigationEnabled = tabNavigationEnabled;
456+
}
457+
439458
/**
440459
* Updates the error state in the UI.
441460
* It does nothing if showing error state is disabled.
@@ -621,6 +640,8 @@ private void extractValuesFromAttributes(AttributeSet attrs, @AttrRes int defSty
621640
mShowErrorStateOnBackEnabled = a.getBoolean(R.styleable.StepperLayout_ms_showErrorStateOnBack, false);
622641
mShowErrorStateOnBackEnabled = a.getBoolean(R.styleable.StepperLayout_ms_showErrorStateOnBackEnabled, mShowErrorStateOnBackEnabled);
623642

643+
mTabNavigationEnabled = a.getBoolean(R.styleable.StepperLayout_ms_tabNavigationEnabled, true);
644+
624645
mStepperLayoutTheme = a.getResourceId(R.styleable.StepperLayout_ms_stepperLayoutTheme, R.style.MSDefaultStepperLayoutTheme);
625646

626647
a.recycle();

material-stepper/src/main/res/values/attrs.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,18 @@ limitations under the License.
5555
<!-- DEPRECATED: Use ms_showErrorStateEnabled instead -->
5656
<attr name="ms_showErrorState" format="boolean" />
5757

58-
<!-- Flag indicating whether to show the error state. Only available with 'tabs' type. False by default. -->
58+
<!-- Flag indicating whether to show the error state. Only applicable for 'tabs' type. False by default. -->
5959
<attr name="ms_showErrorStateEnabled" format="boolean" />
6060

6161
<!-- DEPRECATED: Use ms_showErrorStateOnBackEnabled instead -->
6262
<attr name="ms_showErrorStateOnBack" format="boolean" />
6363

64-
<!-- Flag indicating whether to keep showing the error state when user moves back. Only available with 'tabs' type. False by default. -->
64+
<!-- Flag indicating whether to keep showing the error state when user moves back. Only applicable for 'tabs' type. False by default. -->
6565
<attr name="ms_showErrorStateOnBackEnabled" format="boolean" />
6666

67+
<!-- Flag indicating whether step navigation is possible by clicking on the tabs directly. Only applicable for 'tabs' type. True by default. -->
68+
<attr name="ms_tabNavigationEnabled" format="boolean" />
69+
6770
<!-- Theme to use for even more custom styling of the stepper layout.
6871
It is recommended that it should extend @style/MSDefaultStepperLayoutTheme, which is the default theme used.
6972
See StepperLayoutTheme below for a list of possible inner view styles to overwrite.

sample/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<activity android:name=".NoFragmentsActivity" />
3636
<activity android:name=".ProceedProgrammaticallyActivity"
3737
android:windowSoftInputMode="stateVisible"/>
38+
<activity android:name=".DisabledTabNavigationActivity" />
3839
<activity
3940
android:name=".CustomStepperLayoutThemeActivity"
4041
android:theme="@style/AppThemeDark" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Copyright 2017 StepStone Services
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package com.stepstone.stepper.sample;
18+
19+
public class DisabledTabNavigationActivity extends AbstractStepperActivity {
20+
21+
@Override
22+
protected int getLayoutResId() {
23+
return R.layout.activity_disabled_tab_navigation;
24+
}
25+
26+
}

sample/src/main/java/com/stepstone/stepper/sample/MainActivity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public void onProceedProgrammatically(View view){
118118
startActivity(new Intent(this, ProceedProgrammaticallyActivity.class));
119119
}
120120

121+
@OnClick(R.id.disabledTabNavigation)
122+
public void onDisabledTabNavigation(View view){
123+
startActivity(new Intent(this, DisabledTabNavigationActivity.class));
124+
}
125+
121126
@OnClick(R.id.customStepperLayoutTheme)
122127
public void onCustomStepperLayoutThemeWithTabs(View view){
123128
startActivity(new Intent(this, CustomStepperLayoutThemeActivity.class));
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.stepstone.stepper.StepperLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:id="@+id/stepperLayout"
5+
android:orientation="vertical"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
app:ms_stepperType="tabs"
9+
app:ms_tabNavigationEnabled="false" />

sample/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@
118118
android:layout_height="wrap_content"
119119
android:text="@string/proceed_programmatically" />
120120

121+
<Button
122+
android:id="@+id/disabledTabNavigation"
123+
android:layout_width="wrap_content"
124+
android:layout_height="wrap_content"
125+
android:text="@string/disabled_tab_navigation" />
126+
121127
<Button
122128
android:id="@+id/customStepperLayoutTheme"
123129
android:layout_width="wrap_content"

sample/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<string name="show_back_button">Show Back button on first step</string>
1818
<string name="no_fragments">No Fragment Stepper</string>
1919
<string name="proceed_programmatically">Proceed programmatically</string>
20+
<string name="disabled_tab_navigation">Disabled tab navigation</string>
2021
<string name="custom_stepperlayout_theme">Custom StepperLayout theme</string>
2122

2223
<string name="tab_title">Tab title</string>

0 commit comments

Comments
 (0)