• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 #include "core/components_ng/pattern/animator/animator_model_ng.h"
16 
17 #include "bridge/declarative_frontend/ng/declarative_frontend_ng.h"
18 #include "core/components_ng/pattern/stage/page_pattern.h"
19 #ifdef PLUGIN_COMPONENT_SUPPORTED
20 #include "core/common/plugin_manager.h"
21 #endif
22 
23 namespace OHOS::Ace::Framework {
24 namespace {
GetCurrentPage()25 RefPtr<NG::PagePattern> GetCurrentPage()
26 {
27     RefPtr<NG::FrameNode> pageNode;
28 #ifdef PLUGIN_COMPONENT_SUPPORTED
29     if (Container::CurrentId() >= MIN_PLUGIN_SUBCONTAINER_ID) {
30         auto pluginContainer = PluginManager::GetInstance().GetPluginSubContainer(Container::CurrentId());
31         CHECK_NULL_RETURN(pluginContainer, nullptr);
32         pageNode = pluginContainer->GetPluginNode().Upgrade();
33         CHECK_NULL_RETURN(pageNode, nullptr);
34     } else
35 #endif
36     {
37         auto container = Container::Current();
38         CHECK_NULL_RETURN(container, nullptr);
39         auto frontEnd = AceType::DynamicCast<DeclarativeFrontendNG>(container->GetFrontend());
40         CHECK_NULL_RETURN(frontEnd, nullptr);
41         auto pageRouterManager = frontEnd->GetPageRouterManager();
42         CHECK_NULL_RETURN(pageRouterManager, nullptr);
43         pageNode = pageRouterManager->GetCurrentPageNode();
44         CHECK_NULL_RETURN(pageNode, nullptr);
45     }
46     return pageNode->GetPattern<NG::PagePattern>();
47 }
48 } // namespace
49 
Create(const std::string & animatorId)50 void AnimatorModelNG::Create(const std::string& animatorId)
51 {
52     auto page = GetCurrentPage();
53     CHECK_NULL_VOID(page);
54     auto animatorInfo = page->GetJsAnimator(animatorId);
55     if (!animatorInfo) {
56         animatorInfo = AceType::MakeRefPtr<AnimatorInfo>();
57         auto animator = CREATE_ANIMATOR(animatorId.c_str());
58         animatorInfo->SetAnimator(animator);
59         page->AddJsAnimator(animatorId, animatorInfo);
60     }
61 }
62 
GetAnimatorInfo(const std::string & animatorId)63 RefPtr<AnimatorInfo> AnimatorModelNG::GetAnimatorInfo(const std::string& animatorId)
64 {
65     auto page = GetCurrentPage();
66     CHECK_NULL_RETURN(page, nullptr);
67     auto animatorInfo = page->GetJsAnimator(animatorId);
68     return animatorInfo;
69 }
70 } // namespace OHOS::Ace::Framework
71