diff --git a/lib/screens/explore.dart b/lib/screens/explore.dart index a3c29bc..7d4014d 100644 --- a/lib/screens/explore.dart +++ b/lib/screens/explore.dart @@ -246,34 +246,15 @@ class _ExploreScreenState extends State { onFetchData: _fetchPosts, itemBuilder: (context, idx) { return Center( - child: OpenContainer( - closedBuilder: (_, __) => Container( - constraints: const BoxConstraints(maxWidth: 640), - child: PostItem( - data: _posts[idx], - maxWidth: 640, - onChanged: (data) { - setState(() => _posts[idx] = data); - }, - onDeleted: () { - _refreshPosts(); - }, - ), - ), - openBuilder: (_, close) => PostDetailScreen( - slug: _posts[idx].id.toString(), - preload: _posts[idx], - onBack: close, - ), - openColor: Colors.transparent, - openElevation: 0, - transitionType: ContainerTransitionType.fade, - closedColor: Theme.of(context).colorScheme.surfaceContainerLow.withOpacity( - cfg.prefs.getBool(kAppBackgroundStoreKey) == true ? 0.75 : 1, - ), - closedShape: const RoundedRectangleBorder( - borderRadius: BorderRadius.all(Radius.circular(16)), - ), + child: OpenablePostItem( + data: _posts[idx], + maxWidth: 640, + onChanged: (data) { + setState(() => _posts[idx] = data); + }, + onDeleted: () { + _refreshPosts(); + }, ), ); }, diff --git a/lib/screens/post/post_search.dart b/lib/screens/post/post_search.dart index a31ffe9..7cf17e5 100644 --- a/lib/screens/post/post_search.dart +++ b/lib/screens/post/post_search.dart @@ -134,7 +134,7 @@ class _PostSearchScreenState extends State { body: Stack( children: [ InfiniteList( - padding: const EdgeInsets.only(top: 100), + padding: const EdgeInsets.only(top: 100 + 8), itemCount: _posts.length, isLoading: _isBusy, hasReachedMax: _postCount != null && _posts.length >= _postCount!, @@ -142,27 +142,18 @@ class _PostSearchScreenState extends State { _fetchPosts(); }, itemBuilder: (context, idx) { - return GestureDetector( - child: PostItem( - data: _posts[idx], - maxWidth: 640, - onChanged: (data) { - setState(() => _posts[idx] = data); - }, - onDeleted: () { - _refreshPosts(); - }, - ), - onTap: () { - GoRouter.of(context).pushNamed( - 'postDetail', - pathParameters: {'slug': _posts[idx].id.toString()}, - extra: _posts[idx], - ); + return OpenablePostItem( + data: _posts[idx], + maxWidth: 640, + onChanged: (data) { + setState(() => _posts[idx] = data); + }, + onDeleted: () { + _refreshPosts(); }, ); }, - separatorBuilder: (context, index) => const Divider(height: 1), + separatorBuilder: (_, __) => const Gap(8), ), Positioned( top: 16, diff --git a/lib/screens/post/publisher_page.dart b/lib/screens/post/publisher_page.dart index 4ec30a0..67943a4 100644 --- a/lib/screens/post/publisher_page.dart +++ b/lib/screens/post/publisher_page.dart @@ -287,8 +287,8 @@ class _PostPublisherScreenState extends State with SingleTi Theme( data: Theme.of(context).copyWith( appBarTheme: Theme.of(context).appBarTheme.copyWith( - foregroundColor: Colors.white, - ), + foregroundColor: Colors.white, + ), ), child: SliverAppBar( expandedHeight: _appBarHeight, @@ -597,25 +597,16 @@ class _PublisherPostList extends StatelessWidget { hasReachedMax: postCount != null && posts.length >= postCount!, onFetchData: fetchPosts, itemBuilder: (context, idx) { - return GestureDetector( - child: PostItem( - data: posts[idx], - maxWidth: 640, - onChanged: (data) { - onChanged(idx, data); - }, - onDeleted: onDeleted, - ), - onTap: () { - GoRouter.of(context).pushNamed( - 'postDetail', - pathParameters: {'slug': posts[idx].id.toString()}, - extra: posts[idx], - ); + return OpenablePostItem( + data: posts[idx], + maxWidth: 640, + onChanged: (data) { + onChanged(idx, data); }, + onDeleted: onDeleted, ); }, - separatorBuilder: (context, index) => const Divider(height: 1), + separatorBuilder: (_, __) => const Gap(8), ); } } diff --git a/lib/widgets/post/post_item.dart b/lib/widgets/post/post_item.dart index c2726e0..98f8ea5 100644 --- a/lib/widgets/post/post_item.dart +++ b/lib/widgets/post/post_item.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'dart:math' as math; +import 'package:animations/animations.dart'; import 'package:dio/dio.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:file_saver/file_saver.dart'; @@ -22,6 +23,7 @@ import 'package:styled_widget/styled_widget.dart'; import 'package:surface/providers/config.dart'; import 'package:surface/providers/sn_network.dart'; import 'package:surface/providers/userinfo.dart'; +import 'package:surface/screens/post/post_detail.dart'; import 'package:surface/types/attachment.dart'; import 'package:surface/types/post.dart'; import 'package:surface/types/reaction.dart'; @@ -38,6 +40,65 @@ import 'package:surface/widgets/post/publisher_popover.dart'; import 'package:surface/widgets/universal_image.dart'; import 'package:xml/xml.dart'; +class OpenablePostItem extends StatelessWidget { + final SnPost data; + final bool showReactions; + final bool showComments; + final bool showMenu; + final bool showFullPost; + final double? maxWidth; + final Function(SnPost data)? onChanged; + final Function()? onDeleted; + final Function()? onSelectAnswer; + + const OpenablePostItem({ + super.key, + required this.data, + this.showReactions = true, + this.showComments = true, + this.showMenu = true, + this.showFullPost = false, + this.maxWidth, + this.onChanged, + this.onDeleted, + this.onSelectAnswer, + }); + + @override + Widget build(BuildContext context) { + final cfg = context.read(); + + return OpenContainer( + closedBuilder: (_, __) => Container( + constraints: BoxConstraints(maxWidth: maxWidth ?? double.infinity), + child: PostItem( + data: data, + maxWidth: maxWidth, + showComments: showComments, + showFullPost: showFullPost, + onChanged: onChanged, + onDeleted: onDeleted, + onSelectAnswer: onSelectAnswer, + ), + ), + openBuilder: (_, close) => PostDetailScreen( + slug: data.id.toString(), + preload: data, + onBack: close, + ), + openColor: Colors.transparent, + openElevation: 0, + transitionType: ContainerTransitionType.fade, + closedColor: Theme.of(context).colorScheme.surfaceContainerLow.withOpacity( + cfg.prefs.getBool(kAppBackgroundStoreKey) == true ? 0.75 : 1, + ), + closedShape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(16)), + ), + ); + } +} + class PostItem extends StatelessWidget { final SnPost data; final bool showReactions;