Migrated SendingInfoTo from using of end geometry to end point.

This commit is contained in:
23rd 2022-02-14 03:25:04 +03:00 committed by John Preston
parent 6939da2fd2
commit 0dc2e1a5ae
4 changed files with 18 additions and 15 deletions

View file

@ -5394,7 +5394,7 @@ void HistoryWidget::startMessageSendingAnimation(
Assert(item->mainView() != nullptr);
Assert(item->mainView()->media() != nullptr);
auto globalEndGeometry = rpl::merge(
auto globalEndTopLeft = rpl::merge(
_scroll->innerResizes() | rpl::to_empty,
session().data().newItemAdded() | rpl::to_empty,
geometryValue() | rpl::to_empty,
@ -5405,13 +5405,13 @@ void HistoryWidget::startMessageSendingAnimation(
const auto additional = (_list->height() == _scroll->height())
? view->height()
: 0;
return _list->mapToGlobal(view->innerGeometry().translated(
return _list->mapToGlobal(QPoint(
0,
_list->itemTop(view) - additional));
});
sendingAnimation.startAnimation({
.globalEndGeometry = std::move(globalEndGeometry),
.globalEndTopLeft = std::move(globalEndTopLeft),
.view = [=] { return item->mainView(); },
.paintContext = [=] { return _list->preparePaintContext({}); },
});

View file

@ -1582,18 +1582,17 @@ void ListWidget::startMessageSendingAnimation(
return;
}
auto globalEndGeometry = rpl::merge(
auto globalEndTopLeft = rpl::merge(
session().data().newItemAdded() | rpl::to_empty,
geometryValue() | rpl::to_empty
) | rpl::map([=] {
const auto view = viewForItem(item);
const auto additional = !_visibleTop ? view->height() : 0;
return mapToGlobal(
view->innerGeometry().translated(0, itemTop(view) - additional));
return mapToGlobal(QPoint(0, itemTop(view) - additional));
});
sendingAnimation.startAnimation({
.globalEndGeometry = std::move(globalEndGeometry),
.globalEndTopLeft = std::move(globalEndTopLeft),
.view = [=] { return viewForItem(item); },
.paintContext = [=] { return preparePaintContext({}); },
});

View file

@ -53,7 +53,7 @@ private:
const not_null<Window::SessionController*> _controller;
MessageSendingAnimationController::SendingInfoTo _toInfo;
QRect _from;
QRect _to;
QPoint _to;
QRect _innerContentRect;
Animations::Simple _animation;
@ -74,7 +74,8 @@ Content::Content(
, _controller(controller)
, _toInfo(std::move(to))
, _from(parent->mapFromGlobal(globalGeometryFrom))
, _innerContentRect(view()->media()->contentRectForReactions()) {
, _innerContentRect(view()->media()->contentRectForReactions())
, _minScale(float64(_from.height()) / _innerContentRect.height()) {
Expects(_toInfo.view != nullptr);
Expects(_toInfo.paintContext != nullptr);
@ -83,11 +84,10 @@ Content::Content(
raise();
base::take(
_toInfo.globalEndGeometry
_toInfo.globalEndTopLeft
) | rpl::distinct_until_changed(
) | rpl::start_with_next([=](const QRect &r) {
_to = parent->mapFromGlobal(r);
_minScale = float64(_from.height()) / _to.height();
) | rpl::start_with_next([=](const QPoint &p) {
_to = parent->mapFromGlobal(p);
}, lifetime());
_controller->session().downloaderTaskFinished(
@ -97,11 +97,15 @@ Content::Content(
resize(_innerContentRect.size());
const auto innerGeometry = view()->innerGeometry();
auto animationCallback = [=](float64 value) {
auto resultFrom = rect();
resultFrom.moveCenter(_from.center());
const auto resultTo = _to.topLeft() + _innerContentRect.topLeft();
const auto resultTo = _to
+ innerGeometry.topLeft()
+ _innerContentRect.topLeft();
const auto x = anim::interpolate(resultFrom.x(), resultTo.x(), value);
const auto y = anim::interpolate(resultFrom.y(), resultTo.y(), value);
moveToLeft(x, y);

View file

@ -29,7 +29,7 @@ public:
not_null<Window::SessionController*> controller);
struct SendingInfoTo {
rpl::producer<QRect> globalEndGeometry;
rpl::producer<QPoint> globalEndTopLeft;
Fn<not_null<HistoryView::Element*>()> view;
Fn<Ui::ChatPaintContext()> paintContext;
};