Skip to content

Commit

Permalink
Merge branch 'master_remote'
Browse files Browse the repository at this point in the history
* master_remote:
  chore: 0.15.0 (bluefireteam#553)
  Added pageSnapping option (bluefireteam#542)
  feature/strictscale: add possibility to restrict user scale, fix issue bluefireteam#85 (bluefireteam#537)
  make scale more smoothly (bluefireteam#450)
  Pass through semanticLabel (bluefireteam#530)
  doc: Fix github build badge (bluefireteam#531)
  • Loading branch information
MagTuxGit committed May 6, 2024
2 parents f2dc185 + 47d347d commit 7de4425
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 5 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
<a name="0.15.0"></a>
# [0.15.0](https://github.com/bluefireteam/photo_view/releases/tag/0.15.0) - 17 Apr 2024

## Added
- Added pageSnapping option #542
- make scale more smoothly #450
- Add possibility to restrict user scale #537
- Pass through semanticLabel #530

[Changes][0.15.0]



<a name="0.14.0"></a>
# [0.14.0](https://github.com/bluefireteam/photo_view/releases/tag/0.14.0) - 24 May 2022

Expand Down Expand Up @@ -373,6 +386,7 @@ With this version, Photo view is stable compatible. It means that every new rele
[Changes][0.2.1]


[0.15.0]: https://github.com/bluefireteam/photo_view/compare/0.14.0...0.15.0
[0.14.0]: https://github.com/bluefireteam/photo_view/compare/0.13.0...0.14.0
[0.13.0]: https://github.com/bluefireteam/photo_view/compare/0.12.0...0.13.0
[0.12.0]: https://github.com/bluefireteam/photo_view/compare/0.11.1...0.12.0
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2020 Renan C. Araújo
Copyright 2024 Renan C. Araújo

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Flutter Photo View

[![Tests status](https://img.shields.io/github/workflow/status/bluefireteam/photo_view/Test/master?label=tests)](https://github.com/bluefireteam/photo_view/actions) [![Pub](https://img.shields.io/pub/v/photo_view.svg?style=popout)](https://pub.dartlang.org/packages/photo_view) [![Chat](https://img.shields.io/discord/509714518008528896)](https://discord.gg/pxrBmy4)
[![Tests status](https://img.shields.io/github/actions/workflow/status/bluefireteam/photo_view/ci.yml?branch=master)](https://github.com/bluefireteam/photo_view/actions) [![Pub](https://img.shields.io/pub/v/photo_view.svg?style=popout)](https://pub.dartlang.org/packages/photo_view) [![Chat](https://img.shields.io/discord/509714518008528896)](https://discord.gg/pxrBmy4)

A simple zoomable image/content widget for Flutter.

Expand All @@ -13,7 +13,7 @@ Even though being super simple to use, PhotoView is extremely customizable thoug

## Installation

Add `photo_view` as a dependency in your pubspec.yaml file ([what?](https://flutter.io/using-packages/)).
Add `photo_view` as a dependency in your pubspec.yaml file.

Import Photo View:
```dart
Expand Down
Binary file removed bin/changelog-from-release
Binary file not shown.
Binary file removed bin/changelog-from-release-mac
Binary file not shown.
17 changes: 17 additions & 0 deletions lib/photo_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export 'src/utils/photo_view_hero_attributes.dart';
/// ),
/// ),
/// backgroundDecoration: BoxDecoration(color: Colors.black),
/// semanticLabel: 'Some label',
/// gaplessPlayback: false,
/// customSize: MediaQuery.of(context).size,
/// heroAttributes: const HeroAttributes(
Expand Down Expand Up @@ -68,6 +69,7 @@ export 'src/utils/photo_view_hero_attributes.dart';
/// ),
/// childSize: const Size(220.0, 250.0),
/// backgroundDecoration: BoxDecoration(color: Colors.black),
/// semanticLabel: 'Some label',
/// gaplessPlayback: false,
/// customSize: MediaQuery.of(context).size,
/// heroAttributes: const HeroAttributes(
Expand Down Expand Up @@ -238,6 +240,7 @@ class PhotoView extends StatefulWidget {
this.loadingBuilder,
this.backgroundDecoration,
this.wantKeepAlive = false,
this.semanticLabel,
this.gaplessPlayback = false,
this.heroAttributes,
this.scaleStateChangedCallback,
Expand All @@ -259,6 +262,7 @@ class PhotoView extends StatefulWidget {
this.disableGestures,
this.errorBuilder,
this.enablePanAlways,
this.strictScale,
}) : child = null,
childSize = null,
super(key: key);
Expand Down Expand Up @@ -294,8 +298,10 @@ class PhotoView extends StatefulWidget {
this.filterQuality,
this.disableGestures,
this.enablePanAlways,
this.strictScale,
}) : errorBuilder = null,
imageProvider = null,
semanticLabel = null,
gaplessPlayback = false,
loadingBuilder = null,
super(key: key);
Expand All @@ -319,6 +325,11 @@ class PhotoView extends StatefulWidget {
/// `true` -> keeps the state
final bool wantKeepAlive;

/// A Semantic description of the image.
///
/// Used to provide a description of the image to TalkBack on Android, and VoiceOver on iOS.
final String? semanticLabel;

/// This is used to continue showing the old image (`true`), or briefly show
/// nothing (`false`), when the `imageProvider` changes. By default it's set
/// to `false`.
Expand Down Expand Up @@ -401,6 +412,9 @@ class PhotoView extends StatefulWidget {
/// Useful when you want to drag a widget without restrictions.
final bool? enablePanAlways;

/// Enable strictScale will restrict user scale gesture to the maxScale and minScale values.
final bool? strictScale;

bool get _isCustomChild {
return child != null;
}
Expand Down Expand Up @@ -521,11 +535,13 @@ class _PhotoViewState extends State<PhotoView>
filterQuality: widget.filterQuality,
disableGestures: widget.disableGestures,
enablePanAlways: widget.enablePanAlways,
strictScale: widget.strictScale,
)
: ImageWrapper(
imageProvider: widget.imageProvider!,
loadingBuilder: widget.loadingBuilder,
backgroundDecoration: backgroundDecoration,
semanticLabel: widget.semanticLabel,
gaplessPlayback: widget.gaplessPlayback,
heroAttributes: widget.heroAttributes,
scaleStateChangedCallback: widget.scaleStateChangedCallback,
Expand All @@ -547,6 +563,7 @@ class _PhotoViewState extends State<PhotoView>
disableGestures: widget.disableGestures,
errorBuilder: widget.errorBuilder,
enablePanAlways: widget.enablePanAlways,
strictScale: widget.strictScale,
);
},
);
Expand Down
11 changes: 11 additions & 0 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class PhotoViewGallery extends StatefulWidget {
this.scrollDirection = Axis.horizontal,
this.customSize,
this.allowImplicitScrolling = false,
this.pageSnapping = true,
}) : itemCount = null,
builder = null,
super(key: key);
Expand All @@ -141,6 +142,7 @@ class PhotoViewGallery extends StatefulWidget {
this.scrollDirection = Axis.horizontal,
this.customSize,
this.allowImplicitScrolling = false,
this.pageSnapping = true,
}) : pageOptions = null,
assert(itemCount != null),
assert(builder != null),
Expand Down Expand Up @@ -194,6 +196,8 @@ class PhotoViewGallery extends StatefulWidget {
/// When user attempts to move it to the next element, focus will traverse to the next page in the page view.
final bool allowImplicitScrolling;

final bool pageSnapping;

bool get _isBuilder => builder != null;

@override
Expand Down Expand Up @@ -237,6 +241,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
scrollDirection: widget.scrollDirection,
physics: widget.scrollPhysics,
allowImplicitScrolling: widget.allowImplicitScrolling,
pageSnapping: widget.pageSnapping,
),
);
}
Expand Down Expand Up @@ -280,6 +285,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
controller: pageOption.controller,
scaleStateController: pageOption.scaleStateController,
customSize: widget.customSize,
semanticLabel: pageOption.semanticLabel,
gaplessPlayback: widget.gaplessPlayback,
heroAttributes: pageOption.heroAttributes,
scaleStateChangedCallback: scaleStateChangedCallback,
Expand Down Expand Up @@ -322,6 +328,7 @@ class PhotoViewGalleryPageOptions {
Key? key,
required this.imageProvider,
this.heroAttributes,
this.semanticLabel,
this.minScale,
this.maxScale,
this.initialScale,
Expand All @@ -343,6 +350,7 @@ class PhotoViewGalleryPageOptions {

PhotoViewGalleryPageOptions.customChild({
required this.child,
this.semanticLabel,
this.childSize,
this.heroAttributes,
this.minScale,
Expand All @@ -368,6 +376,9 @@ class PhotoViewGalleryPageOptions {
/// Mirror to [PhotoView.heroAttributes]
final PhotoViewHeroAttributes? heroAttributes;

/// Mirror to [PhotoView.semanticLabel]
final String? semanticLabel;

/// Mirror to [PhotoView.minScale]
final dynamic minScale;

Expand Down
13 changes: 13 additions & 0 deletions lib/src/core/photo_view_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class PhotoViewCore extends StatefulWidget {
Key? key,
required this.imageProvider,
required this.backgroundDecoration,
required this.semanticLabel,
required this.gaplessPlayback,
required this.heroAttributes,
required this.enableRotation,
Expand All @@ -41,6 +42,7 @@ class PhotoViewCore extends StatefulWidget {
required this.filterQuality,
required this.disableGestures,
required this.enablePanAlways,
required this.strictScale,
}) : customChild = null,
super(key: key);

Expand All @@ -63,12 +65,15 @@ class PhotoViewCore extends StatefulWidget {
required this.filterQuality,
required this.disableGestures,
required this.enablePanAlways,
required this.strictScale,
}) : imageProvider = null,
semanticLabel = null,
gaplessPlayback = false,
super(key: key);

final Decoration? backgroundDecoration;
final ImageProvider? imageProvider;
final String? semanticLabel;
final bool? gaplessPlayback;
final PhotoViewHeroAttributes? heroAttributes;
final bool enableRotation;
Expand All @@ -88,6 +93,7 @@ class PhotoViewCore extends StatefulWidget {
final bool tightMode;
final bool disableGestures;
final bool enablePanAlways;
final bool strictScale;

final FilterQuality filterQuality;

Expand Down Expand Up @@ -147,6 +153,12 @@ class PhotoViewCoreState extends State<PhotoViewCore>
final double newScale = _scaleBefore! * details.scale;
final Offset delta = details.focalPoint - _normalizedPosition!;

if (widget.strictScale &&
(newScale > widget.scaleBoundaries.maxScale ||
newScale < widget.scaleBoundaries.minScale)) {
return;
}

updateScaleStateFromNewScale(newScale);

updateMultiple(
Expand Down Expand Up @@ -379,6 +391,7 @@ class PhotoViewCoreState extends State<PhotoViewCore>
? widget.customChild!
: Image(
image: widget.imageProvider!,
semanticLabel: widget.semanticLabel,
gaplessPlayback: widget.gaplessPlayback ?? false,
filterQuality: widget.filterQuality,
width: scaleBoundaries.childSize.width * scale,
Expand Down
1 change: 1 addition & 0 deletions lib/src/core/photo_view_gesture_detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class PhotoViewGestureDetector extends StatelessWidget {
hitDetector: hitDetector, debugOwner: this, validateAxis: axis),
(PhotoViewGestureRecognizer instance) {
instance
..dragStartBehavior = DragStartBehavior.start
..onStart = onScaleStart
..onUpdate = onScaleUpdate
..onEnd = onScaleEnd;
Expand Down
9 changes: 9 additions & 0 deletions lib/src/photo_view_wrappers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ImageWrapper extends StatefulWidget {
required this.imageProvider,
required this.loadingBuilder,
required this.backgroundDecoration,
required this.semanticLabel,
required this.gaplessPlayback,
required this.heroAttributes,
required this.scaleStateChangedCallback,
Expand All @@ -32,12 +33,14 @@ class ImageWrapper extends StatefulWidget {
required this.disableGestures,
required this.errorBuilder,
required this.enablePanAlways,
required this.strictScale,
}) : super(key: key);

final ImageProvider imageProvider;
final LoadingBuilder? loadingBuilder;
final ImageErrorWidgetBuilder? errorBuilder;
final BoxDecoration backgroundDecoration;
final String? semanticLabel;
final bool gaplessPlayback;
final PhotoViewHeroAttributes? heroAttributes;
final ValueChanged<PhotoViewScaleState>? scaleStateChangedCallback;
Expand All @@ -58,6 +61,7 @@ class ImageWrapper extends StatefulWidget {
final FilterQuality? filterQuality;
final bool? disableGestures;
final bool? enablePanAlways;
final bool? strictScale;

@override
_ImageWrapperState createState() => _ImageWrapperState();
Expand Down Expand Up @@ -182,13 +186,15 @@ class _ImageWrapperState extends State<ImageWrapper> {
return PhotoViewCore(
imageProvider: widget.imageProvider,
backgroundDecoration: widget.backgroundDecoration,
semanticLabel: widget.semanticLabel,
gaplessPlayback: widget.gaplessPlayback,
enableRotation: widget.enableRotation,
heroAttributes: widget.heroAttributes,
basePosition: widget.basePosition ?? Alignment.center,
controller: widget.controller,
scaleStateController: widget.scaleStateController,
scaleStateCycle: widget.scaleStateCycle ?? defaultScaleStateCycle,
strictScale: widget.strictScale ?? false,
scaleBoundaries: scaleBoundaries,
onTapUp: widget.onTapUp,
onTapDown: widget.onTapDown,
Expand Down Expand Up @@ -248,6 +254,7 @@ class CustomChildWrapper extends StatelessWidget {
required this.filterQuality,
required this.disableGestures,
required this.enablePanAlways,
required this.strictScale,
}) : super(key: key);

final Widget? child;
Expand Down Expand Up @@ -275,6 +282,7 @@ class CustomChildWrapper extends StatelessWidget {
final FilterQuality? filterQuality;
final bool? disableGestures;
final bool? enablePanAlways;
final bool? strictScale;

@override
Widget build(BuildContext context) {
Expand All @@ -296,6 +304,7 @@ class CustomChildWrapper extends StatelessWidget {
scaleStateCycle: scaleStateCycle ?? defaultScaleStateCycle,
basePosition: basePosition ?? Alignment.center,
scaleBoundaries: scaleBoundaries,
strictScale: strictScale ?? false,
onTapUp: onTapUp,
onTapDown: onTapDown,
onScaleEnd: onScaleEnd,
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: photo_view
description: Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interactive images and other stuff such as SVG.
version: 0.14.0
version: 0.15.0
homepage: https://github.com/renancaraujo/photo_view

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.6.0"

dependencies:
Expand Down

0 comments on commit 7de4425

Please sign in to comment.