fix bug of indexer and button

Signed-off-by: luoying_ace_admin <luoying19@huawei.com>
This commit is contained in:
luoying_ace_admin
2022-04-12 20:32:04 +08:00
parent 83200e8f03
commit 0bc8237aa5
4 changed files with 27 additions and 17 deletions
@@ -31,36 +31,36 @@ const std::vector<V2::AlignStyle> ALIGN_STYLE = { V2::AlignStyle::LEFT, V2::Alig
void JSIndexer::Create(const JSCallbackInfo& args)
{
if (args.Length() >= 1 && args[0]->IsObject()) {
JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
auto param = JsonUtil::ParseJsonString(args[0]->ToString());
if (!param || param->IsNull()) {
LOGE("JSIndexer::Create param is null");
return;
}
std::vector<std::string> indexerArray;
JSRef<JSVal> arrayVal = obj->GetProperty("arrayValue");
if (!arrayVal->IsArray()) {
auto arrayVal = param->GetValue("arrayValue");
if (!arrayVal || !arrayVal->IsArray()) {
LOGW("info is invalid");
return;
}
JSRef<JSArray> array = JSRef<JSArray>::Cast(arrayVal);
int32_t length = static_cast<int32_t>(array->Length());
size_t length = static_cast<uint32_t>(arrayVal->GetArraySize());
if (length <= 0) {
LOGE("info is invalid");
return;
}
for (int32_t i = 0; i < length; i++) {
JSRef<JSVal> value = array->GetValueAt(i);
std::string tmp;
if (ParseJsString(value, tmp)) {
indexerArray.emplace_back(tmp);
for (size_t i = 0; i < length; i++) {
auto value = arrayVal->GetArrayItem(i);
if (!value) {
return;
}
indexerArray.emplace_back(value->GetString());
}
JSRef<JSVal> selectedVal = obj->GetProperty("selected");
if (!selectedVal->IsNumber()) {
LOGE("info is invalid");
return;
}
auto selectedVal = param->GetInt("selected", 0);
auto indexerComponent =
AceType::MakeRefPtr<V2::IndexerComponent>(indexerArray, selectedVal->ToNumber<int32_t>());
AceType::MakeRefPtr<V2::IndexerComponent>(indexerArray, selectedVal);
ViewStackProcessor::GetInstance()->Push(indexerComponent);
JSInteractableView::SetFocusNode(true);
args.ReturnSelf();
@@ -324,7 +324,7 @@ void RenderButton::OnMouseHoverEnterTest()
return;
}
ButtonType type = buttonComponent_->GetType();
if (isPhone_ && ((type == ButtonType::TEXT) || (type == ButtonType::NORMAL))) {
if ((isPhone_ || isTablet_) && ((type == ButtonType::TEXT) || (type == ButtonType::NORMAL))) {
needHoverColor_ = true;
MarkNeedRender();
} else {
@@ -457,6 +457,7 @@ void RenderButton::Update(const RefPtr<Component>& component)
isWatch_ = (SystemProperties::GetDeviceType() == DeviceType::WATCH);
isTv_ = (SystemProperties::GetDeviceType() == DeviceType::TV);
isPhone_ = (SystemProperties::GetDeviceType() == DeviceType::PHONE);
isTablet_ = (SystemProperties::GetDeviceType() == DeviceType::TABLET);
auto catchMode =
buttonComponent_->GetClickedEventId().IsEmpty() || buttonComponent_->GetClickedEventId().GetCatchMode();
static const int32_t bubbleModeVersion = 6;
@@ -178,6 +178,7 @@ protected:
bool isWatch_ = false;
bool isTv_ = false;
bool isPhone_ = false;
bool isTablet_ = false;
bool widthDefined_ = false;
bool heightDefined_ = false;
bool progressDisplay_ = false;
@@ -31,6 +31,14 @@ public:
bool OnKeyEvent(const KeyEvent& keyEvent) override;
bool IndexMoveUp();
bool IndexMoveDown();
bool CanUpdate(const RefPtr<Component>& newComponent) override
{
auto context = context_.Upgrade();
if (context && context->GetIsDeclarative()) {
return false;
}
return true;
}
private:
WeakPtr<RenderIndexerItem> prevFocusedItem_;