mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-10-07 16:33:54 +00:00
提供overlay实例
Signed-off-by: fan_pan <fanpan10@huawei.com> Change-Id: Ifdcaa187524f009a0b7127f5245bf6704c99eea7
This commit is contained in:
parent
0da3d475c9
commit
5a63833a8d
@ -16,7 +16,7 @@
|
||||
class Font {
|
||||
/**
|
||||
* Construct new instance of Font.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -48,7 +48,7 @@ class Font {
|
||||
class MediaQuery {
|
||||
/**
|
||||
* Construct new instance of MediaQuery.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -169,7 +169,7 @@ class MeasureUtils {
|
||||
class UIContext {
|
||||
/**
|
||||
* Construct new instance of UIContext.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -221,6 +221,12 @@ class UIContext {
|
||||
}
|
||||
return this.componentUtils_;
|
||||
}
|
||||
|
||||
getOverlay() {
|
||||
this.overlay_ = new Overlay(this.instanceId_);
|
||||
return this.overlay_;
|
||||
}
|
||||
|
||||
animateTo(value, event) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
Context.animateTo(value, event);
|
||||
@ -347,7 +353,7 @@ class UIContext {
|
||||
class FocusController {
|
||||
/**
|
||||
* Construct new instance of FocusController.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 12
|
||||
*/
|
||||
@ -372,7 +378,7 @@ class FocusController {
|
||||
class ComponentUtils {
|
||||
/**
|
||||
* Construct new instance of ComponentUtils.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -391,7 +397,7 @@ class ComponentUtils {
|
||||
class Router {
|
||||
/**
|
||||
* Construct new instance of Font.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -547,7 +553,7 @@ class Router {
|
||||
class PromptAction {
|
||||
/**
|
||||
* Construct new instance of PromptAction.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 10
|
||||
*/
|
||||
@ -592,7 +598,7 @@ class PromptAction {
|
||||
class AtomicServiceBar {
|
||||
/**
|
||||
* Construct new instance of AtomicServiceBar.
|
||||
* initialzie with instanceId.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 11
|
||||
*/
|
||||
@ -632,6 +638,54 @@ class AtomicServiceBar {
|
||||
}
|
||||
}
|
||||
|
||||
class Overlay {
|
||||
/**
|
||||
* Construct new instance of Overlay.
|
||||
* initialize with instanceId.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
* @since 12
|
||||
*/
|
||||
constructor(instanceId) {
|
||||
this.instanceId_ = instanceId;
|
||||
this.ohos_overlay = globalThis.requireNapi('overlay');
|
||||
}
|
||||
|
||||
addComponentContent(content) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.addFrameNode(content.getFrameNode());
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
removeComponentContent(content) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.removeFrameNode(content.getFrameNode());
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
showComponentContent(content) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.showNode(content.getFrameNode());
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
hideComponentContent(content) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.hideNode(content.getFrameNode());
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
show() {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.show();
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
hide() {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_overlay.hide();
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get UIContext instance.
|
||||
* @param instanceId obtained on the c++ side.
|
||||
|
@ -3194,4 +3194,64 @@ void FrontendDelegateDeclarative::CreateSnapshot(
|
||||
NG::ComponentSnapshot::Create(customNode, std::move(callback), enableInspector);
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->AddFrameNodeToOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->RemoveFrameNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->HideNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::ShowAllNodesOnOverlay()
|
||||
{
|
||||
auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowAllNodesOnOverlay();
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::HideAllNodesOnOverlay()
|
||||
{
|
||||
auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->HideAllNodesOnOverlay();
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -274,6 +274,13 @@ public:
|
||||
std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
|
||||
bool enableInspector) override;
|
||||
|
||||
void AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void ShowAllNodesOnOverlay() override;
|
||||
void HideAllNodesOnOverlay() override;
|
||||
|
||||
void RequestAnimationFrame(const std::string& callbackId) override;
|
||||
|
||||
void CancelAnimationFrame(const std::string& callbackId) override;
|
||||
|
@ -1036,4 +1036,63 @@ void FrontendDelegateDeclarativeNG::CreateSnapshot(
|
||||
#endif
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->AddFrameNodeToOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->RemoveFrameNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
auto task = [node, containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->HideNodeOnOverlay(node);
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::ShowAllNodesOnOverlay()
|
||||
{
|
||||
auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowAllNodesOnOverlay();
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::HideAllNodesOnOverlay()
|
||||
{
|
||||
auto task = [containerId = Container::CurrentId()](const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->HideAllNodesOnOverlay();
|
||||
};
|
||||
MainWindowOverlay(std::move(task));
|
||||
}
|
||||
} // namespace OHOS::Ace::Framework
|
||||
|
@ -215,6 +215,14 @@ public:
|
||||
void CreateSnapshot(std::function<void()>&& customBuilder,
|
||||
std::function<void(std::shared_ptr<Media::PixelMap>, int32_t, std::function<void()>)>&& callback,
|
||||
bool enableInspector) override;
|
||||
|
||||
void AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node) override;
|
||||
void ShowAllNodesOnOverlay() override;
|
||||
void HideAllNodesOnOverlay() override;
|
||||
|
||||
void RequestAnimationFrame(const std::string& callbackId) override {}
|
||||
|
||||
void CancelAnimationFrame(const std::string& callbackId) override {}
|
||||
|
@ -248,6 +248,13 @@ public:
|
||||
|
||||
virtual void GetUIFontConfig(FontConfigJsonInfo& fontConfigJsonInfo) {}
|
||||
|
||||
virtual void AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node) {}
|
||||
virtual void RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node) {}
|
||||
virtual void ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node) {}
|
||||
virtual void HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node) {}
|
||||
virtual void ShowAllNodesOnOverlay() {}
|
||||
virtual void HideAllNodesOnOverlay() {}
|
||||
|
||||
virtual SingleTaskExecutor GetAnimationJsTask() = 0;
|
||||
|
||||
virtual SingleTaskExecutor GetUiTask() = 0;
|
||||
|
@ -2090,6 +2090,9 @@ bool OverlayManager::RemoveOverlay(bool isBackPressed, bool isPageRouter)
|
||||
// stage node is at index 0, remove overlay at last
|
||||
auto overlay = DynamicCast<FrameNode>(rootNode->GetLastChild());
|
||||
CHECK_NULL_RETURN(overlay, false);
|
||||
if (overlay->GetTag() == V2::OVERLAY_ETS_TAG) {
|
||||
return false;
|
||||
}
|
||||
// close dialog with animation
|
||||
auto pattern = overlay->GetPattern();
|
||||
if (InstanceOf<ToastPattern>(pattern)) {
|
||||
@ -4189,6 +4192,119 @@ bool OverlayManager::ShowUIExtensionMenu(const RefPtr<NG::FrameNode>& uiExtNode,
|
||||
return true;
|
||||
}
|
||||
|
||||
void OverlayManager::CreateOverlayNode()
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "create overlay node enter");
|
||||
if (overlayNode_) {
|
||||
return;
|
||||
}
|
||||
auto rootNode = rootNodeWeak_.Upgrade();
|
||||
CHECK_NULL_VOID(rootNode);
|
||||
auto pipelineContext = PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(pipelineContext);
|
||||
auto stageManager = pipelineContext->GetStageManager();
|
||||
CHECK_NULL_VOID(stageManager);
|
||||
auto stageNode = stageManager->GetStageNode();
|
||||
CHECK_NULL_VOID(stageNode);
|
||||
overlayNode_ = FrameNode::CreateFrameNode(
|
||||
V2::OVERLAY_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(), AceType::MakeRefPtr<Pattern>());
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
overlayNode_->SetHitTestMode(HitTestMode::HTMTRANSPARENT_SELF);
|
||||
auto layoutProperty = overlayNode_->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
auto full = CalcLength(Dimension(1.0, DimensionUnit::PERCENT));
|
||||
layoutProperty->UpdateUserDefinedIdealSize(CalcSize(full, full));
|
||||
rootNode->AddChildAfter(overlayNode_, stageNode);
|
||||
}
|
||||
|
||||
void OverlayManager::AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "add FrameNode to the overlay node enter");
|
||||
CHECK_NULL_VOID(node);
|
||||
if (frameNodeSetOnOverlay_.find(node->GetId()) != frameNodeSetOnOverlay_.end()) {
|
||||
TAG_LOGW(AceLogTag::ACE_OVERLAY, "the node already exists in the overlay");
|
||||
return;
|
||||
}
|
||||
CreateOverlayNode();
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
overlayNode_->AddChild(node);
|
||||
frameNodeSetOnOverlay_.insert(node->GetId());
|
||||
overlayNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "delete the FrameNode on the overlay node enter");
|
||||
CHECK_NULL_VOID(node);
|
||||
if (frameNodeSetOnOverlay_.find(node->GetId()) == frameNodeSetOnOverlay_.end()) {
|
||||
TAG_LOGW(AceLogTag::ACE_OVERLAY, "the node does not exist in the overlay");
|
||||
return;
|
||||
}
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
overlayNode_->RemoveChild(node);
|
||||
frameNodeSetOnOverlay_.erase(node->GetId());
|
||||
if (overlayNode_->GetChildren().empty()) {
|
||||
auto rootNode = rootNodeWeak_.Upgrade();
|
||||
CHECK_NULL_VOID(rootNode);
|
||||
rootNode->RemoveChild(overlayNode_);
|
||||
overlayNode_.Reset();
|
||||
frameNodeSetOnOverlay_.clear();
|
||||
rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
return;
|
||||
}
|
||||
overlayNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "show the FrameNode on the overlay node enter");
|
||||
CHECK_NULL_VOID(node);
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
auto layoutProperty = node->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
node->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "hide the FrameNode on the overlay node enter");
|
||||
CHECK_NULL_VOID(node);
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
auto layoutProperty = node->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
node->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::ShowAllNodesOnOverlay()
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "show all FrameNodes on the overlay node enter");
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
for (auto& child : overlayNode_->GetChildren()) {
|
||||
auto frameNode = DynamicCast<FrameNode>(child);
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto layoutProperty = frameNode->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::VISIBLE);
|
||||
}
|
||||
overlayNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::HideAllNodesOnOverlay()
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "hide all FrameNodes on the overlay node enter");
|
||||
CHECK_NULL_VOID(overlayNode_);
|
||||
for (auto& child : overlayNode_->GetChildren()) {
|
||||
auto frameNode = DynamicCast<FrameNode>(child);
|
||||
CHECK_NULL_VOID(frameNode);
|
||||
auto layoutProperty = frameNode->GetLayoutProperty();
|
||||
CHECK_NULL_VOID(layoutProperty);
|
||||
layoutProperty->UpdateVisibility(VisibleType::GONE);
|
||||
}
|
||||
overlayNode_->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF_AND_CHILD);
|
||||
}
|
||||
|
||||
void OverlayManager::MarkDirty(PropertyChangeFlag flag)
|
||||
{
|
||||
auto root = rootNodeWeak_.Upgrade();
|
||||
|
@ -471,6 +471,14 @@ public:
|
||||
{
|
||||
return gatherNodeChildrenInfo_;
|
||||
}
|
||||
|
||||
void CreateOverlayNode();
|
||||
void AddFrameNodeToOverlay(const RefPtr<NG::FrameNode>& node);
|
||||
void RemoveFrameNodeOnOverlay(const RefPtr<NG::FrameNode>& node);
|
||||
void ShowNodeOnOverlay(const RefPtr<NG::FrameNode>& node);
|
||||
void HideNodeOnOverlay(const RefPtr<NG::FrameNode>& node);
|
||||
void ShowAllNodesOnOverlay();
|
||||
void HideAllNodesOnOverlay();
|
||||
private:
|
||||
void PopToast(int32_t targetId);
|
||||
|
||||
@ -560,6 +568,8 @@ private:
|
||||
std::optional<ModalTransition> modalTransition);
|
||||
void HandleModalPop(std::function<void()>&& onWillDisappear, const RefPtr<UINode> rootNode, int32_t targetId);
|
||||
|
||||
RefPtr<FrameNode> overlayNode_;
|
||||
std::unordered_set<int32_t> frameNodeSetOnOverlay_;
|
||||
// Key: target Id, Value: PopupInfo
|
||||
std::unordered_map<int32_t, NG::PopupInfo> popupMap_;
|
||||
// K: target frameNode ID, V: menuNode
|
||||
|
@ -51,6 +51,8 @@ const char ATTRS_COMMON_ZINDEX[] = "zIndex";
|
||||
const char ROOT_ETS_TAG[] = "root";
|
||||
// stage view
|
||||
const char STAGE_ETS_TAG[] = "stage";
|
||||
// overlay view
|
||||
const char OVERLAY_ETS_TAG[] = "overlay";
|
||||
// page view
|
||||
const char PAGE_ETS_TAG[] = "page";
|
||||
// container modal view (title bar)
|
||||
|
@ -59,6 +59,8 @@ ACE_EXPORT extern const char ROOT_ETS_TAG[];
|
||||
ACE_EXPORT extern const char STAGE_ETS_TAG[];
|
||||
// page view
|
||||
ACE_EXPORT extern const char PAGE_ETS_TAG[];
|
||||
// overlay view
|
||||
ACE_EXPORT extern const char OVERLAY_ETS_TAG[];
|
||||
// container modal view (title bar)
|
||||
ACE_EXPORT extern const char CONTAINER_MODAL_ETS_TAG[];
|
||||
|
||||
|
@ -28,6 +28,7 @@ common_napi_libs = [
|
||||
"grid",
|
||||
"measure",
|
||||
"mediaquery",
|
||||
"overlay",
|
||||
"prompt",
|
||||
"promptaction",
|
||||
"router",
|
||||
|
76
interfaces/napi/kits/overlay/BUILD.gn
Normal file
76
interfaces/napi/kits/overlay/BUILD.gn
Normal file
@ -0,0 +1,76 @@
|
||||
# Copyright (c) 2024 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.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||
|
||||
template("napi_overlay_static") {
|
||||
forward_variables_from(invoker, "*")
|
||||
|
||||
ohos_source_set(target_name) {
|
||||
defines += invoker.defines
|
||||
|
||||
defines += [ "USE_ARK_ENGINE" ]
|
||||
cflags_cc += invoker.cflags_cc
|
||||
if (is_mac) {
|
||||
cflags_cc += [ "-O0" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"$ace_root",
|
||||
"$ace_root/frameworks",
|
||||
"$root_out_dir/arkui/framework",
|
||||
]
|
||||
|
||||
sources = [ "js_overlay.cpp" ]
|
||||
|
||||
deps = []
|
||||
external_deps = []
|
||||
if (platform != "" && is_arkui_x) {
|
||||
deps += [ "${crossplatform_plugin_root}/libs/napi:napi_$platform" ]
|
||||
} else {
|
||||
external_deps += [ "napi:ace_napi" ]
|
||||
}
|
||||
|
||||
if (defined(config.libace_target)) {
|
||||
deps += [ config.libace_target ]
|
||||
}
|
||||
|
||||
deps += [ "../utils:napi_utils_static_${platform}" ]
|
||||
|
||||
subsystem_name = "arkui"
|
||||
part_name = ace_engine_part
|
||||
}
|
||||
}
|
||||
|
||||
foreach(item, ace_platforms) {
|
||||
napi_overlay_static("overlay_static_" + item.name) {
|
||||
defines = []
|
||||
cflags_cc = []
|
||||
config = {
|
||||
}
|
||||
platform = item.name
|
||||
|
||||
if (defined(item.config)) {
|
||||
config = item.config
|
||||
}
|
||||
|
||||
if (defined(config.defines)) {
|
||||
defines = config.defines
|
||||
}
|
||||
|
||||
if (defined(config.cflags_cc)) {
|
||||
cflags_cc = config.cflags_cc
|
||||
}
|
||||
}
|
||||
}
|
148
interfaces/napi/kits/overlay/js_overlay.cpp
Normal file
148
interfaces/napi/kits/overlay/js_overlay.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
/*
|
||||
* Copyright (c) 2024 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 "interfaces/napi/kits/utils/napi_utils.h"
|
||||
#include "napi/native_api.h"
|
||||
#include "native_value.h"
|
||||
#include "napi/native_node_api.h"
|
||||
|
||||
#include "bridge/common/utils/engine_helper.h"
|
||||
#include "bridge/js_frontend/engine/common/js_engine.h"
|
||||
|
||||
namespace OHOS::Ace::Napi {
|
||||
static NG::FrameNode* ParseFrameNode(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value argv = nullptr;
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
NAPI_CALL(env, napi_get_cb_info(env, info, &argc, &argv, &thisVar, &data));
|
||||
NAPI_ASSERT(env, argc == 1, "requires 1 paramter");
|
||||
|
||||
napi_value nodePtr = nullptr;
|
||||
NAPI_CALL(env, napi_get_named_property(env, argv, "nodePtr_", &nodePtr));
|
||||
napi_valuetype valueType = napi_undefined;
|
||||
napi_typeof(env, nodePtr, &valueType);
|
||||
NG::UINode* uiNode = nullptr;
|
||||
if (valueType == napi_external) {
|
||||
NAPI_CALL(env, napi_get_value_external(env, nodePtr, (void**)&uiNode));
|
||||
}
|
||||
CHECK_NULL_RETURN(uiNode, nullptr);
|
||||
return reinterpret_cast<NG::FrameNode*>(uiNode);
|
||||
}
|
||||
|
||||
static napi_value JSAddFrameNode(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NG::FrameNode* frameNode = ParseFrameNode(env, info);
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->AddFrameNodeToOverlay(AceType::Claim(frameNode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSRemoveFrameNode(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NG::FrameNode* frameNode = ParseFrameNode(env, info);
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->RemoveFrameNodeOnOverlay(AceType::Claim(frameNode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSShowNode(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NG::FrameNode* frameNode = ParseFrameNode(env, info);
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->ShowNodeOnOverlay(AceType::Claim(frameNode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSHideNode(napi_env env, napi_callback_info info)
|
||||
{
|
||||
NG::FrameNode* frameNode = ParseFrameNode(env, info);
|
||||
CHECK_NULL_RETURN(frameNode, nullptr);
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->HideNodeOnOverlay(AceType::Claim(frameNode));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSShow(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->ShowAllNodesOnOverlay();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value JSHide(napi_env env, napi_callback_info info)
|
||||
{
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
return nullptr;
|
||||
}
|
||||
delegate->HideAllNodesOnOverlay();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static napi_value OverlayExport(napi_env env, napi_value exports)
|
||||
{
|
||||
napi_property_descriptor overlayDesc[] = {
|
||||
DECLARE_NAPI_FUNCTION("addFrameNode", JSAddFrameNode),
|
||||
DECLARE_NAPI_FUNCTION("removeFrameNode", JSRemoveFrameNode),
|
||||
DECLARE_NAPI_FUNCTION("showNode", JSShowNode),
|
||||
DECLARE_NAPI_FUNCTION("hideNode", JSHideNode),
|
||||
DECLARE_NAPI_FUNCTION("show", JSShow),
|
||||
DECLARE_NAPI_FUNCTION("hide", JSHide)
|
||||
};
|
||||
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(overlayDesc) / sizeof(overlayDesc[0]), overlayDesc));
|
||||
return exports;
|
||||
}
|
||||
|
||||
static napi_module overlayModule = {
|
||||
.nm_version = 1,
|
||||
.nm_flags = 0,
|
||||
.nm_filename = nullptr,
|
||||
.nm_register_func = OverlayExport,
|
||||
.nm_modname = "overlay",
|
||||
.nm_priv = ((void*)0),
|
||||
.reserved = { 0 },
|
||||
};
|
||||
|
||||
extern "C" __attribute__((constructor)) void OverlayRegister()
|
||||
{
|
||||
napi_module_register(&overlayModule);
|
||||
}
|
||||
} // namespace OHOS::Ace::Napi
|
Loading…
Reference in New Issue
Block a user