compose-collapsing-toolbar icon indicating copy to clipboard operation
compose-collapsing-toolbar copied to clipboard

Snap on release

Open saket opened this issue 4 years ago • 7 comments
trafficstars

Hey @onebone, would it be possible to snap the header to its nearest edge when a scroll is released?

saket avatar Nov 01 '21 18:11 saket

Personally, I have not found such a feature in the lib. I also need it and I want to implement it this week.

@onebone are there any specific guidelines for contributors?

RareScrap avatar Nov 03 '21 07:11 RareScrap

@RareScrap No I did not have wrote such guidelines, but it would be fine if the code is consistent with the original code base; such as indenting and continuation by tabs and something like that.

onebone avatar Nov 03 '21 11:11 onebone

For now I implemented basics of snapping feature. Snapping is configured by the SnapStrategy instance (almost like the ScrollStrategy) to match the library code style. I have successfully implemented snapping for ExitUntilCollapsed scroll strategy, but with others there is some problems...

I can easily animate the toolbar because I have access to its state object. But in the case when the toolbar moves outside the screen (EnterAlways EnterAlwaysCollapsed), this is of little use - I need to animate the offsetY of CollapsingToolbarScaffoldState, not the CollapsingToolbarState. Now this gives me some architectural difficulties. @onebone, I would be glad to hear your opinion on how best to do this. And feel free to review draft PR

RareScrap avatar Nov 07 '21 14:11 RareScrap

Okay, the snap is working as it should. However, there are a few things that bother me:

  1. Suspicious jump in toolbar animation speed
  2. I think it's worth implementing a snap animation canceling if the onPreScroll was called during the animation
  3. Choreographer "Frame time is X ms in the future" issue

RareScrap avatar Nov 07 '21 20:11 RareScrap

@RareScrap Thank you for sharing, I will review your PR within this week!

onebone avatar Nov 08 '21 03:11 onebone

Hi, I have already created PR for this: https://github.com/onebone/compose-collapsing-toolbar/pull/83

By the way, if you want to use this feature, I created a separated remote dependency, while this PR is under review:

Add it in your root build.gradle at the end of repositories:

all projects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.GIGAMOLE:ComposeCollapsingToolbar:latest-version'
}

Or you can simply download it from there:

https://github.com/GIGAMOLE/ComposeCollapsingToolbar/releases

GIGAMOLE avatar May 12 '23 07:05 GIGAMOLE

Is this implemented into the library?

ivevasiljevic avatar Jan 30 '24 10:01 ivevasiljevic