accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Navigation Material] (0.29.0-alpha) With BottomSheetNavigator.navigatorSheetState.offset removed, there doesn't seem to be a way to access sheet offset/position

Open MarcLFJ opened this issue 3 years ago • 20 comments

Description We were using bottomSheetNavigator.navigatorSheetState.offset.value to reposition a "sticky" content view inside the content. Is this a wrong approach or is there a way to derive this with the new update? :)

Steps to reproduce bottomSheetNavigator.navigatorSheetState.offset annotated as error now.

Expected behavior Handle to access the BottomSheets current offset/drag position on screen.

Additional context None

MarcLFJ avatar Jan 12 '23 10:01 MarcLFJ

@MarcLFJ Do you have a code example of what you were doing before, and possibly a mockup of the use case?

jossiwolf avatar Jan 12 '23 14:01 jossiwolf

@jossiwolf Sorry about the delayed reply, our intention is to have a button be sticky to the bottom of the window, so if the sheet starts half expanded, the button is still visible and when the user drags the sheet to top, the footer sticks to the bottom of the window. Here is a barebone example of what we were doing in 0.28.0, let me know if it's too barebone. 😅

@OptIn(ExperimentalMaterialNavigationApi::class)
@Composable
fun SheetWithSticky(
    bottomSheetNavigator: BottomSheetNavigator,
    stickyFooter: (@Composable () -> Unit)? = null,
    content: @Composable () -> Unit
) {
    val bottomSheetOffset = bottomSheetNavigator.navigatorSheetState.offset.value
    var stickyContainerHeight by remember { mutableStateOf(0) }

    Box(
        Modifier.heightIn(max = LocalConfiguration.current.screenHeightDp.dp)
    ) {
        Column(
            // Ensure content is padded above sticky footer height
            modifier = Modifier.padding(
                bottom = with(LocalDensity.current) { stickyContainerHeight.toDp() }
            )
        ) {
            /*Generic header view and other views here ...*/
            content()
        }

        stickyFooter?.let { footer ->
            Box(
                modifier = Modifier
                    .onGloballyPositioned { stickyContainerHeight = it.size.height }
                    .offset { IntOffset(0, -bottomSheetOffset.toInt()) }
                    .align(Alignment.BottomCenter)
            ) {
                footer()
            }
        }
    }
}

Edited screenshot from design: Screenshot 2023-02-01 at 15 05 10

Using the following accompanist dependencies: com.google.accompanist:accompanist-navigation-material and Material3: androidx.compose.material3:material3:1.1.0-alpha03

MarcLFJ avatar Feb 01 '23 14:02 MarcLFJ

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Mar 19 '23 03:03 github-actions[bot]

@jossiwolf Any update on this? :) Is it not an intended usecase or is there a better way? Mainly the problem trying to be solved is listening to the actual offset position of the bottomsheet and react to it. 👍

MarcLFJ avatar Mar 20 '23 08:03 MarcLFJ

Same issue here, but a different usecase. Want to animate certain elements of the layout based on the sheet offset to create a smooth animation

Nek-12 avatar Mar 23 '23 12:03 Nek-12

Same issue here

Khaled-Eldeeb-BW avatar Apr 11 '23 11:04 Khaled-Eldeeb-BW

This looks like a really important feature, should provide some way to migrate, not the best way to downgrade Compose version.

fedor7peaks avatar Apr 20 '23 04:04 fedor7peaks

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 05 '23 03:06 github-actions[bot]

Not stale

Nek-12 avatar Jun 05 '23 08:06 Nek-12

While we're all waiting for Google for a solution, I came with a super ugly hack to make offset work in newer Compose version, since I cannot wait for this as all dependencies are going to get outdated.

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
@OptIn(ExperimentalMaterialNavigationApi::class, ExperimentalMaterialApi::class)
fun BottomSheetNavigatorSheetState.getOffset() = sheetState.requireOffset()

Hope this helps people in this thread.

fedor7peaks avatar Jun 23 '23 01:06 fedor7peaks

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Aug 07 '23 03:08 github-actions[bot]

Not stale

MarcLFJ avatar Aug 07 '23 10:08 MarcLFJ

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 23 '23 03:09 github-actions[bot]

.

Nek-12 avatar Sep 23 '23 16:09 Nek-12

.

Nek-12 avatar Oct 15 '23 08:10 Nek-12

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Nov 30 '23 03:11 github-actions[bot]

.

Nek-12 avatar Nov 30 '23 10:11 Nek-12

How is this closed if I left a comment

Nek-12 avatar Dec 06 '23 09:12 Nek-12

@jossiwolf Please reopen. Not only is this bot annoying, it also doesn't work correctly

Nek-12 avatar Dec 06 '23 09:12 Nek-12

@ianhanniballake Could you reopen, since this was referred in #1582 as being the issue to track progress on. :)

MarcLFJ avatar Dec 06 '23 12:12 MarcLFJ

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jan 21 '24 03:01 github-actions[bot]

Hello, has what's the state of this issue, if some work pr research has been done on it?

LouisCAD avatar Feb 23 '24 11:02 LouisCAD

@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")  

var offset = Float.POSITIVE_INFINITY try { offset = sheetState.requireOffset() } catch (e: IllegalStateException) { log.d("MODAL BOTTOM SHEET", "${e.printStackTrace()}") } // offset is 1568.9 val outside = it.y < offset this works for me

rcht007 avatar Feb 27 '24 11:02 rcht007

With the release of Compose Material 1.7.0-alpha04, the Material team has added a new artifact: androidx.compose.material:material-navigation, which fully replaces Accompanist Navigation Material.

As such, we are closing all issues here on Accompanist and will be fully deprecating Accompanist Navigation Material in an upcoming release.

This issue was not fixed as part of the migration, so if you're still interested in this, please file an issue and the Material team will take a look.

Include the link here so that others can star it!

ianhanniballake avatar Mar 08 '24 06:03 ianhanniballake