sliver_tools icon indicating copy to clipboard operation
sliver_tools copied to clipboard

New Widget: SliverAlign

Open LucasAschenbach opened this issue 3 years ago • 7 comments

SliverAlign is a simple widget which sets its scrollExtent as a fraction of that of its child and then aligns its child within itself along the scroll axis as specified.

SliverClip(
  child: SliverAlign(
    alignment: AlignmentSliver.center,
    mainAxisFactor: 0.5,
    child: Container(
      height: 100.0,
      color: Colors.red,
      child: const Placeholder(),
    ),
  ),
),

I've mainly created this widget as a way to create custom expansion and collapse animations with slivers and thought it might be a nice addition to this package.

https://user-images.githubusercontent.com/37406743/163694247-e3367de6-f970-45be-a10f-a167a0d7aaa0.mov

Happy for feedback!

LucasAschenbach avatar Apr 16 '22 23:04 LucasAschenbach

@Kavantix Would be great if this lands in master soon :)

passsy avatar Apr 27 '22 08:04 passsy

@LucasAschenbach first of all thanks for the contribution this would make a fine addition!

In order to merge this I would like a few adjustments/additions:

  1. Can we rename the alignment to SliverAlignment
  2. Can you remove any changes that are not needed like some extra whitespace that was added
  3. I haven’t had time to test it yet but I think this might behave weirdly with child slivers like SliverPinnedHeader since you don’t do anything with the paintOrigin
  4. Can you add some tests for this widget, that way it will be easier to maintain.

Let me know if you need any help/advice and thanks again for contributing!

Kavantix avatar Apr 27 '22 09:04 Kavantix

Thanks for the review!

As for modifying the paint origin: After testing the widget with SliverPinnedHeader, I don't think we should set the child's paint origin to match the top edge of the parent. This would result in all headers sticking to the top during mainAxisFactor animations which is usually not expected. Here is what it currently looks like:

https://user-images.githubusercontent.com/37406743/165527755-90026726-fc88-47f5-addb-365834c1c887.mov

@Kavantix What are your thoughts?

LucasAschenbach avatar Apr 27 '22 13:04 LucasAschenbach

Well the main thing is that I believe adding the align witha main axis factor of 1 should have no effect on the widget.

But currently this is what happens with the align on pull down on iOS: Simulator Screen Shot - iPhone 13 - 2022-04-27 at 16 17 58

And Simulator Screen Shot - iPhone 13 - 2022-04-27 at 16 18 11 without:

Kavantix avatar Apr 27 '22 14:04 Kavantix

Perhaps take a look at the implementation of SliverAnimatedPaintExtent that should be fairly similar

Kavantix avatar Apr 27 '22 14:04 Kavantix

I also noticed that there are a few hints from the analyzer to improve the code quality, in the final version they'll need to be fixed

Kavantix avatar Apr 27 '22 14:04 Kavantix

@LucasAschenbach did you have any chance to look at it further?

Kavantix avatar Jul 12 '22 20:07 Kavantix