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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLLABLE_SCROLLABLE_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLLABLE_SCROLLABLE_THEME_H 18 19 #include "core/components/theme/theme.h" 20 #include "core/components/theme/theme_constants.h" 21 #include "core/components/theme/theme_constants_defines.h" 22 23 namespace OHOS::Ace::NG { 24 25 class ScrollableTheme : public virtual Theme { 26 DECLARE_ACE_TYPE(ScrollableTheme, Theme); 27 28 public: 29 class Builder { 30 public: 31 Builder() = default; 32 ~Builder() = default; 33 Build(const RefPtr<ThemeConstants> & themeConstants)34 RefPtr<ScrollableTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 35 { 36 RefPtr<ScrollableTheme> theme = AceType::MakeRefPtr<ScrollableTheme>(); 37 if (!themeConstants) { 38 return theme; 39 } 40 ParsePattern(themeConstants, theme); 41 return theme; 42 } 43 44 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<ScrollableTheme> & theme)45 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<ScrollableTheme>& theme) const 46 { 47 if (!theme) { 48 return; 49 } 50 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_SCROLLABLE); 51 if (!pattern) { 52 return; 53 } 54 theme->friction_ = pattern->GetAttr<double>("scroll_able_friction", 0.75f); 55 theme->flingVelocityScale_ = pattern->GetAttr<double>("scroll_able_fling_velocity_scale", 1.5f); 56 theme->springVelocityScale_ = pattern->GetAttr<double>("scroll_able_spring_velocity_scale", 1.5f); 57 theme->ratio_ = pattern->GetAttr<double>("scroll_able_over_edge_following_ratio_api_twenty", 5.0f); 58 theme->springResponse_ = pattern->GetAttr<double>("scroll_able_spring_response", 0.417f); 59 theme->touchPadVelocityScaleRate_ = 60 pattern->GetAttr<double>("scroll_able_touch_pad_velocity_scale_rate", 1.0f); 61 } 62 }; 63 64 ~ScrollableTheme() override = default; 65 GetFriction()66 float GetFriction() const 67 { 68 return friction_; 69 } 70 GetFlingVelocityScale()71 float GetFlingVelocityScale() const 72 { 73 return flingVelocityScale_; 74 } 75 GetSpringVelocityScale()76 float GetSpringVelocityScale() const 77 { 78 return springVelocityScale_; 79 } 80 GetRatio()81 float GetRatio() const 82 { 83 return ratio_; 84 } 85 GetSpringResponse()86 float GetSpringResponse() const 87 { 88 return springResponse_; 89 } 90 GetTouchPadVelocityScaleRate()91 float GetTouchPadVelocityScaleRate() const 92 { 93 return touchPadVelocityScaleRate_; 94 } 95 96 protected: 97 ScrollableTheme() = default; 98 99 private: 100 float friction_ = 0.75f; 101 float flingVelocityScale_ = 1.5f; 102 float springVelocityScale_ = 1.5f; 103 float ratio_ = 5.0f; 104 float springResponse_ = 0.416f; 105 float touchPadVelocityScaleRate_ = 1.0f; 106 }; 107 } // namespace OHOS::Ace::NG 108 109 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SCROLLABLE_SCROLLABLE_THEME_H 110