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

Allow the API user know the "visibility" progress of the bottom sheet. #57

Open
sergionettl opened this issue Sep 5, 2024 · 2 comments

Comments

@sergionettl
Copy link

Is your feature request related to a problem?
I want to use the progress of the visibility to dynamically update some contents

Describe the solution you'd like:

FlexibleSheetState would contain a state property progress : State<Float>.
0f would mean the bottom sheet is Hidden
1f would mean the bottom sheet is FullyExpanded

This progress would update whenever an automatic animation occurs or when the user drags the bottom sheet up or down.

Describe alternatives you've considered:

Manually calculation the bottom sheet visible height. And doing approximated calculations.

@seanutf1
Copy link
Contributor

seanutf1 commented Sep 6, 2024

In the FlexibleBottomSheet, there is an onTargetChanges callback. This parameter does not meet your requirements, does it?

@sergionettl
Copy link
Author

sergionettl commented Sep 6, 2024

onTargetChanges passes FlexibleSheetValue which is an enum with the discrete defined values. What I mentioned is the full range. This is the code I'm using for now to accomplish this.

// Full screen height
val screenHeightPx = with(LocalDensity.current) { LocalConfiguration.current.screenHeightDp.dp.toPx() }
val fullyExpanded: Float = 1f
  
  /**
 * Offset related to the bottom sheet offset
 * Offset: 0 when Fully expanded
 * Offset: ScreenHeight when Fully Hidden
 */
val offsetPx by rememberUpdatedState(
  try {
    sheetState.requireOffset()
  } catch (ex: IllegalStateException) {
    screenHeightPx
  },
)
    
val progress = when (screenHeightPx) {
  0f -> 0f
  else -> (screenHeightPx - offsetPx) / screenHeightPx
}.coerceIn(0f, 1f)

This assumes FullExpanded equals to screen height

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