@@ -324,13 +324,13 @@ class TopAppBarState(
324324 * A `0.0` indicates that the app bar does not overlap any content, while `1.0` indicates that
325325 * the entire visible app bar area overlaps the scrolled content.
326326 */
327- private val overlappedFraction: Float
327+ val overlappedFraction: Float
328328 get() =
329329 if (heightOffsetLimit != 0f ) {
330330 1 -
331331 ((heightOffsetLimit - contentOffset).coerceIn(
332332 minimumValue = heightOffsetLimit,
333- maximumValue = 0f
333+ maximumValue = 0f ,
334334 ) / heightOffsetLimit)
335335 } else {
336336 0f
@@ -345,9 +345,9 @@ class TopAppBarState(
345345 TopAppBarState (
346346 initialHeightOffsetLimit = it[0 ],
347347 initialHeightOffset = it[1 ],
348- initialContentOffset = it[2 ]
348+ initialContentOffset = it[2 ],
349349 )
350- }
350+ },
351351 )
352352 }
353353
@@ -411,7 +411,7 @@ private class ExitUntilCollapsedScrollBehavior(
411411 override val state : TopAppBarState ,
412412 override val snapAnimationSpec : AnimationSpec <Float >? ,
413413 override val flingAnimationSpec : DecayAnimationSpec <Float >? ,
414- val canScroll : () -> Boolean = { true }
414+ val canScroll : () -> Boolean = { true },
415415) : ScrollBehavior {
416416 override val isPinned: Boolean = false
417417 override var nestedScrollConnection =
@@ -421,7 +421,7 @@ private class ExitUntilCollapsedScrollBehavior(
421421 if (! canScroll() || available.y > 0f ) return Offset .Zero
422422
423423 val prevHeightOffset = state.heightOffset
424- state.heightOffset + = available.y
424+ state.heightOffset = state.heightOffset + available.y
425425 return if (prevHeightOffset != state.heightOffset) {
426426 // We're in the middle of top app bar collapse or expand.
427427 // Consume only the scroll on the Y axis.
@@ -434,35 +434,34 @@ private class ExitUntilCollapsedScrollBehavior(
434434 override fun onPostScroll (
435435 consumed : Offset ,
436436 available : Offset ,
437- source : NestedScrollSource
437+ source : NestedScrollSource ,
438438 ): Offset {
439439 if (! canScroll()) return Offset .Zero
440440 state.contentOffset + = consumed.y
441441
442442 if (available.y < 0f || consumed.y < 0f ) {
443443 // When scrolling up, just update the state's height offset.
444444 val oldHeightOffset = state.heightOffset
445- state.heightOffset + = consumed.y
445+ state.heightOffset = state.heightOffset + consumed.y
446446 return Offset (0f , state.heightOffset - oldHeightOffset)
447447 }
448448
449- if (consumed.y == 0f && available.y > 0 ) {
450- // Reset the total content offset to zero when scrolling all the way down. This
451- // will eliminate some float precision inaccuracies.
452- state.contentOffset = 0f
453- }
454-
455449 if (available.y > 0f ) {
456450 // Adjust the height offset in case the consumed delta Y is less than what was
457451 // recorded as available delta Y in the pre-scroll.
458452 val oldHeightOffset = state.heightOffset
459- state.heightOffset + = available.y
453+ state.heightOffset = state.heightOffset + available.y
460454 return Offset (0f , state.heightOffset - oldHeightOffset)
461455 }
462456 return Offset .Zero
463457 }
464458
465459 override suspend fun onPostFling (consumed : Velocity , available : Velocity ): Velocity {
460+ if (available.y > 0 ) {
461+ // Reset the total content offset to zero when scrolling all the way down. This
462+ // will eliminate some float precision inaccuracies.
463+ state.contentOffset = 0f
464+ }
466465 val superConsumed = super .onPostFling(consumed, available)
467466 return superConsumed +
468467 settleAppBar(state, available.y, flingAnimationSpec, snapAnimationSpec)
0 commit comments