配合解决画中画typeNode方案中onSurfaceCreated等回调问题

Signed-off-by: Ning Yuanfeng <Nyuanfeng@163.com>
This commit is contained in:
Ning Yuanfeng 2024-08-30 16:26:43 +08:00
parent a705e25832
commit 8d42dda46e
5 changed files with 41 additions and 0 deletions

View File

@ -27,6 +27,13 @@ namespace {
constexpr int32_t NUMBER_TWO = 2;
}
napi_value GetType(napi_env env, napi_value value)
{
napi_valuetype res = napi_undefined;
napi_typeof(env, value, &res);
return res;
}
napi_value NapiGetUndefined(napi_env env)
{
napi_value result = nullptr;
@ -179,6 +186,30 @@ napi_value JsPipManager::OnSetTypeNodeEnabled(napi_env env, napi_callback_info i
return NapiGetUndefined(env);
}
napi_value JsPipManager::ResetNodeType(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
return (me != nullptr) ? me->OnResetNodeType(env, info) : nullptr;
}
napi_value JsPipManager::OnResetNodeType(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::WMS_PIP, "[NAPI]");
size_t argc = 4;
napi_value argv[4] = {nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < NUMBER_ONE) {
TLOGE(WmsLogTag::WMS_PIP, "[NAPI]Argc count is invalid: %{public}zu", argc);
return NapiGetUndefined(env);
}
napi_value typeNode = argv[0];
if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) {
TLOGI(WmsLogTag::WMS_PIP, "reset to DEFAULT");
XComponentController::SetSurfaceCallbackMode(env, typeNode, SurfaceCallbackMode::DEFAULT);
}
return NapiGetUndefined(env);
}
napi_value JsPipManager::RegisterCallback(napi_env env, napi_callback_info info)
{
JsPipManager* me = CheckParamsAndGetThis<JsPipManager>(env, info);
@ -250,6 +281,7 @@ napi_value JsPipManagerInit(napi_env env, napi_value exportObj)
BindNativeFunction(env, exportObj, "on", moduleName, JsPipManager::RegisterCallback);
BindNativeFunction(env, exportObj, "off", moduleName, JsPipManager::UnregisterCallback);
BindNativeFunction(env, exportObj, "setTypeNodeEnabled", moduleName, JsPipManager::SetTypeNodeEnabled);
BindNativeFunction(env, exportObj, "resetNodeType", moduleName, JsPipManager::ResetNodeType);
return NapiGetUndefined(env);
}
} // namespace Rosen

View File

@ -32,6 +32,7 @@ public:
static napi_value RegisterCallback(napi_env env, napi_callback_info info);
static napi_value UnregisterCallback(napi_env env, napi_callback_info info);
static napi_value SetTypeNodeEnabled(napi_env env, napi_callback_info info);
static napi_value ResetNodeType(napi_env env, napi_callback_info info);
private:
napi_value OnInitXComponentController(napi_env env, napi_callback_info info);
napi_value OnGetCustomUIController(napi_env env, napi_callback_info info);
@ -39,6 +40,7 @@ private:
napi_value OnRegisterCallback(napi_env env, napi_callback_info info);
napi_value OnUnregisterCallback(napi_env env, napi_callback_info info);
napi_value OnSetTypeNodeEnabled(napi_env env, napi_callback_info info);
napi_value OnResetNodeType(napi_env env, napi_callback_info info);
};
} // namespace Rosen
} // namespace OHOS

View File

@ -281,6 +281,7 @@ napi_value JsPipWindowManager::OnCreatePipController(napi_env env, napi_callback
if (typeNode != nullptr && GetType(env, typeNode) != napi_undefined) {
TLOGI(WmsLogTag::WMS_PIP, "typeNode enabled");
pipOption.SetTypeNodeEnabled(true);
XComponentController::SetSurfaceCallbackTypeMode(env, typeNode, SurfaceCallbackMode::PIP);
napi_create_reference(env, typeNode, 1, &typeNodeRef);
pipOption.SetTypeNodeRef(typeNodeRef);
} else {

View File

@ -99,6 +99,9 @@ export class PiPContent extends ViewPU {
return;
}
this.useNode = true;
if (this.xComponent.getParent() === null || this.xComponent.getParent() === undefined) {
pip.resetNodeType(this.xComponent);
}
pip.setTypeNodeEnabled();
this.mXCNodeController = new XCNodeController(this.xComponent);
console.info(TAG, 'use Node Controller');

View File

@ -63,6 +63,9 @@ export struct PiPContent {
return;
}
this.useNode = true;
if (this.xComponent.getParent() === null || this.xComponent.getParent() === undefined) {
pip.resetNodeType(this.xComponent);
}
pip.setTypeNodeEnabled();
this.mXCNodeController = new XCNodeController(this.xComponent);
console.info(TAG, 'use Node Controller');