Fixed changing of button style between states within single intro step.

This commit is contained in:
23rd 2022-12-29 23:25:53 +03:00
parent 567216f41f
commit 693ff3398e
5 changed files with 41 additions and 27 deletions

View File

@ -100,10 +100,13 @@ CodeWidget::CodeWidget(
_code->setDigitsCountMax(getData()->codeLength);
setTitleText(getData()->codeByFragmentUrl.isEmpty()
? rpl::single(Ui::FormatPhone(getData()->phone))
: tr::lng_intro_fragment_title());
updateDescText();
setTitleText(_isFragment.value(
) | rpl::map([=](bool isFragment) {
return !isFragment
? rpl::single(Ui::FormatPhone(getData()->phone))
: tr::lng_intro_fragment_title();
}) | rpl::flatten_latest());
account->setHandleLoginCode([=](const QString &code) {
_code->setText(code);
@ -126,6 +129,7 @@ int CodeWidget::errorTop() const {
void CodeWidget::updateDescText() {
const auto byTelegram = getData()->codeByTelegram;
const auto isFragment = !getData()->codeByFragmentUrl.isEmpty();
_isFragment = isFragment;
setDescriptionText(
isFragment
? tr::lng_intro_fragment_about(
@ -136,8 +140,7 @@ void CodeWidget::updateDescText() {
Ui::Text::RichLangValue)
: (byTelegram ? tr::lng_code_from_telegram : tr::lng_code_desc)(
Ui::Text::RichLangValue));
if (isFragment) {
} else if (getData()->codeByTelegram) {
if (getData()->codeByTelegram) {
_noTelegramCode->show();
_callTimer.cancel();
} else {
@ -420,15 +423,19 @@ void CodeWidget::submitCode() {
}
rpl::producer<QString> CodeWidget::nextButtonText() const {
return getData()->codeByFragmentUrl.isEmpty()
? Step::nextButtonText()
: tr::lng_intro_fragment_button();
return _isFragment.value(
) | rpl::map([=](bool isFragment) {
return isFragment
? tr::lng_intro_fragment_button()
: Step::nextButtonText();
}) | rpl::flatten_latest();
}
const style::RoundButton *CodeWidget::nextButtonStyle() const {
return !getData()->codeByFragmentUrl.isEmpty()
? &st::introFragmentButton
: nullptr;
rpl::producer<const style::RoundButton*> CodeWidget::nextButtonStyle() const {
return _isFragment.value(
) | rpl::map([](bool isFragment) {
return isFragment ? &st::introFragmentButton : nullptr;
});
}
void CodeWidget::noTelegramCode() {

View File

@ -56,7 +56,7 @@ public:
void cancelled() override;
void submit() override;
rpl::producer<QString> nextButtonText() const override;
const style::RoundButton *nextButtonStyle() const override;
rpl::producer<const style::RoundButton*> nextButtonStyle() const override;
void updateDescText();
@ -96,6 +96,8 @@ private:
QString _sentCode;
mtpRequestId _sentRequest = 0;
rpl::variable<bool> _isFragment = false;
base::Timer _callTimer;
CallStatus _callStatus = CallStatus();
int _callTimeout;

View File

@ -119,8 +119,8 @@ rpl::producer<QString> Step::nextButtonText() const {
return tr::lng_intro_next();
}
const style::RoundButton *Step::nextButtonStyle() const {
return nullptr;
rpl::producer<const style::RoundButton*> Step::nextButtonStyle() const {
return rpl::single((const style::RoundButton*)(nullptr));
}
void Step::goBack() {

View File

@ -81,7 +81,8 @@ public:
virtual void submit() = 0;
[[nodiscard]] virtual rpl::producer<QString> nextButtonText() const;
[[nodiscard]] virtual const style::RoundButton *nextButtonStyle() const;
[[nodiscard]] virtual auto nextButtonStyle() const
-> rpl::producer<const style::RoundButton*>;
[[nodiscard]] int contentLeft() const;
[[nodiscard]] int contentTop() const;

View File

@ -342,17 +342,21 @@ void Widget::historyMove(StackAction action, Animate animate) {
hideAndDestroy(std::exchange(_terms, { nullptr }));
}
{
const auto st = getStep()->nextButtonStyle();
const auto nextStyle = st ? st : &st::introNextButton;
if (_nextStyle != nextStyle) {
_nextStyle = nextStyle;
_next = nullptr;
_next.create(
this,
object_ptr<Ui::RoundButton>(this, nullptr, *nextStyle));
showControls();
updateControlsGeometry();
}
getStep()->nextButtonStyle(
) | rpl::start_with_next([=](const style::RoundButton *st) {
const auto nextStyle = st ? st : &st::introNextButton;
if (_nextStyle != nextStyle) {
_nextStyle = nextStyle;
const auto wasShown = _next->toggled();
_next.destroy();
_next.create(
this,
object_ptr<Ui::RoundButton>(this, nullptr, *nextStyle));
showControls();
updateControlsGeometry();
_next->toggle(wasShown, anim::type::instant);
}
}, _next->lifetime());
}
getStep()->finishInit();