Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using rotaryWithScroll and onRotaryInputAccumulatedWithFocus simultaneously #2112

Open
Pezcraft opened this issue Mar 11, 2024 · 5 comments
Open

Comments

@Pezcraft
Copy link

onRotaryInputAccumulatedWithFocus does nothing when rotaryWithScroll is used too. So what's the best option to react to scrolling events?

ScalingLazyColumn(
    modifier = Modifier
        .fillMaxSize()
        .rotaryWithScroll(columnState, focusRequester)
        .onRotaryInputAccumulatedWithFocus(focusRequester) {
            handleBlackscreen()
        },
    state = columnState.state
) {
    // ...
}
@yschimke
Copy link
Collaborator

They're both have the same input. So the can't. You will need to implement this yourself.

What are you wanting to happen?

@Pezcraft
Copy link
Author

I want to reset a CountDownTimer whenever the user interacts with the app which includes scrolling.

@yschimke
Copy link
Collaborator

You will need to look at the implementations of those and use some of the lower level APIs. if you make a sample screen, I can more easily suggest a change.

@Pezcraft
Copy link
Author

@OptIn(ExperimentalHorologistApi::class, ExperimentalWearFoundationApi::class)
@Composable
fun SampleScreen(
    modifier: Modifier = Modifier,
) {
    val columnState = rememberColumnState()
    val focusRequester = rememberActiveFocusRequester()

    var showBlackScreenNow by remember { mutableStateOf(false) }

    val screenTimeout: CountDownTimer = object : CountDownTimer(5000, 1000) {
        override fun onTick(millisUntilFinished: Long) {}
        override fun onFinish() {
            showBlackScreenNow = true
        }
    }

    Scaffold(modifier = modifier) {
        ScalingLazyColumn(
            modifier = Modifier
                .fillMaxSize()
                .rotaryWithScroll(columnState, focusRequester)
                .onRotaryScrollEvent {
                    if (showBlackScreenNow) {
                        showBlackScreenNow = false
                    }
                    screenTimeout.cancel()
                    screenTimeout.start()
                    true
                },
            state = columnState.state
        ) {
            item { Text(text = "...") }
        }

        if (showBlackScreenNow) {
            Column(
                modifier = Modifier
                    .fillMaxWidth()
                    .fillMaxHeight()
                    .wrapContentSize(Alignment.Center)
                    .clickable {
                        if (showBlackScreenNow) {
                            showBlackScreenNow = false
                        }
                        screenTimeout.cancel()
                        screenTimeout.start()
                    },
            ) {
                Box(
                    modifier = Modifier
                        .fillMaxWidth()
                        .fillMaxHeight()
                        .clip(RectangleShape)
                        .background(Color.Black, RectangleShape)
                )
            }
        }
    }
}

@yschimke
Copy link
Collaborator

Thanks, I'll take a look. But it might be a couple of days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants