From fa8ed186d86d406d03f1b02b1ce728da9a0a228a Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 10 Jun 2024 10:55:44 +0400 Subject: [PATCH] Improve field fade conditions. --- .../chat_helpers/message_field.cpp | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/message_field.cpp b/Telegram/SourceFiles/chat_helpers/message_field.cpp index d65a7acf9..cd7180218 100644 --- a/Telegram/SourceFiles/chat_helpers/message_field.cpp +++ b/Telegram/SourceFiles/chat_helpers/message_field.cpp @@ -580,11 +580,21 @@ void InitMessageFieldFade( }, topFade->lifetime()); const auto descent = field->st().style.font->descent; - topFade->show(); - bottomFade->showOn(field->scrollTop().value( - ) | rpl::map([field, descent](int scroll) { - return (scroll + descent) < field->scrollTopMax(); - }) | rpl::distinct_until_changed()); + rpl::merge( + field->changes(), + field->scrollTop().changes() | rpl::to_empty, + field->sizeValue() | rpl::to_empty + ) | rpl::start_with_next([=] { + const auto topHidden = !field->scrollTop().current(); + if (topFade->isHidden() != topHidden) { + topFade->setVisible(!topHidden); + } + const auto adjusted = field->scrollTop().current() + descent; + const auto bottomHidden = (adjusted >= field->scrollTopMax()); + if (bottomFade->isHidden() != bottomHidden) { + bottomFade->setVisible(!bottomHidden); + } + }, topFade->lifetime()); } InlineBotQuery ParseInlineBotQuery(