oleksandrbalan / programguide

Lazy layout to display program guide data on the two directional plane.
Apache License 2.0
40 stars 7 forks source link

Auto scroll when at end of grid? #2

Closed techker closed 1 year ago

techker commented 1 year ago

is there a way to have autoscroll when at end of page without click?For Tv.

Thx

oleksandrbalan commented 1 year ago

I am not sure what do you mean with autoscroll at end of page?

Maybe you are interesting in observing the scroll state?

If so, you could check state.minaBoxState.translate property, which holds the observable translation of the program guide. Be aware to wrap it inside derivedStateOf, as translation may change frequently when user scrolls in the layout. For example to conditionally show next button when user scrolls near (48dp) the right side of the layout you may use this code:

val buttonVisibilityThreshold = LocalDensity.current.run { 48.dp.toPx() }
val showNext by remember {
    derivedStateOf {
        val translate = state.minaBoxState.translate
        if (translate == null) {
            false
        } else {
            translate.maxX - translate.x < buttonVisibilityThreshold
        }
    }
}
if (showNext) { ... }

Check ProgramGuideStateScreen where buttons prev / next are shown / hidden according to the scroll state.

https://github.com/oleksandrbalan/programguide/assets/20944869/d9bcf8c6-f457-4b98-90b1-1fedca61c8b1

techker commented 1 year ago

good, the issue is i want to mek it like a real eog.no arrows when i get to the edge if the screen to leap to next rows. instead when you scroll it moves like if it was endless.

il try out the code to see.Thx!

On Mon, Jun 5, 2023, 4:26 p.m. Oleksandr Balan @.***> wrote:

I am not sure what do you mean with autoscroll at end of page?

Maybe you are interesting in observing the scroll state?

If so, you could check state.minaBoxState.translate property, which holds the observable translation of the program guide. Be aware to wrap it inside derivedStateOf, as translation may change frequently when user scrolls in the layout. For example to conditionally show next button when user scrolls near (48dp) the right side of the layout you may use this code:

val buttonVisibilityThreshold = LocalDensity.current.run { 48.dp.toPx() }val showNext by remember { derivedStateOf { val translate = state.minaBoxState.translate if (translate == null) { false } else { translate.maxX - translate.x < buttonVisibilityThreshold } } }if (showNext) { ... }

Check ProgramGuideStateScreen https://github.com/oleksandrbalan/programguide/blob/main/demo/src/main/java/eu/wewox/programguide/demo/screens/ProgramGuideStateScreen.kt where buttons prev / next are shown / hidden according to the scroll state.

https://github.com/oleksandrbalan/programguide/assets/20944869/d9bcf8c6-f457-4b98-90b1-1fedca61c8b1

— Reply to this email directly, view it on GitHub https://github.com/oleksandrbalan/programguide/issues/2#issuecomment-1577427993, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOFGYRWZGR3ZMSKPGWISRLXJY6I3ANCNFSM6AAAAAAY27T7IA . You are receiving this because you authored the thread.Message ID: @.***>