Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Extract social overlay widgets

ashilkn0f9bef99418f
diff --git a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
index 09277d36e4..f6fab9c107 100644
--- a/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
+++ b/mobile/apps/photos/lib/ui/social/widgets/file_social_overlay.dart
@@ -389,69 +389,90 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
}
return LayoutBuilder(
- builder: (context, constraints) => Row(
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- if (_latestComment != null && _latestCommentAuthor != null)
- Padding(
- padding: const EdgeInsets.only(right: 4, bottom: 4),
- child: _buildLatestCommentPill(
- _latestComment!,
- _latestCommentAuthor!,
- math.min(constraints.maxWidth * 0.5, 200),
+ builder: (context, constraints) {
+ final latestComment = _latestComment;
+ final latestCommentAuthor = _latestCommentAuthor;
+ return Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ if (latestComment != null && latestCommentAuthor != null)
+ Padding(
+ padding: const EdgeInsets.only(right: 4, bottom: 4),
+ child: _LatestCommentPill(
+ comment: latestComment,
+ author: latestCommentAuthor,
+ maxWidth: math.min(constraints.maxWidth * 0.5, 200),
+ currentUserID: widget.currentUserID!,
+ onTap: () => _openComments(comment: latestComment),
+ ),
),
- ),
- Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Tooltip(
- message: AppLocalizations.of(context).like,
- child: GestureDetector(
- onLongPress: _showLikes,
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Tooltip(
+ message: AppLocalizations.of(context).like,
+ child: GestureDetector(
+ onLongPress: _showLikes,
+ child: SizedBox.square(
+ dimension: _socialControlsSize,
+ child: IconButton(
+ padding: _socialIconPadding,
+ style: IconButton.styleFrom(
+ overlayColor: WidgetStateColor.transparent,
+ ),
+ onPressed: _toggleReaction,
+ icon: Icon(
+ _hasLiked
+ ? EnteIcons.likeFilled
+ : EnteIcons.likeStroke,
+ color: _hasLiked ? _likedColor : Colors.white,
+ size: _socialIconSize,
+ ),
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(height: 8),
+ Tooltip(
+ message: AppLocalizations.of(context).comments,
child: SizedBox.square(
dimension: _socialControlsSize,
child: IconButton(
padding: _socialIconPadding,
- style: IconButton.styleFrom(
- overlayColor: WidgetStateColor.transparent,
- ),
- onPressed: _toggleReaction,
- icon: Icon(
- _hasLiked ? EnteIcons.likeFilled : EnteIcons.likeStroke,
- color: _hasLiked ? _likedColor : Colors.white,
- size: _socialIconSize,
- ),
+ onPressed: _openComments,
+ icon: _CommentBadgeIcon(count: _commentCount),
),
),
),
- ),
- const SizedBox(height: 8),
- Tooltip(
- message: AppLocalizations.of(context).comments,
- child: SizedBox.square(
- dimension: _socialControlsSize,
- child: IconButton(
- padding: _socialIconPadding,
- onPressed: _openComments,
- icon: _buildCommentIcon(),
- ),
- ),
- ),
- ],
- ),
- ],
- ),
+ ],
+ ),
+ ],
+ );
+ },
);
}
+}
- Widget _buildLatestCommentPill(
- Comment comment,
- User author,
- double maxWidth,
- ) {
+class _LatestCommentPill extends StatelessWidget {
+ final Comment comment;
+ final User author;
+ final double maxWidth;
+ final int currentUserID;
+ final VoidCallback onTap;
+
+ const _LatestCommentPill({
+ required this.comment,
+ required this.author,
+ required this.maxWidth,
+ required this.currentUserID,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
return GestureDetector(
behavior: HitTestBehavior.opaque,
- onTap: () => _openComments(comment: comment),
+ onTap: onTap,
child: ConstrainedBox(
constraints: BoxConstraints(maxWidth: maxWidth),
child: Stack(
@@ -496,7 +517,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
child: UserAvatarWidget(
author,
type: AvatarType.small,
- currentUserID: widget.currentUserID!,
+ currentUserID: currentUserID,
),
),
),
@@ -505,8 +526,15 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
),
);
}
+}
+
+class _CommentBadgeIcon extends StatelessWidget {
+ final int count;
- Widget _buildCommentIcon() {
+ const _CommentBadgeIcon({required this.count});
+
+ @override
+ Widget build(BuildContext context) {
return Stack(
clipBehavior: Clip.none,
children: [
@@ -515,7 +543,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
color: Colors.white,
size: _socialIconSize,
),
- if (_commentCount > 0)
+ if (count > 0)
Positioned(
right: -5,
top: -5,
@@ -528,7 +556,7 @@ class _FileSocialOverlayState extends State<FileSocialOverlay> {
),
child: Center(
child: Text(
- _commentCount > 99 ? "99+" : _commentCount.toString(),
+ count > 99 ? "99+" : count.toString(),
style: const TextStyle(
color: Colors.black,
fontSize: 10,
diff --git a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
index 995789b57c..75d3784176 100644
--- a/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
+++ b/mobile/apps/photos/lib/ui/viewer/file/detail_page.dart
@@ -290,7 +290,11 @@ class _BodyState extends State<_Body> {
ValueListenableBuilder(
valueListenable: _selectedIndexNotifier,
builder: (BuildContext context, int selectedIndex, _) {
- return _buildSocialOverlay(_files![selectedIndex]);
+ return _GallerySocialOverlay(
+ file: _files![selectedIndex],
+ mode: widget.config.mode,
+ isGuestView: isGuestView,
+ );
},
),
ValueListenableBuilder(
@@ -403,40 +407,6 @@ class _BodyState extends State<_Body> {
.ignore();
}
- Widget _buildSocialOverlay(EnteFile file) {
- if (widget.config.mode == DetailPageMode.minimalistic ||
- isGuestView ||
- file is TrashFile) {
- return const SizedBox.shrink();
- }
-
- final padding = MediaQuery.paddingOf(context);
- final fullScreenNotifier = InheritedDetailPageState.of(
- context,
- ).enableFullScreenNotifier;
- return Positioned(
- right: padding.right + _socialRightInset,
- bottom: padding.bottom + _socialBottomBarClearance,
- child: ValueListenableBuilder<bool>(
- valueListenable: fullScreenNotifier,
- builder: (context, isFullScreen, child) => IgnorePointer(
- ignoring: isFullScreen,
- child: AnimatedOpacity(
- opacity: isFullScreen ? 0 : 1,
- duration: const Duration(milliseconds: 250),
- curve: Curves.easeInOut,
- child: child,
- ),
- ),
- child: FileSocialOverlay(
- file: file,
- currentUserID: Configuration.instance.getUserID(),
- openingCollectionID: file.collectionID,
- ),
- ),
- );
- }
-
Widget _buildPageView() {
return PageView.builder(
clipBehavior: Clip.none,
@@ -670,3 +640,51 @@ class _BodyState extends State<_Body> {
return files[index];
}
}
+
+/// Must remain under a [Stack] because this widget builds a [Positioned].
+class _GallerySocialOverlay extends StatelessWidget {
+ final EnteFile file;
+ final DetailPageMode mode;
+ final bool isGuestView;
+
+ const _GallerySocialOverlay({
+ required this.file,
+ required this.mode,
+ required this.isGuestView,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ if (mode == DetailPageMode.minimalistic ||
+ isGuestView ||
+ file is TrashFile) {
+ return const SizedBox.shrink();
+ }
+
+ final padding = MediaQuery.paddingOf(context);
+ final fullScreenNotifier = InheritedDetailPageState.of(
+ context,
+ ).enableFullScreenNotifier;
+ return Positioned(
+ right: padding.right + _socialRightInset,
+ bottom: padding.bottom + _socialBottomBarClearance,
+ child: ValueListenableBuilder<bool>(
+ valueListenable: fullScreenNotifier,
+ builder: (context, isFullScreen, child) => IgnorePointer(
+ ignoring: isFullScreen,
+ child: AnimatedOpacity(
+ opacity: isFullScreen ? 0 : 1,
+ duration: const Duration(milliseconds: 250),
+ curve: Curves.easeInOut,
+ child: child,
+ ),
+ ),
+ child: FileSocialOverlay(
+ file: file,
+ currentUserID: Configuration.instance.getUserID(),
+ openingCollectionID: file.collectionID,
+ ),
+ ),
+ );
+ }
+}