Merge pull request 'пофиксили отображение коунтера карусели при переключении картинок, при посте с одной картинкой и одним видео. добавили таймер на видео.' (#1002) from Hasan/eatvio_app:personalized_feed into personalized_feed

Reviewed-on: eatvio/eatvio_app#1002
This commit is contained in:
2026-07-22 07:26:28 +00:00

View File

@@ -244,46 +244,67 @@ class _BlogPostMediaContent extends StatefulWidget {
} }
class _BlogPostMediaContentState extends State<_BlogPostMediaContent> { class _BlogPostMediaContentState extends State<_BlogPostMediaContent> {
static const _counterDisplayDuration = Duration(seconds: 2); static const _counterDisplayDuration = Duration(seconds: 1);
bool _isCounterVisible = false; bool _isCounterVisible = false;
Timer? _counterHideTimer; Timer? _counterHideTimer;
bool get _isCurrentSlideVideo =>
widget.videoEmbedUrl != null && widget.currentGalleryIndex == widget.galleryUrls.length;
bool get _shouldShowCounter => !_isCurrentSlideVideo || _isCounterVisible;
@override @override
void dispose() { void dispose() {
_counterHideTimer?.cancel(); _counterHideTimer?.cancel();
super.dispose(); super.dispose();
} }
@override
void didUpdateWidget(covariant _BlogPostMediaContent oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.currentGalleryIndex != widget.currentGalleryIndex) {
_scheduleCounterHideOnVideo();
}
}
void _scheduleCounterHideOnVideo() {
_counterHideTimer?.cancel();
if (!_isCurrentSlideVideo) return;
_counterHideTimer = Timer(_counterDisplayDuration, () {
if (mounted && _isCurrentSlideVideo) {
setState(() => _isCounterVisible = false);
}
});
}
bool _handleCarouselScroll(ScrollNotification notification) { bool _handleCarouselScroll(ScrollNotification notification) {
if (notification is ScrollStartNotification || notification is ScrollUpdateNotification) { if (notification is ScrollStartNotification || notification is ScrollUpdateNotification) {
_counterHideTimer?.cancel(); _counterHideTimer?.cancel();
if (!_isCounterVisible) { if (!_isCounterVisible) {
setState(() => _isCounterVisible = true); setState(() => _isCounterVisible = true);
} }
} else if (notification is ScrollEndNotification && _isCounterVisible) { } else if (notification is ScrollEndNotification && _isCounterVisible && _isCurrentSlideVideo) {
_counterHideTimer?.cancel(); _scheduleCounterHideOnVideo();
_counterHideTimer = Timer(_counterDisplayDuration, () {
if (mounted) {
setState(() => _isCounterVisible = false);
}
});
} }
return false; return false;
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final mediaContentCount = widget.videoEmbedUrl != null ? widget.galleryUrls.length + 1 : widget.galleryUrls.length; final hasVideo = widget.videoEmbedUrl != null;
final mediaContentCount = hasVideo ? widget.galleryUrls.length + 1 : widget.galleryUrls.length;
final showCarousel = mediaContentCount > 1;
return Column( return Column(
children: [ children: [
if (widget.galleryUrls.length > 1) ...[ if (showCarousel) ...[
Stack( Stack(
children: [ children: [
NotificationListener<ScrollNotification>( NotificationListener<ScrollNotification>(
onNotification: _handleCarouselScroll, onNotification: _handleCarouselScroll,
child: CarouselSlider.builder( child: CarouselSlider.builder(
itemCount: widget.galleryUrls.length + 1, itemCount: mediaContentCount,
itemBuilder: (context, itemIndex, _) { itemBuilder: (context, itemIndex, _) {
if (itemIndex == widget.galleryUrls.length) { if (itemIndex == widget.galleryUrls.length) {
if (widget.videoEmbedUrl != null) { if (widget.videoEmbedUrl != null) {
@@ -315,7 +336,7 @@ class _BlogPostMediaContentState extends State<_BlogPostMediaContent> {
right: 12, right: 12,
child: IgnorePointer( child: IgnorePointer(
child: AnimatedOpacity( child: AnimatedOpacity(
opacity: _isCounterVisible ? 1 : 0, opacity: _shouldShowCounter ? 1 : 0,
duration: const Duration(milliseconds: 150), duration: const Duration(milliseconds: 150),
child: _GalleryPhotoCounter(currentIndex: widget.currentGalleryIndex, total: mediaContentCount), child: _GalleryPhotoCounter(currentIndex: widget.currentGalleryIndex, total: mediaContentCount),
), ),