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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_VALUE_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_VALUE_H
18 
19 #include <functional>
20 
21 #include "core/components/box/render_box.h"
22 #include "core/gestures/click_recognizer.h"
23 #include "core/pipeline/base/render_node.h"
24 
25 namespace OHOS::Ace {
26 
27 using PickerValueCallback = std::function<void()>;
28 
29 class RenderPickerValue : public RenderNode {
30     DECLARE_ACE_TYPE(RenderPickerValue, RenderNode);
31 
32 public:
33     explicit RenderPickerValue(const PickerValueCallback& clickCallback);
34     ~RenderPickerValue() override = default;
35 
Update(const RefPtr<Component> & component)36     void Update(const RefPtr<Component>& component) override {}
37 
38     void PerformLayout() override;
39 
OnPaintFinish()40     void OnPaintFinish() override
41     {
42         if (focus_) {
43             HandleAnimation();
44         }
45     }
46 
47     void HandleClickCallback() const;
48 
HandleFocus(const RefPtr<RenderBox> & box)49     void HandleFocus(const RefPtr<RenderBox>& box)
50     {
51         HandleFocus(box, focus_);
52     }
53 
54     void HandleFocus(const RefPtr<RenderBox>& box, bool focus);
55 
56     void HandleTextFocus(bool focus);
57 
HandleAnimation()58     void HandleAnimation()
59     {
60         HandleAnimation(box_);
61     }
62 
63     void HandleAnimation(const RefPtr<RenderBox>& box);
64 
65 protected:
OnTouchTestHit(const Offset & coordinateOffset,const TouchRestrict & touchRestrict,TouchTestResult & result)66     void OnTouchTestHit(
67         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override
68     {
69         result.emplace_back(clickRecognizer_);
70     }
71 
72 private:
73     PickerValueCallback clickCallback_;
74     RefPtr<ClickRecognizer> clickRecognizer_;
75     RefPtr<RenderBox> box_;
76     bool focus_ = false;
77     Color normalBackColor_;
78     Color focusBackColor_;
79     Color focusAnimationColor_;
80 };
81 
82 } // namespace OHOS::Ace
83 
84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_RENDER_PICKER_VALUE_H
85