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

ToolbarState expand(), collapse() and scroll not working when toolbar's content is set with delay #55

Open
alperenbabagil opened this issue Jul 19, 2022 · 6 comments
Labels
api Improvement of existing library contracts that may break backwards compatibility

Comments

@alperenbabagil
Copy link

Hello, I can't expand or collapse the toolbar programmatically. It works nicely when I scroll a lazyColumn inside it but
collapsingToolbarScaffoldState.toolbarState.expand() or collapsingToolbarScaffoldState.toolbarState.collapse() never works. I know these are in experimental state, so decided to scroll it manually but it is not working either. I will share my code below and any help would be much appreciated.

val collapsingToolbarScaffoldState = rememberCollapsingToolbarScaffoldState()

CollapsingToolbarScaffold(
        state = collapsingToolbarScaffoldState, 
        toolbar = {
            basePageComposableParams.collapsableToolbarContent.value.invoke()
        },
        modifier = Modifier,
        scrollStrategy = ScrollStrategy.EnterAlways,
    ) {
        Scaffold(
            floatingActionButton = basePageComposableParams.floatingActionButtonContent.value
        ) {
            ModalBottomSheetLayout(
                modifier = Modifier,
                sheetState = sheetState,
                sheetContent = {
                    basePageComposableParams.bottomSheetContent.value.invoke()
                }) {
                content()
            }
        }
    }

I call the expand and collapse functions in an onClick callback of a FAB

val crScope = rememberCoroutineScope()
        floatingActionButtonContent.value = @Composable {
            FloatingActionButton(
                onClick = {
                    crScope.launch {
                        focusRequester.requestFocus()
                        collapsingToolbarScaffoldState.toolbarState.expand()
                    }
                },
            ) {
                Icon(Icons.Filled.Search, contentDescription = "search")
            }
        }
@onebone
Copy link
Owner

onebone commented Jul 19, 2022

expand() and collapse() works fine on my mimicked sample that I wrote, can you check that expand() is called?

I do not know how your code is structured, if the coroutine scope is somehow canceled before the floating button is clicked then it might not be called.

@alperenbabagil
Copy link
Author

expand() and collapse() works fine on my mimicked sample that I wrote, can you check that expand() is called?

I do not know how your code is structured, if the coroutine scope is somehow canceled before the floating button is clicked then it might not be called.

Thanks for the answer. The problem was I was setting the content of the toolbar after setting the content of the body. I've fixed it by doing 2 things: First I had to add a dummy 1.dp spacer to the toolbar. Second I set the toolbar content before body content. It changed my structure a little bit and made it uglier, I would make it the old way in the future :D
You can close the issue if you don't think there is no need for action.

@onebone
Copy link
Owner

onebone commented Aug 1, 2022

I will leave it open for now. Actually I didn't think of the case where the layout is resolved with delay, maybe I should deal with it anyway :D

@onebone onebone added the api Improvement of existing library contracts that may break backwards compatibility label Aug 1, 2022
@onebone onebone changed the title ToolbarState expand(), collapse() and scroll not working ToolbarState expand(), collapse() and scroll not working when toolbar's content is set with delay Aug 1, 2022
@witchcraft2001
Copy link

Hi onebone,

I faced the same problem. I have prepared an example code that shows the problem, it's based on sample code from your repository. Please tell me what is my mistake and how to make the toolbar expand when the expand() method is called?

@onebone
Copy link
Owner

onebone commented Dec 14, 2022

Hi onebone,

I faced the same problem. I have prepared an example code that shows the problem, it's based on sample code from your repository. Please tell me what is my mistake and how to make the toolbar expand when the expand() method is called?

I have looked at your code, the toolbar seems to have a fixed height (hence it is not expandable). What layout do you expect when it is expanded?

@witchcraft2001
Copy link

I expect that after hiding the toolbar when scrolling through the contents of the list, the expand method will reveal this toolbar. How can this be achieved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Improvement of existing library contracts that may break backwards compatibility
Projects
None yet
Development

No branches or pull requests

3 participants