Skip to content

Commit

Permalink
YaruCarousel: use size transform animation (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupi007 committed May 18, 2022
1 parent 3166317 commit c4bba9c
Showing 1 changed file with 26 additions and 22 deletions.
48 changes: 26 additions & 22 deletions lib/src/yaru_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,32 @@ class _YaruCarouselState extends State<YaruCarousel> {
height: widget.height,
width: widget.width,
child: PageView.builder(
itemCount: widget.children.length,
pageSnapping: true,
controller: _pageController,
physics:
// Disable physic when auto scroll is enable because we cannot
// disable the timer when dragging the view
widget.autoScroll ? const NeverScrollableScrollPhysics() : null,
onPageChanged: (index) => setState(() => _index = index),
itemBuilder: (context, index) => AnimatedContainer(
duration: _kAnimationDuration,
curve: _kAnimationCurve,
margin: EdgeInsets.all(index == _index ? 10 : 20),
child: _index == index - 1 || _index == index + 1
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _animateToPage(index),
child: IgnorePointer(
child: widget.children[index],
),
)
: widget.children[index],
)),
itemCount: widget.children.length,
pageSnapping: true,
controller: _pageController,
physics:
// Disable physic when auto scroll is enable because we cannot
// disable the timer when dragging the view
widget.autoScroll ? const NeverScrollableScrollPhysics() : null,
onPageChanged: (index) => setState(() => _index = index),
itemBuilder: (context, index) => AnimatedScale(
scale: _index == index ? 1.0 : .95,
duration: _kAnimationDuration,
curve: _kAnimationCurve,
child: Container(
margin: const EdgeInsets.all(10),
child: _index == index - 1 || _index == index + 1
? GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => _animateToPage(index),
child: IgnorePointer(
child: widget.children[index],
),
)
: widget.children[index],
),
),
),
);
}

Expand Down

0 comments on commit c4bba9c

Please sign in to comment.