Skip to content

Commit

Permalink
Merge pull request #2 from renancaraujo/master
Browse files Browse the repository at this point in the history
Merge upstream
  • Loading branch information
scopendo authored Jun 5, 2020
2 parents 620c7c7 + 5cbd22f commit bb98d56
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 26 deletions.
13 changes: 9 additions & 4 deletions example/lib/screens/examples/controller_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ class _ControllerExampleState extends State<ControllerExample> {
void initState() {
controller = PhotoViewController()
..scale = defScale
..outputStateStream.listen(onControllerState);
..outputStateStream.listen(onController);

scaleStateController = PhotoViewScaleStateController();
scaleStateController = PhotoViewScaleStateController()
..outputScaleStateStream.listen(onScaleState);
super.initState();
}

void onControllerState(PhotoViewControllerValue value) {
void onController(PhotoViewControllerValue value) {
setState(() {
calls += 1;
});
}

void onScaleState(PhotoViewScaleState scaleState) {
print(scaleState);
}

@override
void dispose() {
controller.dispose();
Expand Down Expand Up @@ -69,7 +74,7 @@ class _ControllerExampleState extends State<ControllerExample> {
controller: controller,
scaleStateController: scaleStateController,
enableRotation: true,
initialScale: defScale,
initialScale: minScale,
minScale: minScale,
maxScale: maxScale,
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.9.1"
version: "0.9.2"
quiver:
dependency: transitive
description:
Expand Down
18 changes: 6 additions & 12 deletions lib/src/controller/photo_view_controller_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,13 @@ mixin PhotoViewControllerDelegate on State<PhotoViewCore> {
}

void updateScaleStateFromNewScale(double newScale) {
final PhotoViewScaleState newScaleState =
(newScale > scaleBoundaries.initialScale)
? PhotoViewScaleState.zoomedIn
: PhotoViewScaleState.zoomedOut;

scaleStateController.setInvisibly(newScaleState);
}

void checkGoBackToInitial() {
if (scaleStateController.scaleState != PhotoViewScaleState.initial &&
scale == scaleBoundaries.initialScale) {
scaleStateController.setInvisibly(PhotoViewScaleState.initial);
PhotoViewScaleState newScaleState = PhotoViewScaleState.initial;
if (scale != scaleBoundaries.initialScale) {
newScaleState = (newScale > scaleBoundaries.initialScale)
? PhotoViewScaleState.zoomedIn
: PhotoViewScaleState.zoomedOut;
}
scaleStateController.setInvisibly(newScaleState);
}

void nextScaleState() {
Expand Down
14 changes: 11 additions & 3 deletions lib/src/core/photo_view_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/widgets.dart';

import 'package:photo_view/photo_view.dart'
show
PhotoViewScaleState,
PhotoViewHeroAttributes,
PhotoViewImageTapDownCallback,
PhotoViewImageTapUpCallback,
Expand Down Expand Up @@ -138,6 +139,7 @@ class PhotoViewCoreState extends State<PhotoViewCore>

updateScaleStateFromNewScale(newScale);

//
updateMultiple(
scale: newScale,
position: clampPosition(position: delta * details.scale),
Expand Down Expand Up @@ -188,8 +190,6 @@ class PhotoViewCoreState extends State<PhotoViewCore>
clampPosition(position: _position + direction * 100.0),
);
}

checkGoBackToInitial();
}

void onDoubleTap() {
Expand Down Expand Up @@ -224,7 +224,15 @@ class PhotoViewCoreState extends State<PhotoViewCore>

void onAnimationStatus(AnimationStatus status) {
if (status == AnimationStatus.completed) {
checkGoBackToInitial();
onAnimationStatusCompleted();
}
}

/// Check if scale is equal to initial after scale animation update
void onAnimationStatusCompleted() {
if (scaleStateController.scaleState != PhotoViewScaleState.initial &&
scale == scaleBoundaries.initialScale) {
scaleStateController.setInvisibly(PhotoViewScaleState.initial);
}
}

Expand Down
12 changes: 7 additions & 5 deletions lib/src/core/photo_view_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ class PhotoViewGestureDetector extends StatelessWidget {

gestures[PhotoViewGestureRecognizer] =
GestureRecognizerFactoryWithHandlers<PhotoViewGestureRecognizer>(
() => PhotoViewGestureRecognizer(hitDetector, this, axis),
() => PhotoViewGestureRecognizer(
hitDetector: hitDetector, debugOwner: this, validateAxis: axis),
(PhotoViewGestureRecognizer instance) {
instance
..onStart = onScaleStart
Expand All @@ -80,11 +81,12 @@ class PhotoViewGestureDetector extends StatelessWidget {
}

class PhotoViewGestureRecognizer extends ScaleGestureRecognizer {
PhotoViewGestureRecognizer(
PhotoViewGestureRecognizer({
this.hitDetector,
Object debugOwner,
this.validateAxis,
) : super(debugOwner: debugOwner);
PointerDeviceKind kind,
}) : super(debugOwner: debugOwner, kind: kind);
final HitCornersDetector hitDetector;
final Axis validateAxis;

Expand Down Expand Up @@ -152,12 +154,12 @@ class PhotoViewGestureRecognizer extends ScaleGestureRecognizer {
? hitDetector.shouldMoveY(move)
: hitDetector.shouldMoveX(move);
if (shouldMove || _pointerLocations.keys.length > 1) {
resolve(GestureDisposition.accepted);
acceptGesture(event.pointer);
}
}
}

/// An [InheritedWidget] responsible to give a axis aware scope to the internal[GestureRecognizer].
/// An [InheritedWidget] responsible to give a axis aware scope to [PhotoViewGestureRecognizer].
///
/// When using this, PhotoView will test if the content zoomed has hit edge every time user pinches,
/// if so, it will let parent gesture detectors win the gesture arena
Expand Down
2 changes: 1 addition & 1 deletion lib/src/photo_view_scale_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum PhotoViewScaleState {
zoomedOut,
}

extension PhotoViewScaleStateIZoomingExtansion on PhotoViewScaleState {
extension PhotoViewScaleStateIZoomingExtension on PhotoViewScaleState {
bool get isScaleStateZooming =>
this == PhotoViewScaleState.zoomedIn ||
this == PhotoViewScaleState.zoomedOut;
Expand Down

0 comments on commit bb98d56

Please sign in to comment.