Use Ui::PhoneInput for passport phone edit.

This commit is contained in:
John Preston 2018-04-10 21:11:43 +04:00
parent 1c48f33dc1
commit 11fd757e99
3 changed files with 46 additions and 21 deletions

View File

@ -188,7 +188,7 @@ PanelEditContact::Scheme GetContactScheme(Scope::Type type) {
using Scheme = PanelEditContact::Scheme;
switch (type) {
case Scope::Type::Phone: {
auto result = Scheme();
auto result = Scheme(Scheme::ValueType::Phone);
result.aboutExisting = lang(lng_passport_use_existing_phone);
result.newHeader = lang(lng_passport_new_phone);
result.aboutNew = lang(lng_passport_new_phone_code);
@ -207,7 +207,7 @@ PanelEditContact::Scheme GetContactScheme(Scope::Type type) {
} break;
case Scope::Type::Email: {
auto result = Scheme();
auto result = Scheme(Scheme::ValueType::Text);
result.aboutExisting = lang(lng_passport_use_existing_email);
result.newHeader = lang(lng_passport_new_email);
result.newPlaceholder = langFactory(lng_passport_email_title);

View File

@ -154,6 +154,9 @@ void VerifyBox::prepare() {
} // namespace
PanelEditContact::Scheme::Scheme(ValueType type) : type(type) {
}
PanelEditContact::PanelEditContact(
QWidget*,
not_null<PanelController*> controller,
@ -216,22 +219,42 @@ void PanelEditContact::setupControls(
Ui::FlatLabel::InitType::Simple,
st::passportFormHeader),
st::passportDetailsHeaderPadding);
_field = _content->add(
object_ptr<Ui::InputField>(
_content,
st::passportDetailsField,
nullptr,
data),
st::passportContactNewFieldPadding);
} else {
_field = _content->add(
object_ptr<Ui::InputField>(
_content,
st::passportContactField,
_scheme.newPlaceholder,
data),
st::passportContactFieldPadding);
}
const auto &fieldStyle = existing.isEmpty()
? st::passportContactField
: st::passportDetailsField;
const auto fieldPadding = existing.isEmpty()
? st::passportContactFieldPadding
: st::passportContactNewFieldPadding;
const auto fieldPlaceholder = existing.isEmpty()
? _scheme.newPlaceholder
: nullptr;
auto wrap = object_ptr<Ui::RpWidget>(_content);
if (_scheme.type == Scheme::ValueType::Phone) {
_field = Ui::CreateChild<Ui::PhoneInput>(
wrap.data(),
fieldStyle,
fieldPlaceholder,
data);
} else {
_field = Ui::CreateChild<Ui::MaskedInputField>(
wrap.data(),
fieldStyle,
fieldPlaceholder,
data);
}
_field->move(0, 0);
_field->heightValue(
) | rpl::start_with_next([=, pointer = wrap.data()](int height) {
pointer->resize(pointer->width(), height);
}, _field->lifetime());
wrap->widthValue(
) | rpl::start_with_next([=](int width) {
_field->resize(width, _field->height());
}, _field->lifetime());
_content->add(std::move(wrap), fieldPadding);
_content->add(
object_ptr<PanelLabel>(
_content,
@ -247,7 +270,7 @@ void PanelEditContact::setupControls(
save();
});
};
connect(_field, &Ui::InputField::submitted, submit);
connect(_field, &Ui::MaskedInputField::submitted, submit);
_done->addClickHandler(submit);
}

View File

@ -10,7 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rp_widget.h"
namespace Ui {
class InputField;
class MaskedInputField;
class PlainShadow;
class RoundButton;
class VerticalLayout;
@ -27,7 +27,9 @@ public:
Phone,
Text,
};
ValueType type = ValueType::Phone;
explicit Scheme(ValueType type);
ValueType type;
QString aboutExisting;
QString newHeader;
@ -63,7 +65,7 @@ private:
Scheme _scheme;
object_ptr<Ui::VerticalLayout> _content;
QPointer<Ui::InputField> _field;
QPointer<Ui::MaskedInputField> _field;
object_ptr<Ui::PlainShadow> _bottomShadow;
object_ptr<Ui::RoundButton> _done;