mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 01:03:08 +00:00
Search
Signed-off-by: sunfei <sunfei.sun@huawei.com> Change-Id: Ifc3c2fe8e59d1c617681034b9fd12602a66d41c5
This commit is contained in:
parent
cd9e25f1bc
commit
ce26c9999e
@ -181,7 +181,7 @@ void InitializeComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchCo
|
||||
searchComponent->SetCloseIconHotZoneHorizontal(searchTheme->GetCloseIconHotZoneSize());
|
||||
searchComponent->SetHoverColor(textFieldTheme->GetHoverColor());
|
||||
searchComponent->SetPressColor(textFieldTheme->GetPressColor());
|
||||
isPaddingChanged = true;
|
||||
isPaddingChanged = false;
|
||||
}
|
||||
|
||||
void PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>& searchComponent,
|
||||
@ -197,7 +197,7 @@ void PrepareSpecializedComponent(OHOS::Ace::RefPtr<OHOS::Ace::SearchComponent>&
|
||||
}
|
||||
searchComponent->SetTextDirection(TextDirection::RTL);
|
||||
textFieldComponent->SetTextDirection(TextDirection::RTL);
|
||||
UpdateDecorationStyle(boxComponent, textFieldComponent, boxBorder, true);
|
||||
UpdateDecorationStyle(boxComponent, textFieldComponent, boxBorder, false);
|
||||
if (GreatOrEqual(boxComponent->GetHeightDimension().Value(), 0.0)) {
|
||||
textFieldComponent->SetHeight(boxComponent->GetHeightDimension());
|
||||
}
|
||||
@ -231,7 +231,7 @@ void JSSearch::JSBind(BindingTarget globalObj)
|
||||
|
||||
JSClass<JSSearch>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
|
||||
JSClass<JSSearch>::StaticMethod("height", &JSSearch::SetHeight);
|
||||
JSClass<JSSearch>::StaticMethod("width", &JSSearch::SetWidth);
|
||||
JSClass<JSSearch>::StaticMethod("width", &JSViewAbstract::JsWidth);
|
||||
JSClass<JSSearch>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
|
||||
JSClass<JSSearch>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
|
||||
JSClass<JSSearch>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
|
||||
@ -255,13 +255,13 @@ void JSSearch::Create(const JSCallbackInfo& info)
|
||||
}
|
||||
|
||||
auto searchComponent = AceType::MakeRefPtr<OHOS::Ace::SearchComponent>();
|
||||
auto textFieldComponent = AceType::MakeRefPtr<OHOS::Ace::TextFieldComponent>();
|
||||
ViewStackProcessor::GetInstance()->Push(searchComponent);
|
||||
|
||||
auto textFieldComponent = AceType::MakeRefPtr<OHOS::Ace::TextFieldComponent>();
|
||||
auto textFieldTheme = GetTheme<TextFieldTheme>();
|
||||
auto searchTheme = GetTheme<SearchTheme>();
|
||||
|
||||
InitializeComponent(searchComponent, textFieldComponent, searchTheme, textFieldTheme);
|
||||
|
||||
PrepareSpecializedComponent(searchComponent, textFieldComponent);
|
||||
|
||||
auto param = JSRef<JSObject>::Cast(info[0]);
|
||||
@ -282,8 +282,6 @@ void JSSearch::Create(const JSCallbackInfo& info)
|
||||
auto src = icon->ToString();
|
||||
textFieldComponent->SetIconImage(src);
|
||||
}
|
||||
|
||||
ViewStackProcessor::GetInstance()->Push(searchComponent);
|
||||
}
|
||||
|
||||
void JSSearch::SetSearchButton(const std::string& text)
|
||||
@ -433,10 +431,11 @@ void JSSearch::SetHeight(const JSCallbackInfo& info)
|
||||
}
|
||||
Dimension value;
|
||||
if (!ParseJsDimensionVp(info[0], value)) {
|
||||
LOGE("The arg is wrong, it is supposed to be a number arguments");
|
||||
return;
|
||||
}
|
||||
if (LessNotEqual(value.Value(), 0.0)) {
|
||||
return;
|
||||
value.SetValue(0.0);
|
||||
}
|
||||
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
@ -445,31 +444,16 @@ void JSSearch::SetHeight(const JSCallbackInfo& info)
|
||||
LOGE("SearchComponent set height failed, SearchComponent is null.");
|
||||
return;
|
||||
}
|
||||
searchComponent->SetHeight(value);
|
||||
}
|
||||
|
||||
void JSSearch::SetWidth(const JSCallbackInfo& info)
|
||||
{
|
||||
JSViewAbstract::JsWidth(info);
|
||||
if (info.Length() < 1) {
|
||||
LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
|
||||
auto childComponent = searchComponent->GetChild();
|
||||
if (!childComponent) {
|
||||
LOGE("component error");
|
||||
return;
|
||||
}
|
||||
Dimension value;
|
||||
if (!ParseJsDimensionVp(info[0], value)) {
|
||||
auto textFieldComponent = AceType::DynamicCast<TextFieldComponent>(childComponent);
|
||||
if (!textFieldComponent) {
|
||||
LOGE("text component error");
|
||||
return;
|
||||
}
|
||||
if (LessNotEqual(value.Value(), 0.0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto searchComponent = AceType::DynamicCast<SearchComponent>(stack->GetMainComponent());
|
||||
if (!searchComponent) {
|
||||
LOGE("SearchComponent set height failed, SearchComponent is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
searchComponent->SetWidth(value);
|
||||
textFieldComponent->SetHeight(value);
|
||||
}
|
||||
}
|
@ -33,7 +33,6 @@ public:
|
||||
static void OnSubmit(const JSCallbackInfo& info);
|
||||
static void OnChange(const JSCallbackInfo& info);
|
||||
static void SetHeight(const JSCallbackInfo& info);
|
||||
static void SetWidth(const JSCallbackInfo& info);
|
||||
};
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -223,30 +223,6 @@ public:
|
||||
return style.editingStyle;
|
||||
}
|
||||
|
||||
void SetHeight(const Dimension& height)
|
||||
{
|
||||
auto& attribute = MaybeResetAttribute<SearchAttribute>(AttributeTag::SPECIALIZED_ATTR);
|
||||
attribute.searchHeight = height;
|
||||
}
|
||||
|
||||
const Dimension& GetHeight() const
|
||||
{
|
||||
auto& attribute = static_cast<SearchAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
|
||||
return attribute.searchHeight;
|
||||
}
|
||||
|
||||
void SetWidth(const Dimension& width)
|
||||
{
|
||||
auto& attribute = MaybeResetAttribute<SearchAttribute>(AttributeTag::SPECIALIZED_ATTR);
|
||||
attribute.searchWidth = width;
|
||||
}
|
||||
|
||||
const Dimension& GetWidth() const
|
||||
{
|
||||
auto& attribute = static_cast<SearchAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
|
||||
return attribute.searchWidth;
|
||||
}
|
||||
|
||||
protected:
|
||||
void InitSpecialized() override;
|
||||
bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override;
|
||||
|
@ -104,13 +104,7 @@ void RenderSearch::PerformLayout()
|
||||
if (!renderTextField) {
|
||||
return;
|
||||
}
|
||||
LayoutParam layout;
|
||||
layout.SetFixedSize(Size(searchComponent_->GetWidth().Value(), searchComponent_->GetHeight().Value()));
|
||||
if (layout.IsValid()) {
|
||||
renderTextField->Layout(layout);
|
||||
} else {
|
||||
renderTextField->Layout(GetLayoutParam());
|
||||
}
|
||||
renderTextField->Layout(GetLayoutParam());
|
||||
SetLayoutSize(renderTextField->GetLayoutSize());
|
||||
renderTextField->SetSubmitEvent([weak = WeakClaim(this)](const std::string& searchKey) {
|
||||
auto renderSearch = weak.Upgrade();
|
||||
@ -174,7 +168,17 @@ void RenderSearch::InitRect(const RefPtr<RenderTextField>& renderTextField)
|
||||
} else {
|
||||
searchTextRect_ = Rect();
|
||||
}
|
||||
renderTextField->SetPaddingHorizonForSearch(searchTextRect_.Width());
|
||||
|
||||
auto context = context_.Upgrade();
|
||||
if (context && context->GetIsDeclarative()) {
|
||||
double padding = searchTextRect_.Width() + rightBorderWidth +
|
||||
NormalizeToPx(closeIconHotZoneHorizontal_) -
|
||||
(NormalizeToPx(closeIconSize_) / 2.0);
|
||||
renderTextField->SetPaddingHorizonForSearch(padding);
|
||||
} else {
|
||||
renderTextField->SetPaddingHorizonForSearch(searchTextRect_.Width());
|
||||
}
|
||||
|
||||
renderTextField->MarkNeedLayout();
|
||||
|
||||
// Compute rect of close icon.
|
||||
@ -209,11 +213,14 @@ void RenderSearch::OnValueChanged(bool needFireChangeEvent, bool needFireSelectC
|
||||
if (textEditController_) {
|
||||
const auto& currentText = textEditController_->GetValue().text;
|
||||
showCloseIcon_ = !currentText.empty();
|
||||
auto renderTextField = AceType::DynamicCast<RenderTextField>(GetChildren().front());
|
||||
if (showCloseIcon_) {
|
||||
renderTextField->SetTextStyle(editingStyle_);
|
||||
} else {
|
||||
renderTextField->SetTextStyle(placeHoldStyle_);
|
||||
auto context = context_.Upgrade();
|
||||
if (context && context->GetIsDeclarative()) {
|
||||
auto renderTextField = AceType::DynamicCast<RenderTextField>(GetChildren().front());
|
||||
if (showCloseIcon_) {
|
||||
renderTextField->SetTextStyle(editingStyle_);
|
||||
} else {
|
||||
renderTextField->SetTextStyle(placeHoldStyle_);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -168,26 +168,6 @@ const TextStyle& SearchComponent::GetEditingStyle() const
|
||||
return declaration_->GetEditingStyle();
|
||||
}
|
||||
|
||||
void SearchComponent::SetHeight(const Dimension& height)
|
||||
{
|
||||
declaration_->SetHeight(height);
|
||||
}
|
||||
|
||||
const Dimension& SearchComponent::GetHeight() const
|
||||
{
|
||||
return declaration_->GetHeight();
|
||||
}
|
||||
|
||||
void SearchComponent::SetWidth(const Dimension& width)
|
||||
{
|
||||
declaration_->SetWidth(width);
|
||||
}
|
||||
|
||||
const Dimension& SearchComponent::GetWidth() const
|
||||
{
|
||||
return declaration_->GetWidth();
|
||||
}
|
||||
|
||||
void SearchComponent::SetDeclaration(const RefPtr<SearchDeclaration>& declaration)
|
||||
{
|
||||
if (declaration) {
|
||||
|
@ -80,12 +80,6 @@ public:
|
||||
void SetEditingStyle(const TextStyle& style);
|
||||
const TextStyle& GetEditingStyle() const;
|
||||
|
||||
void SetHeight(const Dimension& height);
|
||||
const Dimension& GetHeight() const;
|
||||
|
||||
void SetWidth(const Dimension& width);
|
||||
const Dimension& GetWidth() const;
|
||||
|
||||
void SetDeclaration(const RefPtr<SearchDeclaration>& declaration);
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user