!2054 修复Popup使用自定义builder时多余的padding和js侧watch方法触发时没有实例ID的问题

Merge pull request !2054 from yanshuifeng/0328
This commit is contained in:
openharmony_ci
2022-03-31 09:19:50 +00:00
committed by Gitee
12 changed files with 71 additions and 28 deletions
+2 -3
View File
@@ -326,7 +326,7 @@ void UIContentImpl::CommonInitialize(OHOS::Rosen::Window* window, const std::str
if (hapInfo) {
pageProfile = hapInfo->pages;
const std::string profilePrefix = "@profile:";
if (pageProfile.find(profilePrefix) == 0) {
if (pageProfile.compare(0, profilePrefix.size(), profilePrefix) == 0) {
pageProfile = pageProfile.substr(profilePrefix.length()).append(".json");
}
LOGI("In stage mode, pageProfile:%{public}s", pageProfile.c_str());
@@ -577,8 +577,7 @@ bool UIContentImpl::ProcessKeyEvent(const std::shared_ptr<OHOS::MMI::KeyEvent>&
auto container = Platform::AceContainer::GetContainer(instanceId_);
if (container) {
auto aceView = static_cast<Platform::FlutterAceView*>(container->GetAceView());
Platform::FlutterAceView::DispatchKeyEvent(aceView, touchEvent);
return true;
return Platform::FlutterAceView::DispatchKeyEvent(aceView, touchEvent);
}
return false;
}
@@ -1746,6 +1746,8 @@ class View extends NativeView {
}
propertyHasChanged(info) {
if (info) {
// need to sync container instanceId to switch instanceId in C++ side.
this.syncInstanceId();
if (this.propsUsedForRender.has(info)) {
console.debug(`${this.constructor.name}: propertyHasChanged ['${info || "unknowm"}']. View needs update`);
this.markNeedUpdate();
@@ -1758,6 +1760,7 @@ class View extends NativeView {
console.debug(`${this.constructor.name}: propertyHasChanged ['${info || "unknowm"}']. calling @Watch function`);
cb.call(this, info);
}
this.restoreInstanceId();
} // if info avail.
}
propertyRead(info) {
@@ -26,6 +26,7 @@ namespace OHOS::Ace::Framework {
JSView::JSView(const std::string& viewId, JSRef<JSObject> jsObject, JSRef<JSFunc> jsRenderFunction) : viewId_(viewId)
{
jsViewFunction_ = AceType::MakeRefPtr<ViewFunctions>(jsObject, jsRenderFunction);
instanceId_ = Container::CurrentId();
LOGD("JSView constructor");
}
@@ -132,7 +133,7 @@ RefPtr<OHOS::Ace::Component> JSView::InternalRender(const RefPtr<Component>& par
*/
void JSView::MarkNeedUpdate()
{
ACE_DCHECK((!GetElement().Invalid()) && "JSView's ComposedElement must be created before requesting an update");
ACE_DCHECK((!GetElement().Invalid()));
ACE_SCOPED_TRACE("JSView::MarkNeedUpdate");
auto element = GetElement().Upgrade();
@@ -142,6 +143,17 @@ void JSView::MarkNeedUpdate()
needsUpdate_ = true;
}
void JSView::SyncInstanceId()
{
restoreInstanceId_ = Container::CurrentId();
ContainerScope::UpdateCurrent(instanceId_);
}
void JSView::RestoreInstanceId()
{
ContainerScope::UpdateCurrent(restoreInstanceId_);
}
void JSView::Destroy(JSView* parentCustomView)
{
LOGD("JSView::Destroy start");
@@ -177,6 +189,8 @@ void JSView::JSBind(BindingTarget object)
JSClass<JSView>::Declare("NativeView");
JSClass<JSView>::StaticMethod("create", &JSView::Create);
JSClass<JSView>::Method("markNeedUpdate", &JSView::MarkNeedUpdate);
JSClass<JSView>::Method("syncInstanceId", &JSView::SyncInstanceId);
JSClass<JSView>::Method("restoreInstanceId", &JSView::RestoreInstanceId);
JSClass<JSView>::Method("needsUpdate", &JSView::NeedsUpdate);
JSClass<JSView>::Method("markStatic", &JSView::MarkStatic);
JSClass<JSView>::CustomMethod("findChildById", &JSView::FindChildById);
@@ -44,6 +44,11 @@ public:
RefPtr<PageTransitionComponent> BuildPageTransitionComponent();
void MarkNeedUpdate();
void SyncInstanceId();
void RestoreInstanceId();
bool NeedsUpdate()
{
return needsUpdate_;
@@ -150,6 +155,9 @@ private:
// view id for custom view itself
std::string viewId_;
int32_t instanceId_ = -1;
int32_t restoreInstanceId_ = -1;
WeakPtr<OHOS::Ace::ComposedElement> element_ = nullptr;
bool needsUpdate_ = false;
bool isStatic_ = false;
@@ -510,6 +510,7 @@ void ParseCustomPopupParam(
popupComponent->SetCustomComponent(customComponent);
auto popupParam = popupComponent->GetPopupParam();
popupParam->SetUseCustomComponent(true);
auto placementValue = popupObj->GetProperty("placement");
if (placementValue->IsNumber()) {
auto placement = placementValue->ToNumber<int32_t>();
@@ -105,6 +105,8 @@ abstract class View extends NativeView implements
propertyHasChanged(info?: PropertyInfo): void {
if (info) {
// need to sync container instanceId to switch instanceId in C++ side.
this.syncInstanceId();
if (this.propsUsedForRender.has(info)) {
console.debug(`${this.constructor.name}: propertyHasChanged ['${info || "unknowm"}']. View needs update`);
this.markNeedUpdate();
@@ -116,6 +118,7 @@ abstract class View extends NativeView implements
console.debug(`${this.constructor.name}: propertyHasChanged ['${info || "unknowm"}']. calling @Watch function`);
cb.call(this, info);
}
this.restoreInstanceId();
} // if info avail.
}
@@ -17,6 +17,7 @@ declare class NativeView {
constructor(compilerAssignedUniqueChildId: string, parent: View);
markNeedUpdate(): void;
findChildById(compilerAssignedUniqueChildId: string): View;
syncInstanceId(): void;
restoreInstanceId(): void;
static create(newView: View): void;
}
@@ -78,6 +78,7 @@ void RenderBubble::Update(const RefPtr<Component>& component)
arrowOffset_ = bubble->GetPopupParam()->GetArrowOffset();
targetId_ = bubble->GetPopupParam()->GetTargetId();
weakStack_ = bubble->GetWeakStack();
useCustom_ = bubble->GetPopupParam()->IsUseCustom();
SetDisableTouchEvent(bubble->IsDisabledStatus());
SetInterceptTouchEvent(bubbleComponent_->GetPopupParam()->HasAction() || bubble->IsDisabledStatus());
@@ -145,14 +146,17 @@ void RenderBubble::PerformLayout()
InitTargetSizeAndPosition();
SetLayoutSize(GetLayoutParam().GetMaxSize());
LayoutParam innerLayout = GetLayoutParam();
if (SystemProperties::GetDevcieOrientation() == DeviceOrientation::PORTRAIT) {
innerLayout.SetMaxSize(Size(
innerLayout.GetMaxSize().Width() - NormalizeToPx(GRID_MARGIN_PORTRAIT), innerLayout.GetMaxSize().Height()));
} else {
double colWidth =
(innerLayout.GetMaxSize().Width() - NormalizeToPx(GRID_SPACING_TOTAL)) / GRID_NUMBER_LANDSCAPE;
innerLayout.SetMaxSize(Size(
colWidth * BUBBLR_GRID_MAX_LANDSCAPE + NormalizeToPx(GRID_SPACING) * 5, innerLayout.GetMaxSize().Height()));
if (!useCustom_) {
if (SystemProperties::GetDevcieOrientation() == DeviceOrientation::PORTRAIT) {
innerLayout.SetMaxSize(Size(innerLayout.GetMaxSize().Width() - NormalizeToPx(GRID_MARGIN_PORTRAIT),
innerLayout.GetMaxSize().Height()));
} else {
static const int32_t gridGaps = 5;
double colWidth =
(innerLayout.GetMaxSize().Width() - NormalizeToPx(GRID_SPACING_TOTAL)) / GRID_NUMBER_LANDSCAPE;
innerLayout.SetMaxSize(Size(colWidth * BUBBLR_GRID_MAX_LANDSCAPE + NormalizeToPx(GRID_SPACING) * gridGaps,
innerLayout.GetMaxSize().Height()));
}
}
if (!GetChildren().empty()) {
const auto& child = GetChildren().front();
@@ -67,6 +67,7 @@ protected:
// Is there has enough space for showing arrow.
bool showTopArrow_ = true;
bool showBottomArrow_ = true;
bool useCustom_ = false;
Edge padding_;
Edge margin_;
Border border_;
@@ -177,12 +177,23 @@ public:
enableArrow_ = enableArrow;
}
bool IsUseCustom() const
{
return useCustom_;
}
void SetUseCustomComponent(bool useCustom)
{
useCustom_ = useCustom;
}
private:
bool isShow_ = true;
bool hasAction_ = false;
bool enableArrow_ = true;
bool isMaskColorSetted_ = false;
bool isBackgrouhdColorSetted_ = false;
bool useCustom_ = false;
Color maskColor_;
Color backgroundColor_;
Placement placement_ = Placement::BOTTOM;
@@ -31,15 +31,14 @@ constexpr Dimension DEFAULT_FONT_SIZE = 14.0_fp;
constexpr Dimension BUTTON_PADDING = 8.0_fp;
constexpr Dimension BUTTON_ZERO_PADDING = 0.0_fp;
}
} // namespace
RefPtr<Element> PopupComponentV2::CreateElement()
{
return AceType::MakeRefPtr<PopupElementV2>(GetId());
}
void PopupComponentV2::Initialization(
const RefPtr<ThemeManager>& themeManager, const WeakPtr<PipelineContext>& context)
void PopupComponentV2::Initialization(const RefPtr<ThemeManager>& themeManager, const WeakPtr<PipelineContext>& context)
{
if (hasInitialization_) {
return;
@@ -75,11 +74,12 @@ void PopupComponentV2::Initialization(
box->SetBackDecoration(decoration);
}
decoration->SetBorderRadius(popupTheme->GetRadius());
auto padding = popupTheme->GetPadding();
box->SetPadding(padding);
if (!customComponent_) {
auto padding = popupTheme->GetPadding();
box->SetPadding(padding);
GetPopupParam()->SetPadding(padding);
}
box->SetChild(child);
GetPopupParam()->SetPadding(padding);
GetPopupParam()->SetBorder(decoration->GetBorder());
if (!GetPopupParam()->IsMaskColorSetted()) {
GetPopupParam()->SetMaskColor(popupTheme->GetMaskColor());
@@ -120,12 +120,10 @@ const RefPtr<Component> PopupComponentV2::CreateMessage()
const RefPtr<Component> PopupComponentV2::CreateButtons()
{
std::list<RefPtr<Component>> rowChildren;
rowChildren.emplace_back(
SetPadding(CreateButton(primaryButtonProperties_),
Edge(BUTTON_PADDING, BUTTON_ZERO_PADDING, BUTTON_PADDING, BUTTON_ZERO_PADDING)));
rowChildren.emplace_back(
SetPadding(CreateButton(secondaryButtonProperties_),
Edge(BUTTON_PADDING, BUTTON_ZERO_PADDING, BUTTON_PADDING, BUTTON_ZERO_PADDING)));
rowChildren.emplace_back(SetPadding(CreateButton(primaryButtonProperties_),
Edge(BUTTON_PADDING, BUTTON_ZERO_PADDING, BUTTON_PADDING, BUTTON_ZERO_PADDING)));
rowChildren.emplace_back(SetPadding(CreateButton(secondaryButtonProperties_),
Edge(BUTTON_PADDING, BUTTON_ZERO_PADDING, BUTTON_PADDING, BUTTON_ZERO_PADDING)));
auto row = AceType::MakeRefPtr<RowComponent>(FlexAlign::FLEX_END, FlexAlign::CENTER, rowChildren);
row->SetMainAxisSize(MainAxisSize::MIN);
auto box = AceType::MakeRefPtr<BoxComponent>();
@@ -264,11 +264,11 @@ HWTEST_F(RenderTabBarTest, RenderTabBarTest004, TestSize.Level1)
*/
renderRoot->PerformLayout();
renderTabBar->SetIndex(-1);
ASSERT_EQ(renderTabBar->GetIndex(), 0);
ASSERT_EQ(renderTabBar->GetIndex(), 1);
renderTabBar->SetIndex(1);
ASSERT_EQ(renderTabBar->GetIndex(), 1);
renderTabBar->SetIndex(SMALLTABSIZE);
ASSERT_EQ(renderTabBar->GetIndex(), 0);
ASSERT_EQ(renderTabBar->GetIndex(), 1);
}
} // namespace OHOS::Ace