Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hero #689

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/post/pages/create_comment_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ class _CreateCommentPageState extends State<CreateCommentPage> {
hideNsfwPreviews: thunderState.hideNsfwPreviews,
markPostReadOnMediaView: thunderState.markPostReadOnMediaView,
isUserLoggedIn: true,
disableHero: true,
),
const SizedBox(
height: 12,
Expand Down
3 changes: 0 additions & 3 deletions lib/shared/image_preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ class _ImagePreviewState extends State<ImagePreview> {
transitionDuration: const Duration(milliseconds: 100),
reverseTransitionDuration: const Duration(milliseconds: 50),
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
String heroKey = generateRandomHeroString();

return ImageViewer(
url: widget.url,
heroKey: heroKey,
postId: widget.postId,
navigateToPost: widget.navigateToPost,
);
Expand Down
106 changes: 49 additions & 57 deletions lib/shared/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ import 'package:path/path.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';

import 'package:thunder/shared/hero.dart';
import 'package:thunder/shared/snackbar.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class ImageViewer extends StatefulWidget {
final String url;
final String heroKey;
final int? postId;
final void Function()? navigateToPost;

const ImageViewer({
super.key,
required this.url,
required this.heroKey,
this.postId,
this.navigateToPost,
});
Expand Down Expand Up @@ -223,60 +220,55 @@ class _ImageViewerState extends State<ImageViewer> with TickerProviderStateMixin
}
return true;
},
child: HeroWidget(
tag: widget.heroKey,
slideType: SlideType.onlyImage,
slidePagekey: slidePagekey,
child: ExtendedImage.network(
widget.url,
color: Colors.white.withOpacity(imageTransparency),
colorBlendMode: BlendMode.dstIn,
enableSlideOutPage: true,
mode: ExtendedImageMode.gesture,
extendedImageGestureKey: gestureKey,
cache: true,
clearMemoryCacheWhenDispose: true,
initGestureConfigHandler: (ExtendedImageState state) {
return GestureConfig(
minScale: 0.8,
animationMinScale: 0.8,
maxScale: 4.0,
animationMaxScale: 4.0,
speed: 1.0,
inertialSpeed: 250.0,
initialScale: 1.0,
inPageView: false,
initialAlignment: InitialAlignment.center,
reverseMousePointerScrollDirection: true,
gestureDetailsIsChanged: (GestureDetails? details) {},
);
},
onDoubleTap: (ExtendedImageGestureState state) {
var pointerDownPosition = state.pointerDownPosition;
double begin = state.gestureDetails!.totalScale!;
double end;

animation?.removeListener(animationListener);
animationController.stop();
animationController.reset();

if (begin == 1) {
end = 2;
} else if (begin > 1.99 && begin < 2.01) {
end = 4;
} else {
end = 1;
}
animationListener = () {
state.handleDoubleTap(scale: animation!.value, doubleTapPosition: pointerDownPosition);
};
animation = animationController.drive(Tween<double>(begin: begin, end: end));

animation!.addListener(animationListener);

animationController.forward();
},
),
child: ExtendedImage.network(
widget.url,
color: Colors.white.withOpacity(imageTransparency),
colorBlendMode: BlendMode.dstIn,
enableSlideOutPage: true,
mode: ExtendedImageMode.gesture,
extendedImageGestureKey: gestureKey,
cache: true,
clearMemoryCacheWhenDispose: true,
initGestureConfigHandler: (ExtendedImageState state) {
return GestureConfig(
minScale: 0.8,
animationMinScale: 0.8,
maxScale: 4.0,
animationMaxScale: 4.0,
speed: 1.0,
inertialSpeed: 250.0,
initialScale: 1.0,
inPageView: false,
initialAlignment: InitialAlignment.center,
reverseMousePointerScrollDirection: true,
gestureDetailsIsChanged: (GestureDetails? details) {},
);
},
onDoubleTap: (ExtendedImageGestureState state) {
var pointerDownPosition = state.pointerDownPosition;
double begin = state.gestureDetails!.totalScale!;
double end;

animation?.removeListener(animationListener);
animationController.stop();
animationController.reset();

if (begin == 1) {
end = 2;
} else if (begin > 1.99 && begin < 2.01) {
end = 4;
} else {
end = 1;
}
animationListener = () {
state.handleDoubleTap(scale: animation!.value, doubleTapPosition: pointerDownPosition);
};
animation = animationController.drive(Tween<double>(begin: begin, end: end));

animation!.addListener(animationListener);

animationController.forward();
},
),
),
),
Expand Down
17 changes: 1 addition & 16 deletions lib/shared/media_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MediaView extends StatefulWidget {
final bool? scrapeMissingPreviews;
final ViewMode viewMode;
final void Function()? navigateToPost;
final bool disableHero;
final bool? read;

const MediaView({
Expand All @@ -45,7 +44,6 @@ class MediaView extends StatefulWidget {
this.viewMode = ViewMode.comfortable,
this.scrapeMissingPreviews,
this.navigateToPost,
this.disableHero = false,
this.read,
});

Expand Down Expand Up @@ -178,11 +176,8 @@ class _MediaViewState extends State<MediaView> with SingleTickerProviderStateMix
transitionDuration: const Duration(milliseconds: 100),
reverseTransitionDuration: const Duration(milliseconds: 50),
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
String heroKey = generateRandomHeroString();

return ImageViewer(
url: widget.postView!.media.first.mediaUrl!,
heroKey: heroKey,
postId: widget.postView!.postView.post.id,
navigateToPost: widget.navigateToPost,
);
Expand Down Expand Up @@ -215,7 +210,7 @@ class _MediaViewState extends State<MediaView> with SingleTickerProviderStateMix
double? height = widget.viewMode == ViewMode.compact ? 75 : (widget.showFullHeightImages ? widget.postView!.media.first.height : 150);
double width = widget.viewMode == ViewMode.compact ? 75 : MediaQuery.of(context).size.width - (widget.edgeToEdgeImages ? 0 : 24);

Widget heroChild = ExtendedImage.network(
return ExtendedImage.network(
color: widget.read == true ? const Color.fromRGBO(255, 255, 255, 0.5) : null,
colorBlendMode: widget.read == true ? BlendMode.modulate : null,
widget.postView!.media.first.mediaUrl!,
Expand Down Expand Up @@ -302,15 +297,5 @@ class _MediaViewState extends State<MediaView> with SingleTickerProviderStateMix
}
},
);

if (widget.disableHero) {
return heroChild;
} else {
return Hero(
tag: widget.postView!.media.first.mediaUrl!,
// This is used for image post previews in compact and comfortable mode
child: heroChild,
);
}
}
}
148 changes: 72 additions & 76 deletions lib/shared/preview_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,92 +51,88 @@ class _PreviewImageState extends State<PreviewImage> with SingleTickerProviderSt
double? height = widget.viewMode == ViewMode.compact ? 75 : (widget.showFullHeightImages ? widget.height : 150);
double width = widget.viewMode == ViewMode.compact ? 75 : MediaQuery.of(context).size.width - 24;

return Hero(
tag: widget.mediaUrl,
child: ExtendedImage.network(
widget.mediaUrl,
height: height,
width: width,
fit: widget.viewMode == ViewMode.compact ? BoxFit.cover : BoxFit.fitWidth,
cache: true,
clearMemoryCacheWhenDispose: true,
cacheWidth:
widget.viewMode == ViewMode.compact ? (75 * View.of(context).devicePixelRatio.ceil()) : ((MediaQuery.of(context).size.width - 24) * View.of(context).devicePixelRatio.ceil()).toInt(),
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
_controller.reset();
return Container(
color: useDarkTheme ? Colors.grey.shade900 : Colors.grey.shade300,
child: SizedBox(
height: height,
width: width,
child: const Center(child: SizedBox(width: 40, height: 40, child: CircularProgressIndicator())),
),
);
case LoadState.completed:
if (state.wasSynchronouslyLoaded) {
return state.completedWidget;
}
_controller.forward();
return ExtendedImage.network(
widget.mediaUrl,
height: height,
width: width,
fit: widget.viewMode == ViewMode.compact ? BoxFit.cover : BoxFit.fitWidth,
cache: true,
clearMemoryCacheWhenDispose: true,
cacheWidth: widget.viewMode == ViewMode.compact ? (75 * View.of(context).devicePixelRatio.ceil()) : ((MediaQuery.of(context).size.width - 24) * View.of(context).devicePixelRatio.ceil()).toInt(),
loadStateChanged: (ExtendedImageState state) {
switch (state.extendedImageLoadState) {
case LoadState.loading:
_controller.reset();
return Container(
color: useDarkTheme ? Colors.grey.shade900 : Colors.grey.shade300,
child: SizedBox(
height: height,
width: width,
child: const Center(child: SizedBox(width: 40, height: 40, child: CircularProgressIndicator())),
),
);
case LoadState.completed:
if (state.wasSynchronouslyLoaded) {
return state.completedWidget;
}
_controller.forward();

return FadeTransition(
opacity: _controller,
child: state.completedWidget,
);
case LoadState.failed:
_controller.reset();
return FadeTransition(
opacity: _controller,
child: state.completedWidget,
);
case LoadState.failed:
_controller.reset();

state.imageProvider.evict();
state.imageProvider.evict();

return Container(
color: useDarkTheme ? Colors.grey.shade900 : Colors.grey.shade300,
child: Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 8.0),
child: InkWell(
child: Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
child: Stack(
alignment: Alignment.bottomRight,
fit: StackFit.passthrough,
children: [
Container(
color: Colors.grey.shade900,
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
child: Row(
children: [
const Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
Icons.link,
color: Colors.white60,
),
return Container(
color: useDarkTheme ? Colors.grey.shade900 : Colors.grey.shade300,
child: Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 8.0),
child: InkWell(
child: Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(12)),
child: Stack(
alignment: Alignment.bottomRight,
fit: StackFit.passthrough,
children: [
Container(
color: Colors.grey.shade900,
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
child: Row(
children: [
const Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(
Icons.link,
color: Colors.white60,
),
Expanded(
child: Text(
widget.mediaUrl ?? '',
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium!.copyWith(
color: Colors.white60,
),
),
Expanded(
child: Text(
widget.mediaUrl ?? '',
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodyMedium!.copyWith(
color: Colors.white60,
),
),
],
),
),
],
),
],
),
),
],
),
onTap: () {
openLink(context, url: widget.mediaUrl, openInExternalBrowser: openInExternalBrowser);
},
),
onTap: () {
openLink(context, url: widget.mediaUrl, openInExternalBrowser: openInExternalBrowser);
},
),
);
}
},
),
),
);
}
},
);
}
}