Skip to content

Commit 3c93cbb

Browse files
cortinicopaolorotolo
authored andcommitted
Fix RTL bug on wrongly retained currentItem
1 parent c8f23fb commit 3c93cbb

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

appintro/src/main/java/com/github/appintro/AppIntroBase.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,13 @@ abstract class AppIntroBase : AppCompatActivity(), AppIntroViewPagerListener {
486486
putBoolean(ARG_BUNDLE_IS_SKIP_BUTTON_ENABLED, isSkipButtonEnabled)
487487
putBoolean(ARG_BUNDLE_IS_INDICATOR_ENABLED, isIndicatorEnabled)
488488

489-
putInt(ARG_BUNDLE_CURRENT_ITEM, pager.currentItem)
489+
// We can't use pager.currentItem as we need the current item that is RTL-invariant.
490+
val currentItem = if (isRtl) {
491+
fragments.size - pager.currentItem
492+
} else {
493+
pager.currentItem
494+
}
495+
putInt(ARG_BUNDLE_CURRENT_ITEM, currentItem)
490496
putBoolean(ARG_BUNDLE_IS_FULL_PAGING_ENABLED, pager.isFullPagingEnabled)
491497

492498
putSerializable(ARG_BUNDLE_PERMISSION_MAP, permissionsMap)

example/src/main/res/layout/item_intro.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515

1616
<TextView
1717
android:id="@+id/item_title"
18-
android:layout_width="match_parent"
18+
android:layout_width="0dp"
1919
android:layout_height="wrap_content"
2020
android:layout_gravity="center"
21+
android:layout_marginEnd="@dimen/base_grid_size"
22+
android:layout_marginRight="@dimen/base_grid_size"
2123
android:textAppearance="@style/TextAppearance.AppCompat.Title"
22-
app:layout_constraintEnd_toStartOf="parent"
24+
app:layout_constraintEnd_toStartOf="@id/item_button"
25+
app:layout_constraintStart_toStartOf="parent"
2326
app:layout_constraintTop_toTopOf="parent"
2427
tools:text="AppIntro Sample App" />
2528

0 commit comments

Comments
 (0)