Code Monkey home page Code Monkey logo

tbr-group-software / transformable_list_view Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 3.0 256 KB

Widget that extends the default ListView with ability to add item transform animations according to it's scroll position

Home Page: https://pub.dev/packages/transformable_list_view

License: MIT License

Dart 42.42% Kotlin 0.16% Swift 1.53% Objective-C 0.05% CMake 23.94% C++ 27.61% C 1.88% HTML 2.40%
animations dart flutter listview sliver sliverlist transform

transformable_list_view's Introduction

Scrollable widgets with easily customizable transform animations.

Features

The package contains 3 widgets:

  • TransformableListView that extends ListView
  • TransformableSliverList that extends SliverList
  • TransformableSliver that extends SliverToBoxAdapter

Each of then has getTransformMatrix callback. In the callback you need to return Matrix4 that represetns transormation of the child at the current moment. If you don't need any transformations you can simply return Matrix4.identity().

In getTransformMatrix callback you receive TransformableListItem with the data about list item:

  • Offset offset is main axis offset of the child. By default (with vertical, non reversed scroll view) offset.dx is always 0 while offset.dy is the distance between top edge of the child and top edge of the viewport.
  • Size size is the child size received from its RenderBox.
  • SliverConstraints constraints describes the current scroll state of the viewport from the point of view of the sliver receiving the constraints.
  • int? index is the index of the child. Will be null when using TransformableSliver.
  • TransformableListItemPosition position is child position on the main axis viewport. Can be .topEdge, .middle or .bottomEdge.
  • double visibleExtent is currently visible portion of item. For example, if item is hidden it will be 0 while it's completely displayed will equal to size.height or size.width depending on axis.

Usage

First you need to add TransformableListView where you need transformations

TransformableListView.builder(
  getTransformMatrix: getTransformMatrix,
  itemBuilder: (context, index) {
    return Container(
      height: 100,
      margin: const EdgeInsets.symmetric(
        horizontal: 16,
        vertical: 4,
      ),
      decoration: BoxDecoration(
        color: index.isEven ? Colors.grey : Colors.blueAccent,
        borderRadius: BorderRadius.circular(20),
      ),
      alignment: Alignment.center,
      child: Text(index.toString()),
    );
  },
  itemCount: 30,
),

Second you need to implement getTransformMatrix callback

Matrix4 getTransformMatrix(TransformableListItem item) {
  /// final scale of child when the animation is completed
  const endScaleBound = 0.3;

  /// 0 when animation completed and [scale] == [endScaleBound]
  /// 1 when animation starts and [scale] == 1
  final animationProgress = item.visibleExtent / item.size.height;

  /// result matrix
  final paintTransform = Matrix4.identity();

  /// animate only if item is on edge
  if (item.position != TransformableListItemPosition.middle) {
    final scale = endScaleBound + ((1 - endScaleBound) * animationProgress);

    paintTransform
      ..translate(item.size.width / 2)
      ..scale(scale)
      ..translate(-item.size.width / 2);
  }

  return paintTransform;
}

You can implement your own callback or check more at /example folder.

Additional information

You can read more about matrix transfomations in Flutter here. Any feedback and PRs are welcome.

Developed by TBR Group.

transformable_list_view's People

Contributors

thesharpesttool avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

transformable_list_view's Issues

How to change transparency in getTransformMatrix?

Matrix4 getTransformMatrix(TransformableListItem item) {
/// final scale of child when the animation is completed
const endScaleBound = 0.4;

/// 0 when animation completed and [scale] == [endScaleBound]
/// 1 when animation starts and [scale] == 1
final animationProgress = item.visibleExtent / item.size.height;

/// result matrix
final paintTransform = Matrix4.identity();

/// animate only if item is on edge
if (item.position != TransformableListItemPosition.middle) {
final scale = endScaleBound + ((1 - endScaleBound) * animationProgress);
final opacity =
(endScaleBound + ((1 - endScaleBound) * animationProgress)) / 2;

print(scale);
print(opacity);

paintTransform
  ..translate(item.size.width / 2)
  ..scale(scale)
  ..translate(-item.size.width / 2);

// paintTransform.setEntry(3, 3, opacity); // 添加透明度变换

}

return paintTransform;
}

How to modify transparency changes synchronously in this code?

Example of using TransformableSliverList

Hi!
Do you have an example of how to use this package with TransformableSliverList?
Right now, it doesn't work in CustomScrollView with SliverAppBar. For example, I want to transform the item (let's say, scale) when it is on top edge. It works just fine when you have just a simple page as shown in the example video of this package, but when it is used in CustomScrollView with SliverAppBar, it works like this (basically, the transform is happening behind the SliverAppBar, I've reduced the opacity so you can actually see the effect):

2022-12-29.17.16.48.mov

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.