Signed-off-by: luoying_ace_admin <luoying19@huawei.com>
Change-Id: Id51d7c7879fff9fe8618f6e4c574fd858bc553e2
This commit is contained in:
luoying_ace_admin 2024-10-17 09:43:22 +00:00
parent 4e7c834005
commit c3fabf25d3
24 changed files with 61 additions and 45 deletions

View File

@ -130,7 +130,7 @@ void FfiPromptOpenCustomDialog(void(*builder)(), NativeBaseOption options, void(
func(customId);
};
std::function<void(const int32_t& info)> onWillDismiss = nullptr;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss = nullptr;
auto alignment = DIALOG_ALIGNMENT[options.alignment];

View File

@ -1771,8 +1771,10 @@ void FrontendDelegateDeclarative::ShowDialog(const PromptDialogAttr& dialogAttr,
ShowDialogInner(dialogProperties, std::move(callback), callbacks);
}
void FrontendDelegateDeclarative::RemoveCustomDialog()
void FrontendDelegateDeclarative::RemoveCustomDialog(int32_t instanceId)
{
TAG_LOGI(AceLogTag::ACE_DIALOG, "Dismiss custom dialog, instanceId: %{public}d", instanceId);
ContainerScope scope(instanceId);
NG::ViewAbstract::DismissDialog();
}

View File

@ -210,7 +210,7 @@ public:
std::function<void(bool)>&& onStatusChanged) override;
void ShowDialogInner(DialogProperties& dialogProperties, std::function<void(int32_t, int32_t)>&& callback,
const std::set<std::string>& callbacks);
void RemoveCustomDialog() override;
void RemoveCustomDialog(int32_t instanceId) override;
void OpenCustomDialog(const PromptDialogAttr &dialogAttr, std::function<void(int32_t)> &&callback) override;
void CloseCustomDialog(const int32_t dialogId) override;
void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)> &&callback) override;

View File

@ -384,7 +384,7 @@ void JSActionSheet::Show(const JSCallbackInfo& args)
ActionSheetModel::GetInstance()->SetCancel(eventFunc, properties);
}
std::function<void(const int32_t& info)> onWillDismissFunc = nullptr;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismissFunc = nullptr;
ParseDialogCallback(obj, onWillDismissFunc);
ActionSheetModel::GetInstance()->SetOnWillDismiss(std::move(onWillDismissFunc), properties);

View File

@ -437,7 +437,7 @@ void JSAlertDialog::Show(const JSCallbackInfo& args)
AlertDialogModel::GetInstance()->SetOnCancel(eventFunc, properties);
}
std::function<void(const int32_t& info)> onWillDismissFunc = nullptr;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismissFunc = nullptr;
ParseDialogCallback(obj, onWillDismissFunc);
AlertDialogModel::GetInstance()->SetOnWillDismiss(std::move(onWillDismissFunc), properties);

View File

@ -111,7 +111,7 @@ void JSCustomDialogController::ConstructorCallback(const JSCallbackInfo& info)
instance->dialogProperties_.onCancel = onCancel;
}
std::function<void(const int32_t& info)> onWillDismissFunc = nullptr;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismissFunc = nullptr;
JSViewAbstract::ParseDialogCallback(constructorArg, onWillDismissFunc);
instance->dialogProperties_.onWillDismiss = onWillDismissFunc;

View File

@ -6627,13 +6627,13 @@ panda::Local<panda::JSValueRef> JSViewAbstract::JsDismissPopup(panda::JsiRuntime
#endif
void JSViewAbstract::ParseDialogCallback(const JSRef<JSObject>& paramObj,
std::function<void(const int32_t& info)>& onWillDismiss)
std::function<void(const int32_t& info, const int32_t& instanceId)>& onWillDismiss)
{
auto onWillDismissFunc = paramObj->GetProperty("onWillDismiss");
if (onWillDismissFunc->IsFunction()) {
RefPtr<JsFunction> jsFunc =
AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(onWillDismissFunc));
onWillDismiss = [func = std::move(jsFunc)](const int32_t& info) {
onWillDismiss = [func = std::move(jsFunc)](const int32_t& info, const int32_t& instanceId) {
JSRef<JSObjTemplate> objectTemplate = JSRef<JSObjTemplate>::New();
objectTemplate->SetInternalFieldCount(ON_WILL_DISMISS_FIELD_COUNT);
JSRef<JSObject> dismissObj = objectTemplate->NewInstance();

View File

@ -474,7 +474,7 @@ public:
*/
static void JSBind(BindingTarget globalObj);
static void ParseDialogCallback(const JSRef<JSObject>& paramObj,
std::function<void(const int32_t& info)>& onWillDismiss);
std::function<void(const int32_t& info, const int32_t& instanceId)>& onWillDismiss);
static panda::Local<panda::JSValueRef> JsDismissDialog(panda::JsiRuntimeCallInfo* runtimeCallInfo);
static RefPtr<PipelineBase> GetPipelineContext()

View File

@ -184,7 +184,7 @@ public:
virtual void ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks,
std::function<void(bool)>&& onStatusChanged) {};
virtual void RemoveCustomDialog() {};
virtual void RemoveCustomDialog(int32_t instanceId) {};
virtual void OpenCustomDialog(const PromptDialogAttr &dialogAttr, std::function<void(int32_t)> &&callback) {};
virtual void CloseCustomDialog(const int32_t dialogId) {};
virtual void CloseCustomDialog(const WeakPtr<NG::UINode>& node, std::function<void(int32_t)> &&callback) {};

View File

@ -219,7 +219,7 @@ struct DialogProperties {
bool isSelect = false; // init checkbox state
std::vector<ButtonInfo> buttons;
std::function<void()> onCancel; // NG cancel callback
std::function<void(const int32_t& info)> onWillDismiss; // Cancel Dismiss Callback
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss; // Cancel Dismiss Callback
std::function<void(int32_t, int32_t)> onSuccess; // NG prompt success callback
std::function<void(const bool)> onChange; // onChange success callback
std::function<void(DialogProperties&)> onLanguageChange; // onLanguageChange callback
@ -286,7 +286,7 @@ struct PromptDialogAttr {
bool isModal = false;
bool enableHoverMode = false;
std::function<void()> customBuilder;
std::function<void(const int32_t& info)> customOnWillDismiss;
std::function<void(const int32_t& info, const int32_t& instanceId)> customOnWillDismiss;
std::optional<DialogAlignment> alignment;
std::optional<DimensionOffset> offset;

View File

@ -32,8 +32,8 @@ public:
virtual void SetCancel(std::function<void()>&& eventFunc, DialogProperties& arg) = 0;
virtual void SetConfirm(GestureEventFunc&& gestureEvent, std::function<void()>&& eventFunc,
ButtonInfo& buttonInfo, DialogProperties& arg) = 0;
virtual void SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
DialogProperties& arg) {};
virtual void SetOnWillDismiss(std::function<void(const int32_t& info,
const int32_t& instanceId)>&& onWillDismissFunc, DialogProperties& arg) {};
private:
static std::unique_ptr<ActionSheetModel> instance_;

View File

@ -64,8 +64,8 @@ void ActionSheetModelNG::SetCancel(std::function<void()>&& eventFunc, DialogProp
arg.onCancel = eventFunc;
}
void ActionSheetModelNG::SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
DialogProperties& arg)
void ActionSheetModelNG::SetOnWillDismiss(std::function<void(const int32_t& info,
const int32_t& instanceId)>&& onWillDismissFunc, DialogProperties& arg)
{
arg.onWillDismiss = std::move(onWillDismissFunc);
}

View File

@ -27,7 +27,7 @@ public:
void SetCancel(std::function<void()>&& eventFunc, DialogProperties& arg) override;
void SetConfirm(GestureEventFunc&& gestureEvent, std::function<void()>&& eventFunc,
ButtonInfo& buttonInfo, DialogProperties& arg) override;
void SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
void SetOnWillDismiss(std::function<void(const int32_t& info, const int32_t& instanceId)>&& onWillDismissFunc,
DialogProperties& arg) override;
};
} // namespace OHOS::Ace::NG

View File

@ -29,8 +29,8 @@ public:
const std::string& property) = 0;
virtual void SetOnCancel(std::function<void()>&& eventFunc, DialogProperties& arg) = 0;
virtual void SetShowDialog(const DialogProperties& arg) = 0;
virtual void SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
DialogProperties& arg) {};
virtual void SetOnWillDismiss(std::function<void(const int32_t& info,
const int32_t& instanceId)>&& onWillDismissFunc, DialogProperties& arg) {};
private:
static std::unique_ptr<AlertDialogModel> instance_;

View File

@ -36,8 +36,8 @@ void AlertDialogModelNG::SetOnCancel(std::function<void()>&& eventFunc, DialogPr
arg.onCancel = eventFunc;
}
void AlertDialogModelNG::SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
DialogProperties& arg)
void AlertDialogModelNG::SetOnWillDismiss(std::function<void(const int32_t& info,
const int32_t& instanceId)>&& onWillDismissFunc, DialogProperties& arg)
{
arg.onWillDismiss = std::move(onWillDismissFunc);
}

View File

@ -25,7 +25,7 @@ public:
const std::string& property) override;
void SetOnCancel(std::function<void()>&& eventFunc, DialogProperties& arg) override;
void SetShowDialog(const DialogProperties& arg) override;
void SetOnWillDismiss(std::function<void(const int32_t& info)>&& onWillDismissFunc,
void SetOnWillDismiss(std::function<void(const int32_t& info, const int32_t& instanceId)>&& onWillDismissFunc,
DialogProperties& arg) override;
};
} // namespace OHOS::Ace::NG

View File

@ -226,8 +226,9 @@ void DialogPattern::HandleClick(const GestureEvent& info)
return;
} else if (this->ShouldDismiss()) {
overlayManager->SetDismissDialogId(host->GetId());
this->CallOnWillDismiss(static_cast<int32_t>(DialogDismissReason::DIALOG_TOUCH_OUTSIDE));
TAG_LOGI(AceLogTag::ACE_DIALOG, "Dialog Should Dismiss");
auto currentId = Container::CurrentId();
this->CallOnWillDismiss(static_cast<int32_t>(DialogDismissReason::DIALOG_TOUCH_OUTSIDE), currentId);
TAG_LOGI(AceLogTag::ACE_DIALOG, "Dialog Should Dismiss, currentId: %{public}d", currentId);
return;
}
PopDialog(-1);

View File

@ -62,7 +62,7 @@ public:
return false;
}
void SetOnWillDismiss(const std::function<void(const int32_t& info)>& onWillDismiss)
void SetOnWillDismiss(const std::function<void(const int32_t& info, const int32_t& instanceId)>& onWillDismiss)
{
onWillDismiss_ = onWillDismiss;
}
@ -88,10 +88,10 @@ public:
return false;
}
void CallOnWillDismiss(const int32_t reason)
void CallOnWillDismiss(const int32_t reason, const int32_t instanceId)
{
if (onWillDismiss_) {
onWillDismiss_(reason);
onWillDismiss_(reason, instanceId);
}
}
@ -395,7 +395,7 @@ private:
std::string message_;
std::string title_;
std::string subtitle_;
std::function<void(const int32_t& info)> onWillDismiss_;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss_;
std::function<bool(const int32_t& info)> onWillDismissByNDK_;
DialogProperties dialogProperties_;

View File

@ -3113,8 +3113,9 @@ int32_t OverlayManager::RemoveOverlayCommon(const RefPtr<NG::UINode>& rootNode,
return OVERLAY_REMOVE;
} else if (dialogPattern->ShouldDismiss()) {
SetDismissDialogId(overlay->GetId());
dialogPattern->CallOnWillDismiss(static_cast<int32_t>(DialogDismissReason::DIALOG_PRESS_BACK));
TAG_LOGI(AceLogTag::ACE_OVERLAY, "Dialog Should Dismiss");
auto currentId = Container::CurrentId();
dialogPattern->CallOnWillDismiss(static_cast<int32_t>(DialogDismissReason::DIALOG_PRESS_BACK), currentId);
TAG_LOGI(AceLogTag::ACE_OVERLAY, "Dialog Should Dismiss, currentId: %{public}d", currentId);
return OVERLAY_REMOVE;
}
return RemoveDialog(overlay, isBackPressed, isPageRouter) ? OVERLAY_REMOVE : OVERLAY_EXISTS;

View File

@ -156,7 +156,7 @@ void ParseDialogProperties(DialogProperties& dialogProperties, ArkUIDialogHandle
ParseDialogMask(dialogProperties, controllerHandler);
ParseDialogCornerRadiusRect(dialogProperties, controllerHandler);
if (controllerHandler->onWillDismissCall) {
dialogProperties.onWillDismiss = [controllerHandler](int32_t reason) {
dialogProperties.onWillDismiss = [controllerHandler](int32_t reason, int32_t instanceId) {
CHECK_NULL_VOID(controllerHandler);
CHECK_NULL_VOID(controllerHandler->onWillDismissCall);
(*(controllerHandler->onWillDismissCall))(reason);
@ -334,4 +334,4 @@ ArkUI_Int32 RegisterOnWillDialogDismissWithUserData(
return ERROR_CODE_NO_ERROR;
}
} // namespace OHOS::Ace::NG::ViewModel
} // namespace OHOS::Ace::NG::ViewModel

View File

@ -1815,18 +1815,28 @@ napi_value JSPromptShowActionMenu(napi_env env, napi_callback_info info)
napi_value JSRemoveCustomDialog(napi_env env, napi_callback_info info)
{
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);
int32_t instanceId = Container::CurrentIdSafely();
if (data) {
int32_t* instanceIdPtr = reinterpret_cast<int32_t*>(data);
instanceId = *instanceIdPtr;
}
auto delegate = EngineHelper::GetCurrentDelegateSafely();
if (delegate) {
delegate->RemoveCustomDialog();
delegate->RemoveCustomDialog(instanceId);
}
return nullptr;
}
void ParseDialogCallback(std::shared_ptr<PromptAsyncContext>& asyncContext,
std::function<void(const int32_t& info)>& onWillDismiss)
std::function<void(const int32_t& info, const int32_t& instanceId)>& onWillDismiss)
{
onWillDismiss = [env = asyncContext->env, onWillDismissRef = asyncContext->onWillDismissRef]
(const int32_t& info) {
(const int32_t& info, const int32_t& instanceId) {
if (onWillDismissRef) {
napi_value onWillDismissFunc = nullptr;
napi_value value = nullptr;
@ -1834,7 +1844,9 @@ void ParseDialogCallback(std::shared_ptr<PromptAsyncContext>& asyncContext,
napi_value paramObj = nullptr;
napi_create_object(env, &paramObj);
napi_create_function(env, "dismiss", strlen("dismiss"), JSRemoveCustomDialog, nullptr, &funcValue);
napi_value id = nullptr;
napi_create_int32(env, instanceId, &id);
napi_create_function(env, "dismiss", strlen("dismiss"), JSRemoveCustomDialog, id, &funcValue);
napi_set_named_property(env, paramObj, "dismiss", funcValue);
napi_create_int32(env, info, &value);
@ -1935,7 +1947,7 @@ std::function<void()> GetCustomBuilder(napi_env env, const std::shared_ptr<Promp
}
PromptDialogAttr GetPromptActionDialog(napi_env env, const std::shared_ptr<PromptAsyncContext>& asyncContext,
std::function<void(const int32_t& info)> onWillDismiss)
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss)
{
std::optional<DialogAlignment> alignment;
std::optional<DimensionOffset> offset;
@ -2168,7 +2180,7 @@ napi_value JSPromptOpenCustomDialog(napi_env env, napi_callback_info info)
napi_value result = nullptr;
napi_create_promise(env, &asyncContext->deferred, &result);
std::function<void(const int32_t& info)> onWillDismiss = nullptr;
std::function<void(const int32_t& info, const int32_t& instanceId)> onWillDismiss = nullptr;
if (asyncContext->onWillDismissRef) {
ParseDialogCallback(asyncContext, onWillDismiss);
}

View File

@ -157,7 +157,7 @@ HWTEST_F(DialogModelTestNg, DialogModelTestNg002, TestSize.Level1)
*/
AlertDialogModelNG alertDialogModelNg;
DialogProperties properties;
std::function<void(int32_t)> onWillDismiss = [](int32_t reason) {};
std::function<void(int32_t, int32_t)> onWillDismiss = [](int32_t reason, int32_t instanceId) {};
/**
* @tc.steps: step2. Call SetOnWillDismiss.
@ -179,7 +179,7 @@ HWTEST_F(DialogModelTestNg, DialogModelTestNg003, TestSize.Level1)
*/
ActionSheetModelNG actionSheetModelNg;
DialogProperties properties;
std::function<void(int32_t)> onWillDismiss = [](int32_t reason) {};
std::function<void(int32_t, int32_t)> onWillDismiss = [](int32_t reason, int32_t instanceId) {};
/**
* @tc.steps: step2. Call SetOnWillDismiss.
@ -637,7 +637,7 @@ HWTEST_F(DialogModelTestNg, DialogModelTestNg016, TestSize.Level1)
* @tc.steps: step2. Call onWillDismiss and ShouldDismiss.
* @tc.expected: return value is true.
*/
std::function<void(int32_t)> onWillDismiss = [](int32_t info) {};
std::function<void(int32_t, int32_t)> onWillDismiss = [](int32_t info, int32_t instanceId) {};
pattern->SetOnWillDismiss(std::move(onWillDismiss));
EXPECT_TRUE(pattern->ShouldDismiss());
@ -1490,4 +1490,4 @@ HWTEST_F(DialogModelTestNg, SetOpenDialogWithNode001, TestSize.Level1)
auto result = controllerModel.SetOpenDialogWithNode(props, nullptr);
EXPECT_EQ(result, nullptr);
}
} // namespace OHOS::Ace::NG
} // namespace OHOS::Ace::NG

View File

@ -878,7 +878,7 @@ HWTEST_F(OverlayManagerDialogTestNg, DismissDialogTest001, TestSize.Level1)
* @tc.steps3: Set the onWillDismiss property.
* @tc.expected: return value are as expected.
*/
std::function<void(int32_t)> onWillDismiss1 = [](int32_t reason) {};
std::function<void(int32_t, int32_t)> onWillDismiss1 = [](int32_t reason, int32_t instanceId) {};
auto pattern = overlay->GetPattern();
auto dialogPattern = dialog->GetPattern<DialogPattern>();
dialogPattern->SetOnWillDismiss(onWillDismiss1);

View File

@ -842,7 +842,7 @@ HWTEST_F(OverlayManagerTwoTestNg, RemoveOverlayCommon005, TestSize.Level1)
V2::DIALOG_ETS_TAG, 2, AceType::MakeRefPtr<DialogPattern>(AceType::MakeRefPtr<DialogTheme>(), nullptr));
ASSERT_NE(dialogNode, nullptr);
auto dialogPattern = dialogNode->GetPattern<DialogPattern>();
dialogPattern->SetOnWillDismiss([](const int32_t& info) {});
dialogPattern->SetOnWillDismiss([](const int32_t& info, const int32_t& instanceId) {});
dialogNode->MountToParent(rootNode);
}
@ -1300,4 +1300,4 @@ HWTEST_F(OverlayManagerTwoTestNg, ShowMenuClearAnimation, TestSize.Level1)
EXPECT_EQ(rootNode_->GetChildren().size(), 1);
}
} // namespace OHOS::Ace::NG
} // namespace OHOS::Ace::NG