Opimize spoiler revealing.

This commit is contained in:
John Preston 2022-09-18 16:52:19 +04:00
parent 4f948699c0
commit 8bd0ff7925
10 changed files with 14 additions and 50 deletions

View file

@ -682,11 +682,6 @@ void InnerWidget::elementStartPremium(
void InnerWidget::elementCancelPremium(not_null<const Element*> view) {
}
void InnerWidget::elementShowSpoilerAnimation() {
_spoilerOpacity.stop();
_spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration);
}
void InnerWidget::saveState(not_null<SectionMemento*> memento) {
memento->setFilter(std::move(_filter));
memento->setAdmins(std::move(_admins));

View file

@ -143,7 +143,6 @@ public:
HistoryView::Element *replacing) override;
void elementCancelPremium(
not_null<const HistoryView::Element*> view) override;
void elementShowSpoilerAnimation() override;
~InnerWidget();
@ -327,8 +326,6 @@ private:
QPoint _trippleClickPoint;
base::Timer _trippleClickTimer;
Ui::Animations::Simple _spoilerOpacity;
FilterValue _filter;
QString _searchQuery;
std::vector<not_null<UserData*>> _admins;

View file

@ -273,12 +273,6 @@ public:
}
}
void elementShowSpoilerAnimation() override {
if (_widget) {
_widget->elementShowSpoilerAnimation();
}
}
not_null<HistoryView::ElementDelegate*> delegate() override {
return this;
}
@ -3307,11 +3301,6 @@ void HistoryInner::elementCancelPremium(not_null<const Element*> view) {
_emojiInteractions->cancelPremiumEffect(view);
}
void HistoryInner::elementShowSpoilerAnimation() {
_spoilerOpacity.stop();
_spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration);
}
auto HistoryInner::getSelectionState() const
-> HistoryView::TopBarWidget::SelectedState {
auto result = HistoryView::TopBarWidget::SelectedState {};

View file

@ -158,7 +158,6 @@ public:
not_null<const Element*> view,
Element *replacing);
void elementCancelPremium(not_null<const Element*> view);
void elementShowSpoilerAnimation();
void updateBotInfo(bool recount = true);
@ -503,8 +502,6 @@ private:
crl::time _touchTime = 0;
base::Timer _touchScrollTimer;
Ui::Animations::Simple _spoilerOpacity;
// _menu must be destroyed before _whoReactedMenuLifetime.
rpl::lifetime _whoReactedMenuLifetime;
base::unique_qptr<Ui::PopupMenu> _menu;

View file

@ -217,9 +217,6 @@ void SimpleElementDelegate::elementCancelPremium(
not_null<const Element*> view) {
}
void SimpleElementDelegate::elementShowSpoilerAnimation() {
}
TextSelection UnshiftItemSelection(
TextSelection selection,
uint16 byLength) {

View file

@ -106,7 +106,6 @@ public:
not_null<const Element*> view,
Element *replacing) = 0;
virtual void elementCancelPremium(not_null<const Element*> view) = 0;
virtual void elementShowSpoilerAnimation() = 0;
virtual ~ElementDelegate() {
}
@ -168,7 +167,6 @@ public:
not_null<const Element*> view,
Element *replacing) override;
void elementCancelPremium(not_null<const Element*> view) override;
void elementShowSpoilerAnimation() override;
protected:
[[nodiscard]] not_null<Window::SessionController*> controller() const {

View file

@ -1506,11 +1506,6 @@ void ListWidget::elementCancelPremium(not_null<const Element*> view) {
_emojiInteractions->cancelPremiumEffect(view);
}
void ListWidget::elementShowSpoilerAnimation() {
_spoilerOpacity.stop();
_spoilerOpacity.start([=] { update(); }, 0., 1., st::fadeWrapDuration);
}
void ListWidget::saveState(not_null<ListMemento*> memento) {
memento->setAroundPosition(_aroundPosition);
auto state = countScrollState();

View file

@ -303,8 +303,6 @@ public:
Element *replacing) override;
void elementCancelPremium(not_null<const Element*> view) override;
void elementShowSpoilerAnimation() override;
void setEmptyInfoWidget(base::unique_qptr<Ui::RpWidget> &&w);
~ListWidget();
@ -647,8 +645,6 @@ private:
ElementHighlighter _highlighter;
Ui::Animations::Simple _spoilerOpacity;
Ui::DraggingScrollManager _selectScroll;
InfoTooltip _topToast;

View file

@ -12,17 +12,21 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_element.h"
#include "main/main_session.h"
#include "window/window_session_controller.h"
#include "ui/spoiler_click_handler.h"
namespace HistoryView {
namespace {
class AnimatedSpoilerClickHandler final : public SpoilerClickHandler {
class AnimatedSpoilerClickHandler final : public ClickHandler {
public:
AnimatedSpoilerClickHandler() = default;
explicit AnimatedSpoilerClickHandler(Ui::Text::String &text)
: _text(text) {
}
void onClick(ClickContext context) const override;
private:
Ui::Text::String &_text;
};
void AnimatedSpoilerClickHandler::onClick(ClickContext context) const {
@ -32,11 +36,7 @@ void AnimatedSpoilerClickHandler::onClick(ClickContext context) const {
}
const auto my = context.other.value<ClickHandlerContext>();
if (const auto d = my.elementDelegate ? my.elementDelegate() : nullptr) {
d->elementShowSpoilerAnimation();
const auto nonconst = const_cast<AnimatedSpoilerClickHandler*>(this);
nonconst->setStartMs(crl::now());
SpoilerClickHandler::onClick({});
_text.setSpoilerRevealed(true, anim::type::normal);
if (const auto controller = my.sessionWindow.get()) {
controller->session().data().registerShownSpoiler(my.itemId);
}
@ -46,15 +46,15 @@ void AnimatedSpoilerClickHandler::onClick(ClickContext context) const {
} // namespace
void FillTextWithAnimatedSpoilers(Ui::Text::String &text) {
const auto link = std::make_shared<AnimatedSpoilerClickHandler>();
for (auto i = 0; i < text.spoilersCount(); i++) {
text.setSpoiler(i + 1, link);
if (text.hasSpoilers()) {
text.setSpoilerLink(
std::make_shared<AnimatedSpoilerClickHandler>(text));
}
}
void HideSpoilers(Ui::Text::String &text) {
for (auto i = 0; i < text.spoilersCount(); i++) {
text.setSpoilerShown(i + 1, false);
if (text.hasSpoilers()) {
text.setSpoilerRevealed(false, anim::type::instant);
}
}

@ -1 +1 @@
Subproject commit a60fe582ad9ab797ead0a18a9ed18e1892681c60
Subproject commit 1b429325e4d315f030b71da4262c07f2961ca494