Skip to content

Commit

Permalink
Merge pull request #14 from TatsuUkraine/release-1.2.3
Browse files Browse the repository at this point in the history
Release 1.2.3
  • Loading branch information
TatsuUkraine committed Sep 8, 2019
2 parents 8bc02f8 + 29f72ae commit 9573dcd
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 18 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## [1.2.3] - 2019-09-08

**Bug fixes**

- fixed horizontal scroll usage without controller
[#13](https://github.com/TatsuUkraine/flutter_sticky_infinite_list/issues/13)
- fixed `SingleChildScrollView` viewport usage

**Updates**
- added examples to `README.md`

## [1.2.2] - 2019-06-22

**Bug fixes**
Expand Down
62 changes: 57 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ Luckily you can extend and override base `InfiniteListItem` class
class SomeCustomListItem extends InfiniteListItem<I> {
/// Header alignment
///
/// Currently it supports top left
/// and right alignment
/// Supports all sides alignment, see [HeaderAlignment] for more info
///
/// By default [HeaderAlignment.topLeft]
final HeaderAlignment headerAlignment;
Expand Down Expand Up @@ -389,7 +388,7 @@ class SomeCustomListItem extends InfiniteListItem<I> {
}
```

#### Need more override?.. Ok (not tested)
#### Need more override?..

**If you get any problems with this type of override,
please create an issue**
Expand All @@ -404,6 +403,55 @@ since it subscribes to scroll event and calculates position
against `Viewport` coordinates (see `StickyListItemRenderObject` class
for more information)

For example

```dart
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: height,
color: Colors.lightBlueAccent,
child: Placeholder(),
),
StickyListItem<String>(
header: Container(
height: 30,
width: double.infinity,
color: Colors.orange,
child: Center(
child: Text('Sticky Header')
),
),
content: Container(
height: height,
color: Colors.blueAccent,
child: Placeholder(),
),
itemIndex: 'single-child-index',
),
Container(
height: height,
color: Colors.cyan,
child: Placeholder(),
),
],
),
);
}
```

This code will render single child scroll
with 3 widgets. Middle one - item with sticky header.

**Demo**

<img src="https://github.com/TatsuUkraine/flutter_sticky_infinite_list_example/blob/5dabe8503ad2d578f9b07018d2d1c76a61a258ef/doc/images/single-scroll.gif?raw=true" width="50%" />

For more complex example please take a look at "Single Example" page
in [Example project](https://github.com/TatsuUkraine/flutter_sticky_infinite_list_example)

## Changelog

Please see the [Changelog](https://github.com/TatsuUkraine/flutter_sticky_infinite_list/blob/master/CHANGELOG.md) page to know what's recently changed.
Expand All @@ -417,5 +465,9 @@ Pull request are also welcome.

## Known issues

Currently this package can't work with reverse lists. I hope I will
get enough time to implement this feature soon)
Currently this package can't work with reverse scroll. For some reason
flutter calculates coordinate for negative list items in a
different way in reverse mode, comparing to regular scroll direction.

But there is an workaround can be used, described
in [Reverse infinite scroll](#reverse-infinite-scroll)
38 changes: 27 additions & 11 deletions lib/render.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,25 @@ class StickyListItemRenderObject<I> extends RenderStack {
markNeedsPaint();

if (attached) {
oldScrollable.widget.controller.removeListener(markNeedsPaint);
newScrollable.widget.controller.addListener(markNeedsPaint);
oldScrollable.position.removeListener(markNeedsPaint);
newScrollable.position.addListener(markNeedsPaint);
}
}

RenderBox get _headerBox => lastChild;
RenderBox get _contentBox => firstChild;

RenderViewport get _viewport => RenderAbstractViewport.of(this);
RenderAbstractViewport get _viewport => RenderAbstractViewport.of(this);

@override
void attach(PipelineOwner owner) {
super.attach(owner);
scrollable.widget.controller.addListener(markNeedsPaint);
scrollable.position.addListener(markNeedsPaint);
}

@override
void detach() {
scrollable.widget.controller.removeListener(markNeedsPaint);
scrollable.position.removeListener(markNeedsPaint);
super.detach();
}

Expand Down Expand Up @@ -175,19 +175,35 @@ class StickyListItemRenderObject<I> extends RenderStack {
}

double get _scrollableSize {
final viewportSize = _scrollDirectionVertical
? _viewport.size.height
: _viewport.size.width;
final viewportContainer = _viewport;

double viewportSize;

if (viewportContainer is RenderBox) {
final RenderBox viewportBox = viewportContainer as RenderBox;

viewportSize = _scrollDirectionVertical
? viewportBox.size.height
: viewportBox.size.width;
}

assert(viewportSize != null, 'Can\'t define view port size');

double anchor = 0;

if (viewportContainer is RenderViewport) {
anchor = viewportContainer.anchor;
}

if (_alignmentStart) {
return -viewportSize * _viewport.anchor;
return -viewportSize * anchor;
}

return viewportSize - viewportSize * _viewport.anchor;
return viewportSize - viewportSize * anchor;
}

double get _stuckOffset {
return _viewport.getOffsetToReveal(this, 0).offset - _viewport.offset.pixels - _scrollableSize;
return _viewport.getOffsetToReveal(this, 0).offset - _scrollable.position.pixels - _scrollableSize;
}

double _getContentDirectionSize() {
Expand Down
2 changes: 1 addition & 1 deletion lib/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class StickyListItem<I> extends Stack {
}) : super(
key: key,
children: [content, header],
alignment: alignment,
alignment: alignment ?? AlignmentDirectional.topStart,
overflow: Overflow.clip,
);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: >-
Can be customized or with config options or with override.
version: 1.2.2
version: 1.2.3
author: TatsuUkraine <[email protected]>
homepage: https://github.com/TatsuUkraine/flutter_sticky_infinite_list
repository: https://github.com/TatsuUkraine/flutter_sticky_infinite_list
Expand Down

0 comments on commit 9573dcd

Please sign in to comment.