mirror of
https://github.com/openharmony/ace_ace_engine.git
synced 2026-07-19 14:43:36 -04:00
!2237 BugFix:修复走焦异常
Merge pull request !2237 from bixuefeng/bugfix_focus_0415
This commit is contained in:
@@ -222,6 +222,7 @@ void JSButton::CreateWithLabel(const JSCallbackInfo& info)
|
||||
SetTypeAndStateEffect(JSRef<JSObject>::Cast(info[1]), buttonComponent);
|
||||
}
|
||||
ViewStackProcessor::GetInstance()->Push(buttonComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
|
||||
buttonComponent->SetMouseAnimationType(HoverAnimationType::SCALE);
|
||||
@@ -238,6 +239,7 @@ void JSButton::CreateWithChild(const JSCallbackInfo& info)
|
||||
SetTypeAndStateEffect(obj, buttonComponent);
|
||||
}
|
||||
ViewStackProcessor::GetInstance()->Push(buttonComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
buttonComponent->SetMouseAnimationType(HoverAnimationType::SCALE);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,7 @@ void JSHyperlink::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
|
||||
ViewStackProcessor::GetInstance()->Push(component);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -290,7 +290,7 @@ void JSImage::Create(const JSCallbackInfo& info)
|
||||
RefPtr<ImageComponent> imageComponent = AceType::MakeRefPtr<OHOS::Ace::ImageComponent>(src);
|
||||
imageComponent->SetUseSkiaSvg(false);
|
||||
ViewStackProcessor::GetInstance()->Push(imageComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(false);
|
||||
if (noPixMap) {
|
||||
return;
|
||||
|
||||
@@ -62,6 +62,7 @@ void JSIndexer::Create(const JSCallbackInfo& args)
|
||||
auto indexerComponent =
|
||||
AceType::MakeRefPtr<V2::IndexerComponent>(indexerArray, selectedVal);
|
||||
ViewStackProcessor::GetInstance()->Push(indexerComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
args.ReturnSelf();
|
||||
}
|
||||
|
||||
@@ -95,6 +95,7 @@ void JSList::Create(const JSCallbackInfo& args)
|
||||
}
|
||||
|
||||
ViewStackProcessor::GetInstance()->Push(listComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
args.ReturnSelf();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ void JSListItem::Create(const JSCallbackInfo& args)
|
||||
listItemComponent->SetType(args[0]->ToString());
|
||||
}
|
||||
ViewStackProcessor::GetInstance()->Push(listItemComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
args.ReturnSelf();
|
||||
}
|
||||
|
||||
@@ -1,201 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_side_bar.h"
|
||||
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "core/components/button/button_component.h"
|
||||
#include "core/components/side_bar/render_side_bar_container.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
|
||||
#include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
void JSSideBar::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
|
||||
return;
|
||||
}
|
||||
|
||||
SideBarContainerType style = SideBarContainerType::EMBED;
|
||||
if (!info[0]->IsNull()) {
|
||||
if (info[0]->IsBoolean()) {
|
||||
style = static_cast<SideBarContainerType>(info[0]->ToBoolean());
|
||||
} else if (info[0]->IsNumber()) {
|
||||
style = static_cast<SideBarContainerType>(info[0]->ToNumber<int>());
|
||||
} else {
|
||||
LOGE("The arg is wrong");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<RefPtr<Component>> children;
|
||||
auto sideBarContainer = AceType::MakeRefPtr<OHOS::Ace::SideBarContainerComponent>(children);
|
||||
sideBarContainer->SetMainStackSize(MainStackSize::MAX);
|
||||
sideBarContainer->SetSideBarContainerType(style);
|
||||
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
stack->Push(sideBarContainer);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
}
|
||||
|
||||
void JSSideBar::SetShowControlButton(bool isShow)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetShowControlButton(isShow);
|
||||
}
|
||||
|
||||
void JSSideBar::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSSideBar>::Declare("SideBarContainer");
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSSideBar>::StaticMethod("create", &JSSideBar::Create, opt);
|
||||
JSClass<JSSideBar>::StaticMethod("showSideBar", &JSSideBar::JsShowSideBar);
|
||||
JSClass<JSSideBar>::StaticMethod("controlButton", &JSSideBar::JsControlButton);
|
||||
JSClass<JSSideBar>::StaticMethod("showControlButton", &JSSideBar::SetShowControlButton);
|
||||
JSClass<JSSideBar>::StaticMethod("onChange", &JSSideBar::OnChange);
|
||||
JSClass<JSSideBar>::StaticMethod("sideBarWidth", &JSSideBar::JsSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("minSideBarWidth", &JSSideBar::JsMinSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("maxSideBarWidth", &JSSideBar::JsMaxSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
|
||||
JSClass<JSSideBar>::StaticMethod("width", SetWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("height", SetHeight);
|
||||
JSClass<JSSideBar>::StaticMethod("size", SetSize);
|
||||
JSClass<JSSideBar>::StaticMethod("width", &JSStack::SetWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("height", &JSStack::SetHeight);
|
||||
JSClass<JSSideBar>::StaticMethod("size", &JSStack::SetSize);
|
||||
JSClass<JSSideBar>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
|
||||
JSClass<JSSideBar>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
|
||||
JSClass<JSSideBar>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
|
||||
JSClass<JSSideBar>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
|
||||
JSClass<JSSideBar>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
|
||||
JSClass<JSSideBar>::Inherit<JSContainerBase>();
|
||||
JSClass<JSSideBar>::Inherit<JSViewAbstract>();
|
||||
JSClass<JSSideBar>::Bind(globalObj);
|
||||
}
|
||||
|
||||
void JSSideBar::OnChange(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!JSViewBindEvent(&SideBarContainerComponent::SetOnChange, info)) {
|
||||
LOGE("Failed to bind event");
|
||||
}
|
||||
info.ReturnSelf();
|
||||
}
|
||||
|
||||
void JSSideBar::JsSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsMaxSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarMaxWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsMinSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarMinWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsShowSideBar(bool isShow)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetShowSideBar(isShow);
|
||||
}
|
||||
|
||||
void JSSideBar::JsControlButton(const JSCallbackInfo& info)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!info[0]->IsNull() && info[0]->IsObject()) {
|
||||
JSRef<JSObject> value = JSRef<JSObject>::Cast(info[0]);
|
||||
JSRef<JSVal> width = value->GetProperty("width");
|
||||
JSRef<JSVal> height = value->GetProperty("height");
|
||||
JSRef<JSVal> left = value->GetProperty("left");
|
||||
JSRef<JSVal> top = value->GetProperty("top");
|
||||
JSRef<JSVal> icons = value->GetProperty("icons");
|
||||
|
||||
if (!width->IsNull() && width->IsNumber()) {
|
||||
component->SetButtonWidth(width->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!height->IsNull() && height->IsNumber()) {
|
||||
component->SetButtonHeight(height->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!left->IsNull() && left->IsNumber()) {
|
||||
component->SetButtonLeft(left->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!top->IsNull() && top->IsNumber()) {
|
||||
component->SetButtonTop(top->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!icons->IsNull() && icons->IsObject()) {
|
||||
JSRef<JSObject> iconsVal = JSRef<JSObject>::Cast(icons);
|
||||
JSRef<JSVal> showIcon = iconsVal->GetProperty("shown");
|
||||
JSRef<JSVal> switchingIcon = iconsVal->GetProperty("switching");
|
||||
JSRef<JSVal> hiddenIcon = iconsVal->GetProperty("hidden");
|
||||
std::string showIconStr;
|
||||
if (!showIcon->IsNull() && ParseJsMedia(showIcon, showIconStr)) {
|
||||
component->SetShowIcon(showIconStr);
|
||||
}
|
||||
std::string hiddenIconStr;
|
||||
if (!hiddenIcon->IsNull() && ParseJsMedia(hiddenIcon, hiddenIconStr)) {
|
||||
component->SetHiddenIcon(hiddenIconStr);
|
||||
}
|
||||
std::string switchingIconStr;
|
||||
if (!switchingIcon->IsNull() && ParseJsMedia(switchingIcon, switchingIconStr)) {
|
||||
component->SetSwitchIcon(switchingIconStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
/*
|
||||
* Copyright (c) 2022 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_side_bar.h"
|
||||
|
||||
#include "base/geometry/dimension.h"
|
||||
#include "core/components/button/button_component.h"
|
||||
#include "core/components/side_bar/render_side_bar_container.h"
|
||||
#include "frameworks/bridge/declarative_frontend/jsview/js_view_common_def.h"
|
||||
#include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
|
||||
|
||||
namespace OHOS::Ace::Framework {
|
||||
void JSSideBar::Create(const JSCallbackInfo& info)
|
||||
{
|
||||
if (info.Length() < 1) {
|
||||
LOGE("The arg is wrong, it is supposed to have at least 1 arguments");
|
||||
return;
|
||||
}
|
||||
|
||||
SideBarContainerType style = SideBarContainerType::EMBED;
|
||||
if (!info[0]->IsNull()) {
|
||||
if (info[0]->IsBoolean()) {
|
||||
style = static_cast<SideBarContainerType>(info[0]->ToBoolean());
|
||||
} else if (info[0]->IsNumber()) {
|
||||
style = static_cast<SideBarContainerType>(info[0]->ToNumber<int>());
|
||||
} else {
|
||||
LOGE("The arg is wrong");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
std::list<RefPtr<Component>> children;
|
||||
auto sideBarContainer = AceType::MakeRefPtr<OHOS::Ace::SideBarContainerComponent>(children);
|
||||
sideBarContainer->SetMainStackSize(MainStackSize::MAX);
|
||||
sideBarContainer->SetSideBarContainerType(style);
|
||||
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
stack->Push(sideBarContainer);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
}
|
||||
|
||||
void JSSideBar::SetShowControlButton(bool isShow)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
|
||||
component->SetShowControlButton(isShow);
|
||||
}
|
||||
|
||||
void JSSideBar::JSBind(BindingTarget globalObj)
|
||||
{
|
||||
JSClass<JSSideBar>::Declare("SideBarContainer");
|
||||
MethodOptions opt = MethodOptions::NONE;
|
||||
JSClass<JSSideBar>::StaticMethod("create", &JSSideBar::Create, opt);
|
||||
JSClass<JSSideBar>::StaticMethod("showSideBar", &JSSideBar::JsShowSideBar);
|
||||
JSClass<JSSideBar>::StaticMethod("controlButton", &JSSideBar::JsControlButton);
|
||||
JSClass<JSSideBar>::StaticMethod("showControlButton", &JSSideBar::SetShowControlButton);
|
||||
JSClass<JSSideBar>::StaticMethod("onChange", &JSSideBar::OnChange);
|
||||
JSClass<JSSideBar>::StaticMethod("sideBarWidth", &JSSideBar::JsSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("minSideBarWidth", &JSSideBar::JsMinSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("maxSideBarWidth", &JSSideBar::JsMaxSideBarWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
|
||||
JSClass<JSSideBar>::StaticMethod("width", SetWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("height", SetHeight);
|
||||
JSClass<JSSideBar>::StaticMethod("size", SetSize);
|
||||
JSClass<JSSideBar>::StaticMethod("width", &JSStack::SetWidth);
|
||||
JSClass<JSSideBar>::StaticMethod("height", &JSStack::SetHeight);
|
||||
JSClass<JSSideBar>::StaticMethod("size", &JSStack::SetSize);
|
||||
JSClass<JSSideBar>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
|
||||
JSClass<JSSideBar>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
|
||||
JSClass<JSSideBar>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
|
||||
JSClass<JSSideBar>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
|
||||
JSClass<JSSideBar>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
|
||||
JSClass<JSSideBar>::Inherit<JSContainerBase>();
|
||||
JSClass<JSSideBar>::Inherit<JSViewAbstract>();
|
||||
JSClass<JSSideBar>::Bind(globalObj);
|
||||
}
|
||||
|
||||
void JSSideBar::OnChange(const JSCallbackInfo& info)
|
||||
{
|
||||
if (!JSViewBindEvent(&SideBarContainerComponent::SetOnChange, info)) {
|
||||
LOGE("Failed to bind event");
|
||||
}
|
||||
info.ReturnSelf();
|
||||
}
|
||||
|
||||
void JSSideBar::JsSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsMaxSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarMaxWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsMinSideBarWidth(double length)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetSideBarMinWidth(Dimension(length, DimensionUnit::VP));
|
||||
}
|
||||
|
||||
void JSSideBar::JsShowSideBar(bool isShow)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
component->SetShowSideBar(isShow);
|
||||
}
|
||||
|
||||
void JSSideBar::JsControlButton(const JSCallbackInfo& info)
|
||||
{
|
||||
auto stack = ViewStackProcessor::GetInstance();
|
||||
auto component = AceType::DynamicCast<OHOS::Ace::SideBarContainerComponent>(stack->GetMainComponent());
|
||||
if (!component) {
|
||||
LOGE("side bar is null");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!info[0]->IsNull() && info[0]->IsObject()) {
|
||||
JSRef<JSObject> value = JSRef<JSObject>::Cast(info[0]);
|
||||
JSRef<JSVal> width = value->GetProperty("width");
|
||||
JSRef<JSVal> height = value->GetProperty("height");
|
||||
JSRef<JSVal> left = value->GetProperty("left");
|
||||
JSRef<JSVal> top = value->GetProperty("top");
|
||||
JSRef<JSVal> icons = value->GetProperty("icons");
|
||||
|
||||
if (!width->IsNull() && width->IsNumber()) {
|
||||
component->SetButtonWidth(width->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!height->IsNull() && height->IsNumber()) {
|
||||
component->SetButtonHeight(height->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!left->IsNull() && left->IsNumber()) {
|
||||
component->SetButtonLeft(left->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!top->IsNull() && top->IsNumber()) {
|
||||
component->SetButtonTop(top->ToNumber<double>());
|
||||
}
|
||||
|
||||
if (!icons->IsNull() && icons->IsObject()) {
|
||||
JSRef<JSObject> iconsVal = JSRef<JSObject>::Cast(icons);
|
||||
JSRef<JSVal> showIcon = iconsVal->GetProperty("shown");
|
||||
JSRef<JSVal> switchingIcon = iconsVal->GetProperty("switching");
|
||||
JSRef<JSVal> hiddenIcon = iconsVal->GetProperty("hidden");
|
||||
std::string showIconStr;
|
||||
if (!showIcon->IsNull() && ParseJsMedia(showIcon, showIconStr)) {
|
||||
component->SetShowIcon(showIconStr);
|
||||
}
|
||||
std::string hiddenIconStr;
|
||||
if (!hiddenIcon->IsNull() && ParseJsMedia(hiddenIcon, hiddenIconStr)) {
|
||||
component->SetHiddenIcon(hiddenIconStr);
|
||||
}
|
||||
std::string switchingIconStr;
|
||||
if (!switchingIcon->IsNull() && ParseJsMedia(switchingIcon, switchingIconStr)) {
|
||||
component->SetSwitchIcon(switchingIconStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
||||
@@ -452,7 +452,7 @@ void JSText::Create(const JSCallbackInfo& info)
|
||||
|
||||
auto textComponent = AceType::MakeRefPtr<OHOS::Ace::TextComponentV2>(data);
|
||||
ViewStackProcessor::GetInstance()->Push(textComponent);
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(false);
|
||||
|
||||
// Init text style, allowScale is not supported in declarative.
|
||||
|
||||
@@ -184,6 +184,8 @@ void JSTextInput::Create(const JSCallbackInfo& info)
|
||||
} else {
|
||||
LOGI("controller is nullptr");
|
||||
}
|
||||
JSInteractableView::SetFocusable(true);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
}
|
||||
|
||||
void JSTextInput::SetBackgroundColor(const JSCallbackInfo& info)
|
||||
|
||||
@@ -73,6 +73,7 @@ void JSTextPicker::Create(const JSCallbackInfo& info)
|
||||
|
||||
RefPtr<Component> pickerTextComponent = AceType::MakeRefPtr<OHOS::Ace::PickerTextComponent>();
|
||||
ViewStackProcessor::GetInstance()->Push(pickerTextComponent);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
|
||||
auto component = ViewStackProcessor::GetInstance()->GetMainComponent();
|
||||
|
||||
@@ -580,6 +580,7 @@ void JSWeb::Create(const JSCallbackInfo& info)
|
||||
webComponent->SetWebController(controller->GetController());
|
||||
}
|
||||
ViewStackProcessor::GetInstance()->Push(webComponent);
|
||||
JSInteractableView::SetFocusable(false);
|
||||
JSInteractableView::SetFocusNode(true);
|
||||
}
|
||||
|
||||
|
||||
@@ -326,7 +326,6 @@ RefPtr<FocusableComponent> ViewStackProcessor::GetFocusableComponent(bool create
|
||||
}
|
||||
if (createIfNotExist) {
|
||||
RefPtr<FocusableComponent> focusableComponent = AceType::MakeRefPtr<OHOS::Ace::FocusableComponent>();
|
||||
focusableComponent->SetFocusable(true);
|
||||
wrappingComponentsMap.emplace("focusable", focusableComponent);
|
||||
return focusableComponent;
|
||||
}
|
||||
|
||||
@@ -100,11 +100,17 @@ bool ListElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect
|
||||
return false;
|
||||
}
|
||||
LOGI("RequestNextFocus vertical:%{public}d reverse:%{public}d.", vertical, reverse);
|
||||
if (!UpdateFocusIndex()) {
|
||||
LOGE("Update focus index failed");
|
||||
return false;
|
||||
}
|
||||
bool ret = false;
|
||||
while (!ret) {
|
||||
int32_t focusIndex = list->RequestNextFocus(vertical, reverse);
|
||||
LOGI("Request next focus index = %{public}d", focusIndex);
|
||||
int32_t size = static_cast<int32_t>(GetChildrenList().size());
|
||||
if (focusIndex < 0 || focusIndex >= size) {
|
||||
LOGW("Invalid next focus index");
|
||||
return false;
|
||||
}
|
||||
auto iter = GetChildrenList().begin();
|
||||
@@ -120,6 +126,24 @@ bool ListElement::RequestNextFocus(bool vertical, bool reverse, const Rect& rect
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool ListElement::UpdateFocusIndex()
|
||||
{
|
||||
RefPtr<RenderList> list = AceType::DynamicCast<RenderList>(renderNode_);
|
||||
if (!list) {
|
||||
LOGE("Render grid is null.");
|
||||
return false;
|
||||
}
|
||||
int32_t index = 0;
|
||||
for (const auto& iter : GetChildrenList()) {
|
||||
if (iter->IsCurrentFocus()) {
|
||||
list->SetFocusIndex(index);
|
||||
return true;
|
||||
}
|
||||
++index;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
RefPtr<Element> ListElement::OnUpdateElement(const RefPtr<Element>& element, const RefPtr<Component>& component)
|
||||
{
|
||||
return UpdateChild(element, component);
|
||||
|
||||
@@ -44,6 +44,8 @@ public:
|
||||
size_t FindPreviousStickyListItem(size_t index) override;
|
||||
|
||||
bool RequestNextFocus(bool vertical, bool reverse, const Rect& rect) override;
|
||||
bool UpdateFocusIndex();
|
||||
|
||||
void OnPostFlush() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -225,6 +225,11 @@ public:
|
||||
|
||||
std::string ProvideRestoreInfo() override;
|
||||
|
||||
void SetFocusIndex(int32_t focusIndex)
|
||||
{
|
||||
focusIndex_ = focusIndex;
|
||||
}
|
||||
|
||||
protected:
|
||||
void UpdateAccessibilityAttr();
|
||||
bool HandleActionScroll(bool forward);
|
||||
|
||||
@@ -101,19 +101,19 @@ struct AxisEvent final {
|
||||
}
|
||||
static bool IsDirectionUp(AxisDirection direction)
|
||||
{
|
||||
return (static_cast<int32_t>(direction) & static_cast<int32_t>(AxisDirection::UP));
|
||||
return (static_cast<uint32_t>(direction) & static_cast<uint32_t>(AxisDirection::UP));
|
||||
}
|
||||
static bool IsDirectionDown(AxisDirection direction)
|
||||
{
|
||||
return (static_cast<int32_t>(direction) & static_cast<int32_t>(AxisDirection::DOWN));
|
||||
return (static_cast<uint32_t>(direction) & static_cast<uint32_t>(AxisDirection::DOWN));
|
||||
}
|
||||
static bool IsDirectionLeft(AxisDirection direction)
|
||||
{
|
||||
return (static_cast<int32_t>(direction) & static_cast<int32_t>(AxisDirection::LEFT));
|
||||
return (static_cast<uint32_t>(direction) & static_cast<uint32_t>(AxisDirection::LEFT));
|
||||
}
|
||||
static bool IsDirectionRight(AxisDirection direction)
|
||||
{
|
||||
return (static_cast<int32_t>(direction) & static_cast<int32_t>(AxisDirection::RIGHT));
|
||||
return (static_cast<uint32_t>(direction) & static_cast<uint32_t>(AxisDirection::RIGHT));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -395,12 +395,8 @@ bool FocusGroup::IsFocusable() const
|
||||
if (!FocusNode::IsFocusable()) {
|
||||
return false;
|
||||
}
|
||||
if (focusNodes_.size() > 0) {
|
||||
return std::any_of(focusNodes_.begin(), focusNodes_.end(),
|
||||
[](const RefPtr<FocusNode>& focusNode) { return focusNode->IsFocusable(); });
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return std::any_of(focusNodes_.begin(), focusNodes_.end(),
|
||||
[](const RefPtr<FocusNode>& focusNode) { return focusNode->IsFocusable(); });
|
||||
}
|
||||
|
||||
bool FocusGroup::GoToNextFocus(bool reverse, const Rect& rect)
|
||||
@@ -470,23 +466,23 @@ bool FocusGroup::OnKeyEvent(const KeyEvent& keyEvent)
|
||||
OnFocusMove(keyEvent.code);
|
||||
switch (keyEvent.code) {
|
||||
case KeyCode::TV_CONTROL_UP:
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'UP' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'UP' by KeyCode(%{public}d)", keyEvent.code);
|
||||
return RequestNextFocus(true, true, GetRect());
|
||||
case KeyCode::TV_CONTROL_DOWN:
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'DOWN' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'DOWN' by KeyCode(%{public}d)", keyEvent.code);
|
||||
return RequestNextFocus(true, false, GetRect());
|
||||
case KeyCode::TV_CONTROL_LEFT:
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'LEFT' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'LEFT' by KeyCode(%{public}d)", keyEvent.code);
|
||||
return RequestNextFocus(false, !AceApplicationInfo::GetInstance().IsRightToLeft(), GetRect());
|
||||
case KeyCode::TV_CONTROL_RIGHT:
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'RIGHT' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'RIGHT' by KeyCode(%{public}d)", keyEvent.code);
|
||||
return RequestNextFocus(false, AceApplicationInfo::GetInstance().IsRightToLeft(), GetRect());
|
||||
case KeyCode::KEY_TAB:
|
||||
if (keyEvent.pressedCodes.size() == 1) {
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'TAB' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'TAB' by KeyCode(%{public}d)", keyEvent.code);
|
||||
return RequestNextFocus(false, false, GetRect()) || RequestNextFocus(true, false, GetRect());
|
||||
} else {
|
||||
LOGI("FocusGroup::OnKeyEvent: RequestNextFocus 'SHIFT-TAB' by KeyCode(%{public}d)", keyEvent.code);
|
||||
LOGI("RequestNextFocus 'SHIFT-TAB' by KeyCode(%{public}d)", keyEvent.code);
|
||||
if (keyEvent.IsKey({ KeyCode::KEY_SHIFT_LEFT, KeyCode::KEY_TAB }) ||
|
||||
keyEvent.IsKey({ KeyCode::KEY_SHIFT_RIGHT, KeyCode::KEY_TAB })) {
|
||||
return RequestNextFocus(false, true, GetRect()) || RequestNextFocus(true, true, GetRect());
|
||||
|
||||
Reference in New Issue
Block a user