mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-27 09:12:41 +00:00
回退promptAction提供主动关闭Toast弹窗的能力
Signed-off-by: Zhang Jinyu <zhangjinyu101@huawei.com>
This commit is contained in:
parent
12b558e427
commit
18dcafd7c9
@ -450,8 +450,8 @@ sptr<OHOS::Rosen::Window> DialogContainer::GetUIWindowInner() const
|
||||
return uiWindow_;
|
||||
}
|
||||
|
||||
void DialogContainer::ShowToast(int32_t instanceId, const std::string& message, int32_t duration,
|
||||
const std::string& bottom, std::function<void(int32_t)>&& callback)
|
||||
void DialogContainer::ShowToast(
|
||||
int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom)
|
||||
{
|
||||
auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId));
|
||||
CHECK_NULL_VOID(container);
|
||||
@ -470,26 +470,7 @@ void DialogContainer::ShowToast(int32_t instanceId, const std::string& message,
|
||||
.showMode = NG::ToastShowMode::DEFAULT,
|
||||
.alignment = -1,
|
||||
.offset = std::nullopt };
|
||||
delegate->ShowToast(toastInfo, std::move(callback));
|
||||
}
|
||||
|
||||
void DialogContainer::CloseToast(int32_t instanceId, int32_t toastId, std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
auto container = AceType::DynamicCast<DialogContainer>(AceEngine::Get().GetContainer(instanceId));
|
||||
CHECK_NULL_VOID(container);
|
||||
|
||||
auto frontend = AceType::DynamicCast<DeclarativeFrontend>(container->GetFrontend());
|
||||
CHECK_NULL_VOID(frontend);
|
||||
|
||||
auto delegate = frontend->GetDelegate();
|
||||
CHECK_NULL_VOID(delegate);
|
||||
delegate->SetToastStopListenerCallback([instanceId = instanceId]() {
|
||||
if (ContainerScope::CurrentId() >= 0) {
|
||||
DialogContainer::HideWindow(instanceId);
|
||||
}
|
||||
});
|
||||
|
||||
delegate->CloseToast(toastId, std::move(callback));
|
||||
delegate->ShowToast(toastInfo);
|
||||
}
|
||||
|
||||
void DialogContainer::ShowDialog(int32_t instanceId, const std::string& title, const std::string& message,
|
||||
|
@ -161,9 +161,7 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
static void ShowToast(int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom,
|
||||
std::function<void(int32_t)>&& callback);
|
||||
static void CloseToast(int32_t instanceId, const int32_t toastId, std::function<void(int32_t)>&& callback);
|
||||
static void ShowToast(int32_t instanceId, const std::string& message, int32_t duration, const std::string& bottom);
|
||||
static void ShowDialog(int32_t instanceId, const std::string& title, const std::string& message,
|
||||
const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks);
|
||||
|
@ -1122,7 +1122,7 @@ void SubwindowOhos::ClearToast()
|
||||
HideWindow();
|
||||
}
|
||||
|
||||
void SubwindowOhos::ShowToastForAbility(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void SubwindowOhos::ShowToastForAbility(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show toast for ability enter, containerId : %{public}d", childContainerId_);
|
||||
SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
|
||||
@ -1153,19 +1153,18 @@ void SubwindowOhos::ShowToastForAbility(const NG::ToastInfo& toastInfo, std::fun
|
||||
ResizeWindow();
|
||||
ShowWindow(false);
|
||||
}
|
||||
delegate->ShowToast(toastInfo, std::move(callback));
|
||||
delegate->ShowToast(toastInfo);
|
||||
}
|
||||
|
||||
void SubwindowOhos::ShowToastForService(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void SubwindowOhos::ShowToastForService(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
bool ret = CreateEventRunner();
|
||||
if (!ret) {
|
||||
TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create event runner failed");
|
||||
return;
|
||||
}
|
||||
|
||||
SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this));
|
||||
auto showDialogCallback = [toastInfo, callbackParam = std::move(callback)]() {
|
||||
auto showDialogCallback = [toastInfo]() {
|
||||
int32_t posX = 0;
|
||||
int32_t posY = 0;
|
||||
int32_t width = 0;
|
||||
@ -1195,15 +1194,13 @@ void SubwindowOhos::ShowToastForService(const NG::ToastInfo& toastInfo, std::fun
|
||||
ContainerScope scope(childContainerId);
|
||||
subwindowOhos->UpdateAceView(width, height, density, childContainerId);
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW,
|
||||
"update ace view width : %{public}d, height : %{public}d, density : %{public}f,childContainerId : "
|
||||
"%{public}d",
|
||||
"update ace view width: %{public}d, height: %{public}d, density: %{public}f, childContainerId: %{public}d",
|
||||
width, height, density, childContainerId);
|
||||
auto container = Platform::DialogContainer::GetContainer(childContainerId);
|
||||
CHECK_NULL_VOID(container);
|
||||
container->SetFontScaleAndWeightScale(childContainerId);
|
||||
Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height, true);
|
||||
Platform::DialogContainer::ShowToast(childContainerId, toastInfo.message, toastInfo.duration, toastInfo.bottom,
|
||||
std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam)));
|
||||
Platform::DialogContainer::ShowToast(childContainerId, toastInfo.message, toastInfo.duration, toastInfo.bottom);
|
||||
};
|
||||
if (!handler_->PostTask(showDialogCallback)) {
|
||||
TAG_LOGW(AceLogTag::ACE_SUB_WINDOW, "create show dialog callback failed");
|
||||
@ -1211,35 +1208,13 @@ void SubwindowOhos::ShowToastForService(const NG::ToastInfo& toastInfo, std::fun
|
||||
}
|
||||
}
|
||||
|
||||
void SubwindowOhos::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void SubwindowOhos::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGI(AceLogTag::ACE_SUB_WINDOW, "show toast, window parent id is %{public}d", parentContainerId_);
|
||||
if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
|
||||
ShowToastForService(toastInfo, std::move(callback));
|
||||
ShowToastForService(toastInfo);
|
||||
} else {
|
||||
ShowToastForAbility(toastInfo, std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
void SubwindowOhos::CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close toast enter");
|
||||
if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
|
||||
auto subwindowOhos =
|
||||
AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow());
|
||||
CHECK_NULL_VOID(subwindowOhos);
|
||||
auto childContainerId = subwindowOhos->GetChildContainerId();
|
||||
CHECK_NULL_VOID(childContainerId);
|
||||
ContainerScope scope(childContainerId);
|
||||
Platform::DialogContainer::CloseToast(childContainerId, toastId, std::move(callback));
|
||||
} else {
|
||||
auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
|
||||
CHECK_NULL_VOID(aceContainer);
|
||||
auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId());
|
||||
auto delegate = engine->GetFrontend();
|
||||
CHECK_NULL_VOID(delegate);
|
||||
ContainerScope scope(childContainerId_);
|
||||
delegate->CloseToast(toastId, std::move(callback));
|
||||
ShowToastForAbility(toastInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,8 +99,7 @@ public:
|
||||
void SetHotAreas(const std::vector<Rect>& rects, int32_t nodeId) override;
|
||||
void DeleteHotAreas(int32_t nodeId) override;
|
||||
void ClearToast() override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) override;
|
||||
void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo) override;
|
||||
void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
@ -164,8 +163,8 @@ private:
|
||||
int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const;
|
||||
bool InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast = false);
|
||||
bool InitToastDialogView(int32_t width, int32_t height, float density);
|
||||
void ShowToastForAbility(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback);
|
||||
void ShowToastForService(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback);
|
||||
void ShowToastForAbility(const NG::ToastInfo& toastInfo);
|
||||
void ShowToastForService(const NG::ToastInfo& toastInfo);
|
||||
void ShowDialogForAbility(const std::string& title, const std::string& message,
|
||||
const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks);
|
||||
|
@ -138,8 +138,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void ClearToast() = 0;
|
||||
virtual void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) = 0;
|
||||
virtual void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback) = 0;
|
||||
virtual void ShowToast(const NG::ToastInfo& toastInfo) = 0;
|
||||
virtual void ShowDialog(const std::string& title, const std::string& message,
|
||||
const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) = 0;
|
||||
|
@ -658,7 +658,7 @@ RefPtr<Subwindow> SubwindowManager::GetOrCreateSystemSubWindow()
|
||||
return subwindow;
|
||||
}
|
||||
|
||||
void SubwindowManager::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void SubwindowManager::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "show toast enter");
|
||||
auto containerId = Container::CurrentId();
|
||||
@ -669,50 +669,24 @@ void SubwindowManager::ShowToast(const NG::ToastInfo& toastInfo, std::function<v
|
||||
CHECK_NULL_VOID(subwindow);
|
||||
subwindow->SetIsSystemTopMost(toastInfo.showMode == NG::ToastShowMode::SYSTEM_TOP_MOST);
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before show toast");
|
||||
subwindow->ShowToast(toastInfo, std::move(callback));
|
||||
subwindow->ShowToast(toastInfo);
|
||||
} else {
|
||||
// for ability
|
||||
auto taskExecutor = Container::CurrentTaskExecutor();
|
||||
CHECK_NULL_VOID(taskExecutor);
|
||||
taskExecutor->PostTask(
|
||||
[containerId, toastInfo, callbackParam = std::move(callback)] {
|
||||
[containerId, toastInfo] {
|
||||
auto manager = SubwindowManager::GetInstance();
|
||||
CHECK_NULL_VOID(manager);
|
||||
auto subwindow = manager->GetOrCreateToastWindow(containerId, toastInfo.showMode);
|
||||
CHECK_NULL_VOID(subwindow);
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before show toast : %{public}d", containerId);
|
||||
subwindow->ShowToast(toastInfo, std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam)));
|
||||
subwindow->ShowToast(toastInfo);
|
||||
},
|
||||
TaskExecutor::TaskType::PLATFORM, "ArkUISubwindowShowToast");
|
||||
}
|
||||
}
|
||||
|
||||
void SubwindowManager::CloseToast(
|
||||
const int32_t toastId, const NG::ToastShowMode& showMode, std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "close toast enter");
|
||||
auto containerId = Container::CurrentId();
|
||||
|
||||
if (containerId >= MIN_PA_SERVICE_ID || containerId < 0) {
|
||||
// for pa service
|
||||
auto subwindow =
|
||||
showMode == NG::ToastShowMode::SYSTEM_TOP_MOST ? GetSystemToastWindow() : GetDialogSubwindow(containerId);
|
||||
CHECK_NULL_VOID(subwindow);
|
||||
subwindow->SetIsSystemTopMost(showMode == NG::ToastShowMode::SYSTEM_TOP_MOST);
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before close toast");
|
||||
subwindow->CloseToast(toastId, std::move(callback));
|
||||
} else {
|
||||
// for ability
|
||||
auto manager = SubwindowManager::GetInstance();
|
||||
CHECK_NULL_VOID(manager);
|
||||
auto subwindow =
|
||||
showMode == NG::ToastShowMode::SYSTEM_TOP_MOST ? GetSystemToastWindow() : GetSubwindow(containerId);
|
||||
CHECK_NULL_VOID(subwindow);
|
||||
TAG_LOGD(AceLogTag::ACE_SUB_WINDOW, "before close toast : %{public}d", containerId);
|
||||
subwindow->CloseToast(toastId, std::move(callback));
|
||||
}
|
||||
}
|
||||
|
||||
RefPtr<Subwindow> SubwindowManager::GetOrCreateToastWindow(int32_t containerId, const NG::ToastShowMode& showMode)
|
||||
{
|
||||
auto isSystemTopMost = (showMode == NG::ToastShowMode::SYSTEM_TOP_MOST);
|
||||
|
@ -115,9 +115,7 @@ public:
|
||||
void DeleteHotAreas(int32_t subwindowId, int32_t nodeId);
|
||||
|
||||
void ClearToastInSubwindow();
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback);
|
||||
void CloseToast(
|
||||
const int32_t toastId, const NG::ToastShowMode& showMode, std::function<void(int32_t)>&& callback);
|
||||
void ShowToast(const NG::ToastInfo& toastInfo);
|
||||
void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& napiCallback,
|
||||
const std::set<std::string>& dialogCallbacks);
|
||||
|
@ -238,7 +238,7 @@ void CJFrontendAbstract::ShowToast(
|
||||
.showMode = showMode,
|
||||
.alignment = -1,
|
||||
.offset = std::nullopt };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
};
|
||||
MainWindowOverlay(std::move(task), "ArkUIOverlayShowToast");
|
||||
}
|
||||
|
@ -952,19 +952,6 @@ class PromptAction {
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
openToast(options) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
let promise = this.ohos_prompt.openToast(options);
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
return promise;
|
||||
}
|
||||
|
||||
closeToast(toastId) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
this.ohos_prompt.closeToast(toastId);
|
||||
__JSScopeUtil__.restoreInstanceId();
|
||||
}
|
||||
|
||||
showDialog(options, callback) {
|
||||
__JSScopeUtil__.syncInstanceId(this.instanceId_);
|
||||
if (typeof callback !== 'undefined') {
|
||||
|
@ -1547,19 +1547,18 @@ Size FrontendDelegateDeclarative::MeasureTextSize(MeasureContext context)
|
||||
return MeasureUtil::MeasureTextSize(context);
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void FrontendDelegateDeclarative::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "show toast enter");
|
||||
NG::ToastInfo updatedToastInfo = toastInfo;
|
||||
updatedToastInfo.duration = std::clamp(toastInfo.duration, TOAST_TIME_DEFAULT, TOAST_TIME_MAX);
|
||||
updatedToastInfo.isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
|
||||
if (Container::IsCurrentUseNewPipeline()) {
|
||||
auto task = [updatedToastInfo, callbackParam = std::move(callback), containerId = Container::CurrentId()](
|
||||
auto task = [updatedToastInfo, containerId = Container::CurrentId()](
|
||||
const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowToast(
|
||||
updatedToastInfo, std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam)));
|
||||
overlayManager->ShowToast(updatedToastInfo);
|
||||
};
|
||||
MainWindowOverlay(std::move(task), "ArkUIOverlayShowToast");
|
||||
return;
|
||||
@ -1573,20 +1572,6 @@ void FrontendDelegateDeclarative::ShowToast(const NG::ToastInfo& toastInfo, std:
|
||||
TaskExecutor::TaskType::UI, "ArkUIShowToast");
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "close toast enter");
|
||||
auto currentId = Container::CurrentId();
|
||||
ContainerScope scope(currentId);
|
||||
|
||||
auto context = NG::PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
|
||||
auto overlayManager = context->GetOverlayManager();
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
overlayManager->CloseToast(toastId, std::move(callback));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarative::SetToastStopListenerCallback(std::function<void()>&& stopCallback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "set toast stop listener enter");
|
||||
|
@ -191,8 +191,7 @@ public:
|
||||
double MeasureText(MeasureContext context) override;
|
||||
Size MeasureTextSize(MeasureContext context) override;
|
||||
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback = nullptr) override;
|
||||
void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback = nullptr) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo) override;
|
||||
void SetToastStopListenerCallback(std::function<void()>&& stopCallback) override;
|
||||
void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
|
@ -1031,34 +1031,21 @@ size_t FrontendDelegateDeclarativeNG::GetComponentsCount()
|
||||
return pageNode->GetAllDepthChildrenCount();
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void FrontendDelegateDeclarativeNG::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "show toast enter");
|
||||
NG::ToastInfo updatedToastInfo = toastInfo;
|
||||
updatedToastInfo.duration = std::clamp(toastInfo.duration, TOAST_TIME_DEFAULT, TOAST_TIME_MAX);
|
||||
updatedToastInfo.isRightToLeft = AceApplicationInfo::GetInstance().IsRightToLeft();
|
||||
auto task = [updatedToastInfo, callbackParam = std::move(callback), containerId = Container::CurrentId()](
|
||||
auto task = [updatedToastInfo, containerId = Container::CurrentId()](
|
||||
const RefPtr<NG::OverlayManager>& overlayManager) {
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
ContainerScope scope(containerId);
|
||||
overlayManager->ShowToast(
|
||||
updatedToastInfo, std::move(const_cast<std::function<void(int32_t)>&&>(callbackParam)));
|
||||
overlayManager->ShowToast(updatedToastInfo);
|
||||
};
|
||||
MainWindowOverlay(std::move(task), "ArkUIOverlayShowToast");
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "close toast enter");
|
||||
auto currentId = Container::CurrentId();
|
||||
ContainerScope scope(currentId);
|
||||
auto context = NG::PipelineContext::GetCurrentContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
auto overlayManager = context->GetOverlayManager();
|
||||
CHECK_NULL_VOID(overlayManager);
|
||||
overlayManager->CloseToast(toastId, std::move(callback));
|
||||
}
|
||||
|
||||
void FrontendDelegateDeclarativeNG::ShowDialogInner(DialogProperties& dialogProperties,
|
||||
std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks)
|
||||
{
|
||||
|
@ -135,8 +135,7 @@ public:
|
||||
|
||||
double MeasureText(MeasureContext context) override;
|
||||
Size MeasureTextSize(MeasureContext context) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback = nullptr) override;
|
||||
void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback = nullptr) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo) override;
|
||||
void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
|
@ -930,7 +930,7 @@ void ShowToast(const shared_ptr<JsRuntime>& runtime, const shared_ptr<JsValue>&
|
||||
.showMode = NG::ToastShowMode::DEFAULT,
|
||||
.alignment = -1,
|
||||
.offset = std::nullopt };
|
||||
GetFrontendDelegate(runtime)->ShowToast(toastInfo, nullptr);
|
||||
GetFrontendDelegate(runtime)->ShowToast(toastInfo);
|
||||
}
|
||||
|
||||
std::vector<ButtonInfo> ParseDialogButtons(
|
||||
|
@ -161,8 +161,7 @@ public:
|
||||
// ----------------
|
||||
// system.prompt
|
||||
// ----------------
|
||||
virtual void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) = 0;
|
||||
virtual void CloseToast(const int32_t toastId, std::function<void(int32_t)>&& callback) {};
|
||||
virtual void ShowToast(const NG::ToastInfo& toastInfo) = 0;
|
||||
virtual void SetToastStopListenerCallback(std::function<void()>&& stopCallback) {};
|
||||
virtual void ShowDialog(const std::string& title, const std::string& message,
|
||||
const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
|
@ -958,7 +958,7 @@ Size FrontendDelegateImpl::MeasureTextSize(MeasureContext context)
|
||||
return MeasureUtil::MeasureTextSize(context);
|
||||
}
|
||||
|
||||
void FrontendDelegateImpl::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void FrontendDelegateImpl::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
NG::ToastInfo updatedToastInfo = toastInfo;
|
||||
updatedToastInfo.duration = std::clamp(toastInfo.duration, TOAST_TIME_DEFAULT, TOAST_TIME_MAX);
|
||||
|
@ -257,7 +257,7 @@ public:
|
||||
double MeasureText(MeasureContext context) override;
|
||||
Size MeasureTextSize(MeasureContext context) override;
|
||||
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo) override;
|
||||
void ShowDialog(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
|
@ -930,7 +930,7 @@ Size PluginFrontendDelegate::MeasureTextSize(MeasureContext context)
|
||||
return MeasureUtil::MeasureTextSize(context);
|
||||
}
|
||||
|
||||
void PluginFrontendDelegate::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void PluginFrontendDelegate::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
NG::ToastInfo updatedToastInfo = toastInfo;
|
||||
updatedToastInfo.duration = std::clamp(toastInfo.duration, TOAST_TIME_DEFAULT, TOAST_TIME_MAX);
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
double MeasureText(MeasureContext context) override;
|
||||
Size MeasureTextSize(MeasureContext context) override;
|
||||
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback) override;
|
||||
void ShowToast(const NG::ToastInfo& toastInfo) override;
|
||||
void ShowDialog(const std::string& title, const std::string& message,
|
||||
const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
|
||||
const std::set<std::string>& callbacks) override;
|
||||
|
@ -1322,7 +1322,7 @@ bool OverlayManager::IsContextMenuBindedOnOrigNode()
|
||||
return focusHub->FindContextMenuOnKeyEvent(OnKeyEventType::CONTEXT_MENU);
|
||||
}
|
||||
|
||||
void OverlayManager::ShowToast(const NG::ToastInfo& toastInfo, const std::function<void(int32_t)>& callback)
|
||||
void OverlayManager::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "show toast enter");
|
||||
auto context = PipelineContext::GetCurrentContext();
|
||||
@ -1343,39 +1343,9 @@ void OverlayManager::ShowToast(const NG::ToastInfo& toastInfo, const std::functi
|
||||
toastNode->MountToParent(rootNode);
|
||||
rootNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE_SELF);
|
||||
toastMap_[toastId] = toastNode;
|
||||
if (callback != nullptr) {
|
||||
auto callbackToastId = ((toastId << 3) | // 3 : Use the last 3 bits of callbackToastId to store showMode
|
||||
(static_cast<int32_t>(toastInfo.showMode) & 0b111));
|
||||
callback(callbackToastId);
|
||||
}
|
||||
OpenToastAnimation(toastNode, toastInfo.duration);
|
||||
}
|
||||
|
||||
void OverlayManager::CloseToast(int32_t toastId, const std::function<void(int32_t)>& callback)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "close toast enter");
|
||||
if (!callback) {
|
||||
TAG_LOGE(AceLogTag::ACE_OVERLAY, "Parameters of CloseToast are incomplete because of no callback.");
|
||||
callback(ERROR_CODE_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
auto rootNode = rootNodeWeak_.Upgrade();
|
||||
if (!rootNode) {
|
||||
callback(ERROR_CODE_INTERNAL_ERROR);
|
||||
return;
|
||||
}
|
||||
for (auto [id, toastNodeWeak] : toastMap_) {
|
||||
if (id == toastId) {
|
||||
rootNode->RemoveChild(toastNodeWeak.Upgrade());
|
||||
rootNode->MarkDirtyNode(PROPERTY_UPDATE_BY_CHILD_REQUEST);
|
||||
toastMap_.erase(id);
|
||||
callback(ERROR_CODE_NO_ERROR);
|
||||
return;
|
||||
}
|
||||
}
|
||||
callback(ERROR_CODE_TOAST_NOT_FOUND);
|
||||
}
|
||||
|
||||
void OverlayManager::OpenToastAnimation(const RefPtr<FrameNode>& toastNode, int32_t duration)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_OVERLAY, "open toast animation enter");
|
||||
|
@ -163,8 +163,7 @@ public:
|
||||
|
||||
void ClearToastInSubwindow();
|
||||
void ClearToast();
|
||||
void ShowToast(const NG::ToastInfo& toastInfo, const std::function<void(int32_t)>& callback);
|
||||
void CloseToast(int32_t toastId, const std::function<void(int32_t)>& callback);
|
||||
void ShowToast(const NG::ToastInfo& toastInfo);
|
||||
|
||||
void FireAutoSave(const RefPtr<FrameNode>& ContainerNode);
|
||||
|
||||
|
@ -692,7 +692,8 @@ int32_t ServiceCollaborationAceCallback::OnEvent(uint32_t code, uint32_t eventId
|
||||
CHECK_NULL_RETURN(toastPipeline, -1);
|
||||
auto overlay = toastPipeline->GetOverlayManager();
|
||||
CHECK_NULL_RETURN(overlay, -1);
|
||||
overlay->ShowToast({ category, 2000, "", true }, nullptr);
|
||||
auto toastInfo = NG::ToastInfo { .message = category, .duration = 2000, .bottom = "", .isRightToLeft = true };
|
||||
overlay->ShowToast(toastInfo);
|
||||
info_ = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,8 +36,6 @@ static napi_value PromptActionExport(napi_env env, napi_value exports)
|
||||
|
||||
napi_property_descriptor promptDesc[] = {
|
||||
DECLARE_NAPI_FUNCTION("showToast", JSPromptShowToast),
|
||||
DECLARE_NAPI_FUNCTION("openToast", JSPromptOpenToast),
|
||||
DECLARE_NAPI_FUNCTION("closeToast", JSPromptCloseToast),
|
||||
DECLARE_NAPI_FUNCTION("showDialog", JSPromptShowDialog),
|
||||
DECLARE_NAPI_FUNCTION("showActionMenu", JSPromptShowActionMenu),
|
||||
DECLARE_NAPI_FUNCTION("openCustomDialog", JSPromptOpenCustomDialog),
|
||||
|
@ -416,7 +416,7 @@ bool GetToastParams(napi_env env, napi_value argv, NG::ToastInfo& toastInfo)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ShowToast(napi_env env, NG::ToastInfo& toastInfo, std::function<void(int32_t)>& toastCallback)
|
||||
bool ShowToast(napi_env env, NG::ToastInfo& toastInfo)
|
||||
{
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
if ((SystemProperties::GetExtSurfaceEnabled() || !ContainerIsService()) && !ContainerIsScenceBoard() &&
|
||||
@ -427,10 +427,10 @@ bool ShowToast(napi_env env, NG::ToastInfo& toastInfo, std::function<void(int32_
|
||||
return false;
|
||||
}
|
||||
TAG_LOGD(AceLogTag::ACE_DIALOG, "before delegate show toast");
|
||||
delegate->ShowToast(toastInfo, std::move(toastCallback));
|
||||
delegate->ShowToast(toastInfo);
|
||||
} else if (SubwindowManager::GetInstance() != nullptr) {
|
||||
TAG_LOGD(AceLogTag::ACE_DIALOG, "before subwindow manager show toast");
|
||||
SubwindowManager::GetInstance()->ShowToast(toastInfo, std::move(toastCallback));
|
||||
SubwindowManager::GetInstance()->ShowToast(toastInfo);
|
||||
}
|
||||
#else
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
@ -440,10 +440,10 @@ bool ShowToast(napi_env env, NG::ToastInfo& toastInfo, std::function<void(int32_
|
||||
}
|
||||
if (toastInfo.showMode == NG::ToastShowMode::DEFAULT) {
|
||||
TAG_LOGD(AceLogTag::ACE_DIALOG, "before delegate show toast");
|
||||
delegate->ShowToast(toastInfo, std::move(toastCallback));
|
||||
delegate->ShowToast(toastInfo);
|
||||
} else if (SubwindowManager::GetInstance() != nullptr) {
|
||||
TAG_LOGD(AceLogTag::ACE_DIALOG, "before subwindow manager show toast");
|
||||
SubwindowManager::GetInstance()->ShowToast(toastInfo, std::move(toastCallback));
|
||||
SubwindowManager::GetInstance()->ShowToast(toastInfo);
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
@ -466,91 +466,7 @@ napi_value JSPromptShowToast(napi_env env, napi_callback_info info)
|
||||
if (!GetToastParams(env, argv, toastInfo)) {
|
||||
return nullptr;
|
||||
}
|
||||
std::function<void(int32_t)> toastCallback = nullptr;
|
||||
ShowToast(env, toastInfo, toastCallback);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value JSPromptOpenToast(napi_env env, napi_callback_info info)
|
||||
{
|
||||
TAG_LOGD(AceLogTag::ACE_DIALOG, "open toast enter");
|
||||
size_t requireArgc = 1;
|
||||
size_t argc = 1;
|
||||
napi_value argv = nullptr;
|
||||
napi_value thisVar = nullptr;
|
||||
void* data = nullptr;
|
||||
napi_get_cb_info(env, info, &argc, &argv, &thisVar, &data);
|
||||
if (argc != requireArgc) {
|
||||
NapiThrow(env, "The number of parameters must be equal to 1.", ERROR_CODE_PARAM_INVALID);
|
||||
return nullptr;
|
||||
}
|
||||
auto toastInfo = NG::ToastInfo { .duration = -1, .showMode = NG::ToastShowMode::DEFAULT, .alignment = -1 };
|
||||
if (!GetToastParams(env, argv, toastInfo)) {
|
||||
return nullptr;
|
||||
}
|
||||
napi_deferred deferred;
|
||||
napi_value result;
|
||||
napi_create_promise(env, &deferred, &result);
|
||||
std::function<void(int32_t)> toastCallback = nullptr;
|
||||
toastCallback = [env, deferred](int32_t toastId) mutable {
|
||||
napi_value napiToastId = nullptr;
|
||||
napi_create_int32(env, toastId, &napiToastId);
|
||||
napi_resolve_deferred(env, deferred, napiToastId);
|
||||
};
|
||||
if (ShowToast(env, toastInfo, toastCallback)) {
|
||||
return result;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
napi_value JSPromptCloseToast(napi_env env, napi_callback_info info)
|
||||
{
|
||||
size_t argc = 1;
|
||||
napi_value args[1];
|
||||
napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
|
||||
if (argc != 1) {
|
||||
NapiThrow(env, "The number of parameters is incorrect.", ERROR_CODE_PARAM_INVALID);
|
||||
return nullptr;
|
||||
}
|
||||
int32_t id = -1;
|
||||
napi_get_value_int32(env, args[0], &id);
|
||||
int32_t showModeVal = id & 0b111;
|
||||
int32_t toastId = id >> 3; // 3 : Move 3 bits to the right to get toastId, and the last 3 bits are the showMode
|
||||
if (toastId < 0 || showModeVal < 0 || showModeVal > static_cast<int32_t>(NG::ToastShowMode::SYSTEM_TOP_MOST)) {
|
||||
NapiThrow(env, "", ERROR_CODE_TOAST_NOT_FOUND);
|
||||
return nullptr;
|
||||
}
|
||||
auto showMode = static_cast<NG::ToastShowMode>(showModeVal);
|
||||
std::function<void(int32_t)> toastCloseCallback = nullptr;
|
||||
toastCloseCallback = [env](int32_t errorCode) mutable {
|
||||
if (errorCode != ERROR_CODE_NO_ERROR) {
|
||||
NapiThrow(env, "", errorCode);
|
||||
}
|
||||
};
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
if ((SystemProperties::GetExtSurfaceEnabled() || !ContainerIsService()) && !ContainerIsScenceBoard() &&
|
||||
showMode == NG::ToastShowMode::DEFAULT) {
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (delegate) {
|
||||
delegate->CloseToast(toastId, std::move(toastCloseCallback));
|
||||
} else {
|
||||
NapiThrow(env, "Can not get delegate.", ERROR_CODE_INTERNAL_ERROR);
|
||||
}
|
||||
} else if (SubwindowManager::GetInstance() != nullptr) {
|
||||
SubwindowManager::GetInstance()->CloseToast(
|
||||
toastId, static_cast<NG::ToastShowMode>(showMode), std::move(toastCloseCallback));
|
||||
}
|
||||
#else
|
||||
auto delegate = EngineHelper::GetCurrentDelegateSafely();
|
||||
if (!delegate) {
|
||||
NapiThrow(env, "UI execution context not found.", ERROR_CODE_INTERNAL_ERROR);
|
||||
}
|
||||
if (showMode == NG::ToastShowMode::DEFAULT) {
|
||||
delegate->CloseToast(toastId, std::move(toastCloseCallback));
|
||||
} else if (SubwindowManager::GetInstance() != nullptr) {
|
||||
SubwindowManager::GetInstance()->CloseToast(toastId, showMode, std::move(toastCloseCallback));
|
||||
}
|
||||
#endif
|
||||
ShowToast(env, toastInfo);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,6 @@
|
||||
|
||||
namespace OHOS::Ace::Napi {
|
||||
napi_value JSPromptShowToast(napi_env env, napi_callback_info info);
|
||||
napi_value JSPromptOpenToast(napi_env env, napi_callback_info info);
|
||||
napi_value JSPromptCloseToast(napi_env env, napi_callback_info info);
|
||||
napi_value JSPromptShowDialog(napi_env env, napi_callback_info info);
|
||||
napi_value JSPromptShowActionMenu(napi_env env, napi_callback_info info);
|
||||
napi_value JSPromptOpenCustomDialog(napi_env env, napi_callback_info info);
|
||||
|
@ -65,8 +65,7 @@ public:
|
||||
MOCK_CONST_METHOD0(GetUIExtensionHostWindowRect, Rect());
|
||||
MOCK_CONST_METHOD0(CheckHostWindowStatus, bool());
|
||||
MOCK_METHOD0(ClearToast, void());
|
||||
MOCK_METHOD2(ShowToast, void(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback));
|
||||
MOCK_METHOD2(CloseToast, void(int32_t toastId, std::function<void(int32_t)>&& callback));
|
||||
MOCK_METHOD1(ShowToast, void(const NG::ToastInfo& toastInfo));
|
||||
MOCK_METHOD6(ShowDialog,
|
||||
void(const std::string& title, const std::string& message, const std::vector<ButtonInfo>& buttons,
|
||||
bool autoCancel, std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks));
|
||||
|
@ -1855,7 +1855,7 @@ HWTEST_F(OverlayManagerPopupTestNg, ToastTest001, TestSize.Level1)
|
||||
*/
|
||||
auto toastInfo =
|
||||
NG::ToastInfo { .message = MESSAGE, .duration = DURATION, .bottom = BOTTOMSTRING, .isRightToLeft = true };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
EXPECT_FALSE(overlayManager->toastMap_.empty());
|
||||
}
|
||||
} // namespace OHOS::Ace::NG
|
@ -241,7 +241,7 @@ HWTEST_F(OverlayManagerTestNg, DeleteModal001, TestSize.Level1)
|
||||
auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
|
||||
auto toastInfo =
|
||||
NG::ToastInfo { .message = MESSAGE, .duration = DURATION, .bottom = BOTTOMSTRING, .isRightToLeft = true };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
EXPECT_FALSE(overlayManager->toastMap_.empty());
|
||||
|
||||
auto builderFunc = []() -> RefPtr<UINode> {
|
||||
|
@ -1241,9 +1241,9 @@ HWTEST_F(OverlayTestNg, ToastShowModeTest001, TestSize.Level1)
|
||||
auto toastInfo = NG::ToastInfo { .message = MESSAGE,
|
||||
.duration = DURATION,
|
||||
.bottom = BOTTOMSTRING,
|
||||
.showMode = NG::ToastShowMode::TOP_MOST,
|
||||
.isRightToLeft = true };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
.isRightToLeft = true,
|
||||
.showMode = NG::ToastShowMode::TOP_MOST };
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
EXPECT_FALSE(overlayManager->toastMap_.empty());
|
||||
/**
|
||||
* @tc.steps: step2. Test Toast showMode and offset.
|
||||
@ -1292,7 +1292,7 @@ HWTEST_F(OverlayTestNg, ToastTest001, TestSize.Level1)
|
||||
auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
|
||||
auto toastInfo =
|
||||
NG::ToastInfo { .message = MESSAGE, .duration = DURATION, .bottom = BOTTOMSTRING, .isRightToLeft = true };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
EXPECT_TRUE(overlayManager->toastMap_.empty());
|
||||
/**
|
||||
* @tc.steps: step2. call PopToast.
|
||||
@ -1331,7 +1331,7 @@ HWTEST_F(OverlayTestNg, ToastTest002, TestSize.Level1)
|
||||
auto overlayManager = AceType::MakeRefPtr<OverlayManager>(rootNode);
|
||||
auto toastInfo =
|
||||
NG::ToastInfo { .message = MESSAGE, .duration = DURATION, .bottom = BOTTOMSTRING, .isRightToLeft = true };
|
||||
overlayManager->ShowToast(toastInfo, nullptr);
|
||||
overlayManager->ShowToast(toastInfo);
|
||||
EXPECT_TRUE(overlayManager->toastMap_.empty());
|
||||
/**
|
||||
* @tc.steps: step2. call PopToast.
|
||||
|
@ -229,7 +229,7 @@ double PluginFrontendDelegate::MeasureText(const MeasureContext& context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PluginFrontendDelegate::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>&& callback)
|
||||
void PluginFrontendDelegate::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{}
|
||||
|
||||
void PluginFrontendDelegate::ShowDialog(const std::string& title, const std::string& message,
|
||||
|
@ -20,7 +20,7 @@ namespace OHOS::Ace::NG {
|
||||
namespace {
|
||||
bool removeOverlayFlag = false;
|
||||
} // namespace
|
||||
void OverlayManager::ShowToast(const NG::ToastInfo& toastInfo, std::function<void(int32_t)>& callback)
|
||||
void OverlayManager::ShowToast(const NG::ToastInfo& toastInfo)
|
||||
{}
|
||||
|
||||
void OverlayManager::ClearToastInSubwindow() {}
|
||||
|
Loading…
Reference in New Issue
Block a user