Skip to content

Commit

Permalink
Merge pull request #11 from ramtinq/master
Browse files Browse the repository at this point in the history
Added onScaleStart and onScaleEnd VoidCallbacks
  • Loading branch information
Mayb3Nots authored Feb 28, 2023
2 parents 2b77d24 + 321b1f4 commit 3c55387
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.3

- Added `onScaleStart` and `onScaleStop` VoidCallbacks

## 1.3.2

- Made package compatible with stable channel
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ ZoomOverlay(
animationCurve: Curves.fastOutSlowIn, // Defaults to fastOutSlowIn which mimics IOS instagram behavior
animationDuration: Duration(milliseconds: 300), // Defaults to 100 Milliseconds. Recommended duration is 300 milliseconds for Curves.fastOutSlowIn
twoTouchOnly: true, // Defaults to false
onScaleStart: () {}, // optional VoidCallback
onScaleStop: () {}, // optional VoidCallback
child: CachedNetworkImage(
imageUrl: imageUrl,
),
Expand Down
6 changes: 6 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class _MyHomePageState extends State<MyHomePage> {
twoTouchOnly: true,
animationDuration: Duration(milliseconds: 300),
animationCurve: Curves.fastOutSlowIn,
onScaleStart: () {
debugPrint('zooming!');
}, // optional
onScaleStop: () {
debugPrint('zooming ended!');
}, // optional
child: CachedNetworkImage(
imageUrl: 'https://picsum.photos/800?image=$image')),
Padding(
Expand Down
12 changes: 12 additions & 0 deletions lib/zoom_pinch_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class ZoomOverlay extends StatefulWidget {
this.animationDuration = const Duration(milliseconds: 100),
this.animationCurve = Curves.fastOutSlowIn,
this.modalBarrierColor,
this.onScaleStart,
this.onScaleStop,
}) : super(key: key);

/// A widget to make zoomable.
Expand All @@ -77,6 +79,10 @@ class ZoomOverlay extends StatefulWidget {
/// Specifies the color of the modal barrier that shows in the background.
final Color? modalBarrierColor;

/// add callback functions
final VoidCallback? onScaleStart;
final VoidCallback? onScaleStop;

@override
_ZoomOverlayState createState() => _ZoomOverlayState();
}
Expand Down Expand Up @@ -137,6 +143,9 @@ class _ZoomOverlayState extends State<ZoomOverlay>
//Dont start the effect if the image havent reset complete.
if (_controllerReset.isAnimating) return;
if (widget.twoTouchOnly && _touchCount < 2) return;

// call start callback before everything else
widget.onScaleStart?.call();
_startFocalPoint = details.focalPoint;

_matrix = Matrix4.identity();
Expand Down Expand Up @@ -206,6 +215,9 @@ class _ZoomOverlayState extends State<ZoomOverlay>
_controllerReset
..reset()
..forward();

// call end callback function after everything else
widget.onScaleStop?.call();
}

Widget _build(BuildContext context) {
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: zoom_pinch_overlay
description: An instagram style pinch and zoom widget that can be moved globally.
version: 1.3.2
version: 1.3.3
homepage: https://github.com/Mayb3Nots/zoom_pinch_overlay

environment:
Expand Down

0 comments on commit 3c55387

Please sign in to comment.