!42276 AddForMenuItem截图时机不合理,容易截到缩放动效期间的组件内容

Merge pull request !42276 from zhubingwei/master
This commit is contained in:
openharmony_ci 2024-09-04 16:19:43 +00:00 committed by Gitee
commit ea9b113077
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 36 additions and 78 deletions

View File

@ -22,36 +22,32 @@ const util = requireNapi('util');
const tag = 'AddFormMenuItem::js::'; const tag = 'AddFormMenuItem::js::';
async function querySnapshotAsync(want, componentId) { async function querySnapshotAsync(want, componentId, uiContext) {
let compInfo = componentUtils.getRectangleById(componentId); let compInfo = uiContext.getComponentUtils().getRectangleById(componentId);
try { try {
const imagePackageApi = image.createImagePacker(); const imagePackageApi = image.createImagePacker();
const packOpts = { const packOpts = {
format: 'image/jpeg', format: 'image/jpeg',
quality: 50, quality: 50,
}; };
let packPixmap = await componentSnapshot.get(componentId); hilog.info(0x3900, tag, 'componentId:' + componentId);
let packPixmap = await uiContext.getComponentSnapshot().get(componentId);
let arrayBuffer = await imagePackageApi.packing(packPixmap, packOpts); let arrayBuffer = await imagePackageApi.packing(packPixmap, packOpts);
let base64Helper = new util.Base64Helper(); let base64Helper = new util.Base64Helper();
let uint8Arr = new Uint8Array(arrayBuffer); let uint8Arr = new Uint8Array(arrayBuffer);
let pixelStr = base64Helper.encodeToStringSync(uint8Arr); let pixelStr = base64Helper.encodeToStringSync(uint8Arr);
!want.parameters && (want.parameters = {}); !want.parameters && (want.parameters = {});
want.parameters['ohos.extra.param.key.add_form_to_host_width'] = compInfo.size.width.toFixed(2); want.parameters['ohos.extra.param.key.add_form_to_host_width'] = compInfo.size.width.toFixed(2);
want.parameters['ohos.extra.param.key.add_form_to_host_height'] = compInfo.size.height.toFixed(2); want.parameters['ohos.extra.param.key.add_form_to_host_height'] = compInfo.size.height.toFixed(2);
want.parameters['ohos.extra.param.key.add_form_to_host_screenx'] = compInfo.screenOffset.x.toFixed(2); want.parameters['ohos.extra.param.key.add_form_to_host_screenx'] = compInfo.screenOffset.x.toFixed(2);
want.parameters['ohos.extra.param.key.add_form_to_host_screeny'] = compInfo.screenOffset.y.toFixed(2); want.parameters['ohos.extra.param.key.add_form_to_host_screeny'] = compInfo.screenOffset.y.toFixed(2);
want.parameters['ohos.extra.param.key.add_form_to_host_snapshot'] = pixelStr; want.parameters['ohos.extra.param.key.add_form_to_host_snapshot'] = pixelStr;
hilog.info(0x3900, tag, 'pixelStr length:' + pixelStr.length);
} catch (err) { } catch (err) {
hilog.error(0x3900, tag, 'get pixelmap string error:' + err); hilog.error(0x3900, tag, 'get pixelmap string error:' + err);
} }
} }
function querySnapshot(want, componentId) {
querySnapshotAsync(want, componentId);
return true;
}
/** /**
* Build function of AddFormMenuItem. * Build function of AddFormMenuItem.
* *
@ -62,18 +58,6 @@ function querySnapshot(want, componentId) {
* @since 12 * @since 12
*/ */
export function AddFormMenuItem(want, componentId, options, parent = null) { export function AddFormMenuItem(want, componentId, options, parent = null) {
this.observeComponentCreation2((elmtId, isInitialRender) => {
If.create();
if (querySnapshot(want, componentId)) {
this.ifElseBranchUpdateFunction(0, () => {
});
}
else {
this.ifElseBranchUpdateFunction(1, () => {
});
}
}, If);
If.pop();
this.observeComponentCreation2((elmtId, isInitialRender) => { this.observeComponentCreation2((elmtId, isInitialRender) => {
FormMenuItem.create(options?.style?.options ? options.style.options : { FormMenuItem.create(options?.style?.options ? options.style.options : {
startIcon: { startIcon: {
@ -91,7 +75,14 @@ export function AddFormMenuItem(want, componentId, options, parent = null) {
'moduleName': '' 'moduleName': ''
} }
}); });
FormMenuItem.onRegClick(want, componentId, options?.formBindingData?.data, options?.callback);
let uiContext = this.getUIContext();
FormMenuItem.onClick(async () => {
await querySnapshotAsync(want, componentId, uiContext);
uiContext.runScopedTask(() => {
FormMenuItem.onRequestPublishFormWithSnapshot(want, options?.formBindingData?.data, options?.callback);
});
});
}, FormMenuItem); }, FormMenuItem);
FormMenuItem.pop(); FormMenuItem.pop();
} }

View File

@ -54,11 +54,13 @@ const querySnapshot = (want: Want, componentId: string): boolean => {
@Builder @Builder
AddFormMenuItem(want: Want, componentId: string, options?: AddFormOptions): void { AddFormMenuItem(want: Want, componentId: string, options?: AddFormOptions): void {
if (querySnapshot(want, componentId)) {
}
FormMenuItem(options?.style?.options ? options.style.options : { FormMenuItem(options?.style?.options ? options.style.options : {
startIcon: $r('sys.media.ic_form_menu_add'), startIcon: $r('sys.media.ic_form_menu_add'),
content: $r('sys.string.ohos_add_form_to_desktop') content: $r('sys.string.ohos_add_form_to_desktop')
}) })
.onRegClick(want, componentId, options?.formBindingData?.data, options?.callback) .onClick(async () => {
let uiContext = this.getUIContext();
await querySnapshot(want, componentId, uiContext);
FormMenuItem.onRequestPublishFormWithSnapshot(want, options?.formBindingData?.data, options?.callback);
})
} }

View File

@ -39,19 +39,19 @@
namespace OHOS::Ace::Framework { namespace OHOS::Ace::Framework {
namespace { namespace {
constexpr int NUM_WANT_1 = 0; constexpr int NUM_WANT_1 = 0;
constexpr int NUM_ID_2 = 1; constexpr int NUM_DATA_2 = 1;
constexpr int NUM_DATA_3 = 2; constexpr int NUM_FUN_3 = 2;
constexpr int NUM_FUN_4 = 3;
constexpr int NUM_CALLBACKNUM = 2; constexpr int NUM_CALLBACKNUM = 2;
} }
void JSFormMenuItem::JSBind(BindingTarget globalObj) void JSFormMenuItem::JSBind(BindingTarget globalObj)
{ {
JSClass<JSFormMenuItem>::Declare("FormMenuItem"); JSClass<JSFormMenuItem>::Declare("FormMenuItem");
MethodOptions opt = MethodOptions::NONE; MethodOptions opt = MethodOptions::NONE;
JSClass<JSFormMenuItem>::StaticMethod("create", &JSMenuItem::Create, opt); JSClass<JSFormMenuItem>::StaticMethod("create", &JSMenuItem::Create, opt);
JSClass<JSFormMenuItem>::StaticMethod("onRegClick", &JSFormMenuItem::JsOnRegClick); JSClass<JSFormMenuItem>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
JSClass<JSFormMenuItem>::StaticMethod("onRequestPublishFormWithSnapshot",
&JSFormMenuItem::JsOnRequestPublishFormWithSnapshot);
JSClass<JSFormMenuItem>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass<JSFormMenuItem>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
JSClass<JSFormMenuItem>::InheritAndBind<JSViewAbstract>(globalObj); JSClass<JSFormMenuItem>::InheritAndBind<JSViewAbstract>(globalObj);
} }
@ -93,7 +93,7 @@ void JSFormMenuItem::RequestPublishFormWithSnapshot(JSRef<JSVal> wantValue,
jsCBFunc->ExecuteJS(NUM_CALLBACKNUM, params); jsCBFunc->ExecuteJS(NUM_CALLBACKNUM, params);
} }
void JSFormMenuItem::JsOnRegClick(const JSCallbackInfo& info) void JSFormMenuItem::JsOnRequestPublishFormWithSnapshot(const JSCallbackInfo& info)
{ {
bool retFlag; bool retFlag;
OnClickParameterCheck(info, retFlag); OnClickParameterCheck(info, retFlag);
@ -101,68 +101,33 @@ void JSFormMenuItem::JsOnRegClick(const JSCallbackInfo& info)
return; return;
} }
std::string compId; auto want = info[NUM_WANT_1];
JSViewAbstract::ParseJsString(info[NUM_ID_2], compId); JSRef<JSVal> wantValue = JSRef<JSVal>::Cast(want);
if (compId.empty()) { if (wantValue->IsNull()) {
TAG_LOGE(AceLogTag::ACE_FORM, "JsOnClick compId is empty.Input parameter componentId check failed."); TAG_LOGE(AceLogTag::ACE_FORM, "JsOnClick wantValue is null");
return; return;
} }
std::string formBindingDataStr; std::string formBindingDataStr;
JSViewAbstract::ParseJsString(info[NUM_DATA_3], formBindingDataStr); JSViewAbstract::ParseJsString(info[NUM_DATA_2], formBindingDataStr);
if (formBindingDataStr.empty()) { if (formBindingDataStr.empty()) {
TAG_LOGW(AceLogTag::ACE_FORM, "JsOnClick formBindingDataStr is empty"); TAG_LOGW(AceLogTag::ACE_FORM, "JsOnClick formBindingDataStr is empty");
} }
RefPtr<JsFunction> jsCallBackFunc = nullptr; RefPtr<JsFunction> jsCallBackFunc = nullptr;
if (!info[NUM_FUN_4]->IsUndefined() && info[NUM_FUN_4]->IsFunction()) { if (!info[NUM_FUN_3]->IsUndefined() && info[NUM_FUN_3]->IsFunction()) {
jsCallBackFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[NUM_FUN_4])); jsCallBackFunc = AceType::MakeRefPtr<JsFunction>(JSRef<JSObject>(), JSRef<JSFunc>::Cast(info[NUM_FUN_3]));
} }
WeakPtr<NG::FrameNode> targetNode = AceType::WeakClaim(NG::ViewStackProcessor::GetInstance()->GetMainFrameNode()); RequestPublishFormWithSnapshot(wantValue, formBindingDataStr, jsCallBackFunc);
auto onTap = [execCtx = info.GetExecutionContext(), node = targetNode,
jsCBFunc = std::move(jsCallBackFunc), want = info[NUM_WANT_1], formBindingDataStr] (GestureEvent& event) {
JSRef<JSVal> wantValue = JSRef<JSVal>::Cast(want);
if (wantValue->IsNull()) {
TAG_LOGE(AceLogTag::ACE_FORM, "JsOnClick wantValue is null");
return;
}
TAG_LOGI(AceLogTag::ACE_FORM, "JsOnClick ontap");
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
ACE_SCORING_EVENT("onTap");
RequestPublishFormWithSnapshot(wantValue, formBindingDataStr, jsCBFunc);
#if !defined(PREVIEW) && defined(OHOS_PLATFORM)
JSInteractableView::ReportClickEvent(node);
#endif
};
auto onClick = [execCtx = info.GetExecutionContext(), node = targetNode,
jsCBFunc = std::move(jsCallBackFunc), want = info[NUM_WANT_1], formBindingDataStr]
(const ClickInfo* event) {
JSRef<JSVal> wantValue = JSRef<JSVal>::Cast(want);
if (wantValue->IsNull()) {
TAG_LOGE(AceLogTag::ACE_FORM, "JsOnClick wantValue is null");
return;
}
JAVASCRIPT_EXECUTION_SCOPE_WITH_CHECK(execCtx);
ACE_SCORING_EVENT("onClick");
PipelineContext::SetCallBackNode(node);
RequestPublishFormWithSnapshot(wantValue, formBindingDataStr, jsCBFunc);
#if !defined(PREVIEW) && defined(OHOS_PLATFORM)
JSInteractableView::ReportClickEvent(node);
#endif
};
ViewAbstractModel::GetInstance()->SetOnClick(std::move(onTap), std::move(onClick));
} }
void JSFormMenuItem::OnClickParameterCheck(const JSCallbackInfo& info, bool& retFlag) void JSFormMenuItem::OnClickParameterCheck(const JSCallbackInfo& info, bool& retFlag)
{ {
retFlag = true; retFlag = true;
if (info[NUM_WANT_1]->IsUndefined() || !info[NUM_WANT_1]->IsObject() || info[NUM_ID_2]->IsUndefined() || if (info[NUM_WANT_1]->IsUndefined() || !info[NUM_WANT_1]->IsObject()) {
!info[NUM_ID_2]->IsString()) { TAG_LOGE(AceLogTag::ACE_FORM, "OnClickParameterCheck bad parameter info[1]");
TAG_LOGE(AceLogTag::ACE_FORM, "OnClickParameterCheck bad parameter info[1] and info[2]");
return; return;
} }
retFlag = false; retFlag = false;

View File

@ -23,7 +23,7 @@ namespace OHOS::Ace::Framework {
class JSFormMenuItem : public JSMenuItem { class JSFormMenuItem : public JSMenuItem {
public: public:
static void JSBind(BindingTarget globalObj); static void JSBind(BindingTarget globalObj);
static void JsOnRegClick(const JSCallbackInfo& info); static void JsOnRequestPublishFormWithSnapshot(const JSCallbackInfo& info);
static void OnClickParameterCheck(const JSCallbackInfo& info, bool& retFlag); static void OnClickParameterCheck(const JSCallbackInfo& info, bool& retFlag);
private: private:
static void RequestPublishFormWithSnapshot(JSRef<JSVal> wantValue, static void RequestPublishFormWithSnapshot(JSRef<JSVal> wantValue,