Skip to content

Commit

Permalink
Merge pull request #27 from rasitayaz/dev
Browse files Browse the repository at this point in the history
update to 1.2.4
  • Loading branch information
rasitayaz authored Dec 28, 2022
2 parents 8681c0c + 060a60e commit 83bedf8
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 30 deletions.
1 change: 1 addition & 0 deletions .pubignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ build/
example/.metadata
example/demo.apk
example/demo-windows.zip
example/demo-macos.zip
# Showcase images
showcase/**
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.2.4

* Improved menu bounce animations.
* Added [macOS demo](https://github.com/rasitayaz/flutter-pie-menu/raw/main/example/demo-macos.zip).

## 1.2.3

* Fixed broken repository links in `README.md`.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Flutter Pie Menu 🥧

[![pub](https://img.shields.io/pub/v/pie_menu.svg?style=popout)](https://pub.dartlang.org/packages/pie_menu)
[![apk](https://img.shields.io/badge/APK-Demo-brightgreen.svg)](https://github.com/rasitayaz/flutter-pie-menu/raw/main/example/demo.apk)
[![exe](https://img.shields.io/badge/EXE-Windows Demo-blueviolet)](https://github.com/rasitayaz/flutter-pie-menu/raw/main/example/demo-windows.zip)
[![apk](https://img.shields.io/badge/apk-demo-brightgreen.svg)](https://github.com/rasitayaz/flutter-pie-menu/raw/main/example/demo.apk)
[![app](https://img.shields.io/badge/app-mac demo-blueviolet)](https://github.com/rasitayaz/flutter-pie-menu/raw/main/example/demo-macos.zip)
[![github](https://img.shields.io/badge/github-rasitayaz-red)](https://github.com/rasitayaz)
[![buy me a coffee](https://img.shields.io/badge/buy me a coffee-donate-blue)](https://www.buymeacoffee.com/RasitAyaz)

Expand Down
Binary file added example/demo-macos.zip
Binary file not shown.
Binary file modified example/demo.apk
Binary file not shown.
75 changes: 50 additions & 25 deletions lib/src/pie_menu.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:pie_menu/src/pie_action.dart';
Expand Down Expand Up @@ -52,25 +53,35 @@ class PieMenuState extends State<PieMenu> with SingleTickerProviderStateMixin {

PieCanvasOverlayState get _canvas => _canvasProvider.canvasKey.currentState!;

/// Controls [_menuBounceAnimation].
late final AnimationController _menuBounceController = AnimationController(
duration: _theme.menuBounceDuration,
Size? _size;

Duration get _bounceDuration => _theme.menuBounceDuration;

/// Controls [_bounceAnimation].
late final AnimationController _bounceController = AnimationController(
duration: _bounceDuration,
vsync: this,
);

Animation<double> _getAnimation(double depth) {
return Tween(
begin: 1.0,
end: depth,
).animate(CurvedAnimation(
parent: _bounceController,
curve: _theme.menuBounceCurve,
reverseCurve: _theme.menuBounceReverseCurve,
));
}

/// Bouncing animation for [PieMenu].
late final Animation<double> _menuBounceAnimation = Tween(
begin: 1.0,
end: _theme.menuBounceDepth,
).animate(CurvedAnimation(
parent: _menuBounceController,
curve: _theme.menuBounceCurve,
reverseCurve: _theme.menuBounceReverseCurve,
));
late Animation<double> _bounceAnimation = _getAnimation(
_theme.menuBounceDepth,
);

Widget get _bouncingChild {
return ScaleTransition(
scale: _menuBounceAnimation,
scale: _bounceAnimation,
child: widget.child,
);
}
Expand All @@ -81,23 +92,20 @@ class PieMenuState extends State<PieMenu> with SingleTickerProviderStateMixin {
}
}

void debounce() async {
void debounce() {
if (!mounted || !_theme.bouncingMenu) return;

if (_bouncing) {
_bouncing = false;

if (_bounceStopwatch.elapsed > _theme.menuBounceDuration) {
_menuBounceController.reverse();
if (_bounceStopwatch.elapsed > _bounceDuration || !_canvas.menuActive) {
_bounceController.reverse();
} else {
Future.delayed(
_theme.menuBounceDuration - _bounceStopwatch.elapsed,
() {
if (mounted) {
_menuBounceController.reverse();
}
},
);
Future.delayed(_bounceDuration - _bounceStopwatch.elapsed, () {
if (mounted) {
_bounceController.reverse();
}
});
}

_bounceStopwatch.stop();
Expand All @@ -114,12 +122,29 @@ class PieMenuState extends State<PieMenu> with SingleTickerProviderStateMixin {

@override
void dispose() {
_menuBounceController.dispose();
_bounceController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
final size = context.size;

if (mounted && _size != size && size != null && !size.isEmpty) {
_size = context.size;

final screenSize = MediaQuery.of(context).size;

final widthRatio = size.width / screenSize.width;
final heightRatio = size.height / screenSize.height;

final depth = max(0, min(1, max(widthRatio, heightRatio))) * 0.1 + 0.8;

setState(() => _bounceAnimation = _getAnimation(depth));
}
});

return Listener(
behavior: HitTestBehavior.translucent,
onPointerDown: (event) {
Expand All @@ -131,7 +156,7 @@ class PieMenuState extends State<PieMenu> with SingleTickerProviderStateMixin {
}

if (_theme.bouncingMenu) {
_menuBounceController.forward();
_bounceController.forward();
_bouncing = true;
_bounceStopwatch.start();
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/pie_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class PieTheme {
this.tooltipPadding = const EdgeInsets.symmetric(horizontal: 32),
this.tooltipStyle,
this.pieBounceDuration = const Duration(seconds: 1),
this.menuBounceDuration = const Duration(milliseconds: 150),
this.menuBounceDuration = const Duration(milliseconds: 100),
this.menuBounceDepth = 0.95,
this.menuBounceCurve = Curves.ease,
this.menuBounceCurve = Curves.decelerate,
this.menuBounceReverseCurve,
this.fadeDuration = const Duration(milliseconds: 250),
this.hoverDuration = const Duration(milliseconds: 250),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pie_menu
description: A Flutter package that provides a customizable circular/radial context menu
version: 1.2.3
version: 1.2.4
homepage: https://github.com/rasitayaz/flutter-pie-menu
repository: https://github.com/rasitayaz/flutter-pie-menu
issue_tracker: https://github.com/rasitayaz/flutter-pie-menu/issues
Expand Down

0 comments on commit 83bedf8

Please sign in to comment.