feat: Support infinite scroll on home screen (#5807)

* scrolling

* removed logging from the scrolling part in pagedview

* added toggle for infinite scrolling

* strings

* scrolling preferences moved

* string fix
This commit is contained in:
ELY M.
2025-12-02 20:54:40 -06:00
committed by GitHub
parent deca6d910e
commit 736e6c85d6
4 changed files with 29 additions and 9 deletions

View File

@@ -585,7 +585,10 @@
<string name="wallpaper_depth_effect_label">Wallpaper depth effect</string>
<string name="wallpaper_depth_effect_description">Zoom in and out of the wallpaper when transitioning between areas of the launcher</string>
<string name="show_sys_ui_scrim">Top shadow</string>
<string name="infinite_scrolling_label">Infinite scrolling</string>
<string name="infinite_scrolling_description">Swipe to loop between the first and last pages</string>
<string name="home_screen_grid">Home screen grid</string>
<string name="home_screen_lock">Lock home screen</string>
<string name="home_screen_unlock">Unlock home screen</string>

View File

@@ -63,6 +63,7 @@ class PreferenceManager private constructor(private val context: Context) :
val windowCornerRadius = IntPref("pref_windowCornerRadius", 80, recreate)
val autoLaunchRoot = BoolPref("pref_autoLaunchRoot", false)
val wallpaperScrolling = BoolPref("pref_wallpaperScrolling", true)
val infiniteScrolling = BoolPref("pref_infiniteScrolling", false)
val enableDebugMenu = BoolPref("pref_enableDebugMenu", false)
val customAppName = object : MutableMapPref<ComponentKey, String>("pref_appNameMap", reloadGrid) {
override fun flattenKey(key: ComponentKey) = key.toString()

View File

@@ -89,6 +89,11 @@ fun HomeScreenPreferences(
adapter = prefs2.doubleTapGestureHandler.getAdapter(),
label = stringResource(id = R.string.gesture_double_tap),
)
SwitchPreference(
prefs.infiniteScrolling.getAdapter(),
label = stringResource(id = R.string.infinite_scrolling_label),
description = stringResource(id = R.string.infinite_scrolling_description),
)
}
PreferenceGroup(heading = stringResource(id = R.string.minus_one)) {
val feedAvailable = OverlayCallbackImpl.minusOneAvailable(LocalContext.current)

View File

@@ -65,6 +65,7 @@ import com.android.launcher3.views.ActivityContext;
import java.util.ArrayList;
import java.util.function.Consumer;
import app.lawnchair.preferences.PreferenceManager;
import app.lawnchair.ui.StretchEdgeEffect;
/**
@@ -85,6 +86,8 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
private static final float SIGNIFICANT_MOVE_THRESHOLD = 0.4f;
private static final float MAX_SCROLL_PROGRESS = 1.0f;
private PreferenceManager prefs = PreferenceManager.getInstance(getContext());
private boolean mFreeScroll = false;
@@ -1421,19 +1424,27 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
// test for a large move if a fling has been registered. That is, a large
// move to the left and fling to the right will register as a fling to the right.
boolean infiniteScroll = prefs.getInstance(getContext()).getInfiniteScrolling().get();
if (((isSignificantMove && !isDeltaLeft && !isFling) ||
(isFling && !isVelocityLeft)) && mCurrentPage > 0) {
finalPage = returnToOriginalPage
? mCurrentPage : mCurrentPage - getPanelCount();
runOnPageScrollsInitialized(
() -> snapToPageWithVelocity(finalPage, velocity));
} else if (((isSignificantMove && isDeltaLeft && !isFling) ||
(isFling && isVelocityLeft)) &&
mCurrentPage < getChildCount() - 1) {
finalPage = returnToOriginalPage
? mCurrentPage : mCurrentPage + getPanelCount();
runOnPageScrollsInitialized(
() -> snapToPageWithVelocity(finalPage, velocity));
() -> snapToPageWithVelocity(finalPage, velocity));
} else if (((isSignificantMove && isDeltaLeft && !isFling) || (isFling && isVelocityLeft)) && mCurrentPage < getChildCount() - 1) {
finalPage = returnToOriginalPage ? mCurrentPage : mCurrentPage + getPanelCount();
runOnPageScrollsInitialized(() -> snapToPageWithVelocity(finalPage, velocity));
} else if (mCurrentPage == getChildCount() - 1 && infiniteScroll) {
finalPage = returnToOriginalPage ? mCurrentPage : 0;
snapToPageWithVelocity(finalPage, velocity);
} else if (mCurrentPage == 0 && infiniteScroll) {
finalPage = returnToOriginalPage ? mCurrentPage : getChildCount() - 1;
snapToPageWithVelocity(finalPage, velocity);
} else {
runOnPageScrollsInitialized(this::snapToDestination);
}