diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 5b1518d65..1b696ae8d 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -793,7 +793,10 @@ void Widget::setupMainMenuToggle() { } void Widget::setupStories() { - trackScroll(_stories.get()); + _stories->verticalScrollEvents( + ) | rpl::start_with_next([=](not_null e) { + _scroll->viewportEvent(e); + }, _stories->lifetime()); _storiesContents.fire(Stories::ContentForSession( &controller()->session(), diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.cpp b/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.cpp index b7f5abd3a..1a1a395d3 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.cpp +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.cpp @@ -152,6 +152,10 @@ rpl::producer<> List::loadMoreRequests() const { return _loadMoreRequests.events(); } +rpl::producer> List::verticalScrollEvents() const { + return _verticalScrollEvents.events(); +} + void List::requestExpanded(bool expanded) { if (_expanded != expanded) { _expanded = expanded; @@ -635,18 +639,30 @@ void List::validateName(not_null item) { } void List::wheelEvent(QWheelEvent *e) { - const auto horizontal = (e->angleDelta().x() != 0); - if (!horizontal || _state == State::Small) { + const auto phase = e->phase(); + const auto fullDelta = e->pixelDelta().isNull() + ? e->angleDelta() + : e->pixelDelta(); + if (phase == Qt::ScrollBegin || phase == Qt::ScrollEnd) { + _scrollingLock = Qt::Orientation(); + if (fullDelta.isNull()) { + return; + } + } + const auto vertical = qAbs(fullDelta.x()) < qAbs(fullDelta.y()); + if (_scrollingLock == Qt::Orientation() && phase != Qt::NoScrollPhase) { + _scrollingLock = vertical ? Qt::Vertical : Qt::Horizontal; + } + if (_scrollingLock == Qt::Vertical || (vertical && !_scrollLeftMax)) { + _verticalScrollEvents.fire(e); + return; + } else if (_state == State::Small) { e->ignore(); return; } - auto delta = horizontal - ? ((style::RightToLeft() ? -1 : 1) * (e->pixelDelta().x() - ? e->pixelDelta().x() - : e->angleDelta().x())) - : (e->pixelDelta().y() - ? e->pixelDelta().y() - : e->angleDelta().y()); + const auto delta = vertical + ? fullDelta.y() + : ((style::RightToLeft() ? -1 : 1) * fullDelta.x()); const auto now = _scrollLeft; const auto used = now - delta; diff --git a/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.h b/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.h index a870f83d6..3182d7229 100644 --- a/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.h +++ b/Telegram/SourceFiles/dialogs/ui/dialogs_stories_list.h @@ -91,6 +91,9 @@ public: [[nodiscard]] rpl::producer<> entered() const; [[nodiscard]] rpl::producer<> loadMoreRequests() const; + [[nodiscard]] auto verticalScrollEvents() const + -> rpl::producer>; + private: struct Layout; enum class State { @@ -177,6 +180,7 @@ private: int _scrollLeft = 0; int _scrollLeftMax = 0; bool _dragging = false; + Qt::Orientation _scrollingLock = {}; Ui::Animations::Simple _expandedAnimation; Ui::Animations::Simple _expandCatchUpAnimation; @@ -188,6 +192,8 @@ private: int _selected = -1; int _pressed = -1; + rpl::event_stream> _verticalScrollEvents; + base::unique_qptr _menu; base::has_weak_ptr _menuGuard;