1 /*
2 * Copyright (c) 2021 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 #include "bridge/declarative_frontend/jsview/js_loading_progress.h"
17
18 #include "bridge/declarative_frontend/jsview/models/loading_progress_model_impl.h"
19 #include "core/components/common/properties/color.h"
20 #include "core/components_ng/pattern/loading_progress/loading_progress_model.h"
21 #include "core/components_ng/pattern/loading_progress/loading_progress_model_ng.h"
22
23 namespace OHOS::Ace {
24 std::unique_ptr<LoadingProgressModel> LoadingProgressModel::instance_ = nullptr;
25
GetInstance()26 LoadingProgressModel* LoadingProgressModel::GetInstance()
27 {
28 if (!instance_) {
29 #ifdef NG_BUILD
30 instance_.reset(new NG::LoadingProgressModelNG());
31 #else
32 if (Container::IsCurrentUseNewPipeline()) {
33 instance_.reset(new NG::LoadingProgressModelNG());
34 } else {
35 instance_.reset(new Framework::LoadingProgressModelImpl());
36 }
37 #endif
38 }
39 return instance_.get();
40 }
41
42 } // namespace OHOS::Ace
43
44 namespace OHOS::Ace::Framework {
JSBind(BindingTarget globalObj)45 void JSLoadingProgress::JSBind(BindingTarget globalObj)
46 {
47 JSClass<JSLoadingProgress>::Declare("LoadingProgress");
48 MethodOptions opt = MethodOptions::NONE;
49
50 JSClass<JSLoadingProgress>::StaticMethod("create", &JSLoadingProgress::Create, opt);
51 JSClass<JSLoadingProgress>::StaticMethod("color", &JSLoadingProgress::SetColor, opt);
52 JSClass<JSLoadingProgress>::Inherit<JSViewAbstract>();
53 JSClass<JSLoadingProgress>::Bind(globalObj);
54 }
55
Create()56 void JSLoadingProgress::Create()
57 {
58 LoadingProgressModel::GetInstance()->Create();
59 }
60
SetColor(const JSCallbackInfo & info)61 void JSLoadingProgress::SetColor(const JSCallbackInfo& info)
62 {
63 Color progressColor;
64 if (!ParseJsColor(info[0], progressColor)) {
65 return;
66 }
67
68 LoadingProgressModel::GetInstance()->SetColor(progressColor);
69 }
70 }; // namespace OHOS::Ace::Framework
71