• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H
18 
19 namespace OHOS::Ace::Framework {
20 class JSLazyForEachTheme {
21 public:
ObtainItemGeneratorForThemeSupport(panda::ecmascript::EcmaVM * vm,JSRef<JSFunc> & itemGenerator)22     static void ObtainItemGeneratorForThemeSupport(panda::ecmascript::EcmaVM* vm, JSRef<JSFunc> &itemGenerator)
23     {
24         CHECK_NULL_VOID(vm);
25 
26         panda::Local<panda::ObjectRef> globalObj(JSNApi::GetGlobalObject(vm));
27         if (!globalObj->IsObject(vm)) {
28             return;
29         }
30 
31         JSRef<JSVal> lazy4each = JSRef<JSObject>::Make(globalObj)->GetProperty("LazyForEach");
32         if (!lazy4each->IsObject()) {
33             return;
34         }
35 
36         JSRef<JSVal> updateItemFunc = JSRef<JSObject>::Cast(lazy4each)->GetProperty("getItemGeneratorForThemeSupport");
37         if (!updateItemFunc->IsFunction()) {
38             return;
39         }
40 
41         JSRef<JSVal> params[] = { JSRef<JSVal>::Cast(itemGenerator) };
42         JSRef<JSVal> retVal = JSRef<JSFunc>::Cast(updateItemFunc)->Call(JSRef<JSObject>(), ArraySize(params), params);
43         if (!retVal->IsFunction()) {
44             return;
45         }
46         itemGenerator = JSRef<JSFunc>::Cast(retVal);
47     }
48 };
49 } // namespace OHOS::Ace::Framework
50 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_THEME_JS_LAZY_FOR_EACH_THEME_H