1 /* 2 * Copyright (c) 2025 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_NG_PATTERNS_SHEET_SHEET_OBJECT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHEET_SHEET_OBJECT_H 18 19 #include "base/memory/ace_type.h" 20 21 #include "core/common/window_animation_config.h" 22 #include "core/components_ng/event/gesture_event_hub.h" 23 #include "core/components_ng/layout/layout_algorithm.h" 24 #include "core/components_ng/pattern/overlay/sheet_style.h" 25 #include "core/components_ng/pattern/scrollable/scrollable.h" 26 27 namespace OHOS::Ace::NG { 28 29 class SheetPresentationPattern; 30 enum class BindSheetDismissReason; 31 32 class SheetObject : public virtual AceType { 33 DECLARE_ACE_TYPE(SheetObject, AceType); 34 35 public: SheetObject(SheetType sheetType)36 SheetObject(SheetType sheetType) : sheetType_(sheetType) {} 37 virtual BorderWidthProperty PostProcessBorderWidth(const BorderWidthProperty& borderWidth); 38 virtual void DirtyLayoutProcess(const RefPtr<LayoutAlgorithmWrapper>& layoutAlgorithmWrapper); 39 virtual void SetSheetAnimationOption(AnimationOption& option) const; 40 virtual RefPtr<InterpolatingSpring> GetSheetTransitionCurve(float dragVelocity) const; 41 virtual std::function<void()> GetSheetTransitionFinishEvent(bool isTransitionIn); 42 virtual std::function<void()> GetSheetAnimationEvent(bool isTransitionIn, float offset); 43 virtual void ClipSheetNode(); 44 virtual void InitAnimationForOverlay(bool isTransitionIn, bool isFirstTransition); 45 virtual void SetFinishEventForAnimationOption( 46 AnimationOption& option, bool isTransitionIn, bool isFirstTransition); 47 virtual AnimationOption GetAnimationOptionForOverlay(bool isTransitionIn, bool isFirstTransition); 48 virtual std::function<void()> GetAnimationPropertyCallForOverlay(bool isTransitionIn); OnLanguageConfigurationUpdate()49 virtual void OnLanguageConfigurationUpdate() {}; GetSheetSafeAreaPadding()50 virtual PaddingPropertyF GetSheetSafeAreaPadding() const { return PaddingPropertyF(); }; 51 virtual void HandleDragStart(); 52 virtual void HandleDragUpdate(const GestureEvent& info); 53 virtual void HandleDragEnd(float dragVelocity); 54 virtual void ModifyFireSheetTransition(float dragVelocity); 55 virtual void CreatePropertyCallback(); 56 virtual void BeforeCreateLayoutWrapper(); 57 virtual SheetKeyboardAvoidMode GetAvoidKeyboardModeByDefault() const; 58 virtual void AvoidKeyboardInDirtyLayoutProcess(); 59 virtual void AvoidKeyboard(bool forceAvoid); 60 61 virtual ScrollResult HandleScroll(float scrollOffset, int32_t source, 62 NestedState state, float velocity = 0.f); 63 virtual void OnScrollStartRecursive(float position, float dragVelocity = 0.0f); 64 virtual void OnScrollEndRecursive (const std::optional<float>& velocity); 65 virtual bool HandleScrollVelocity(float velocity); 66 virtual void InitScrollProps(); 67 ScrollResult HandleScrollWithSheet(float scrollOffset); 68 GetPanDirection()69 virtual uint32_t GetPanDirection() const 70 { 71 return PanDirection::VERTICAL; 72 } 73 CheckIfNeedSetOuterBorderProp()74 virtual bool CheckIfNeedSetOuterBorderProp() const 75 { 76 return sheetType_ != SheetType::SHEET_POPUP; 77 } 78 CheckIfNeedShadowByDefault()79 virtual bool CheckIfNeedShadowByDefault() const 80 { 81 return true; 82 } 83 BindPattern(const WeakPtr<SheetPresentationPattern> & pattern)84 void BindPattern(const WeakPtr<SheetPresentationPattern>& pattern) 85 { 86 auto patternPtr = pattern.Upgrade(); 87 if (patternPtr) { 88 pattern_ = WeakPtr<SheetPresentationPattern>(pattern); 89 } 90 } 91 GetPattern()92 RefPtr<SheetPresentationPattern> GetPattern() const 93 { 94 auto pattern = pattern_.Upgrade(); 95 return pattern; 96 } 97 GetSheetHeight()98 float GetSheetHeight() const 99 { 100 return sheetHeight_; 101 } 102 SetSheetHeight(float height)103 void SetSheetHeight(float height) 104 { 105 sheetHeight_ = height; 106 } 107 GetSheetType()108 SheetType GetSheetType() const 109 { 110 return sheetType_; 111 } 112 UpdateSheetType(SheetType type)113 void UpdateSheetType(SheetType type) 114 { 115 sheetType_ = type; 116 } 117 CopyData(const RefPtr<SheetObject> & other)118 void CopyData(const RefPtr<SheetObject>& other) 119 { 120 sheetWidth_ = other->sheetWidth_; 121 sheetHeight_ = other->sheetHeight_; 122 } 123 CheckIfUpdateObject(SheetType newType)124 virtual bool CheckIfUpdateObject(SheetType newType) 125 { 126 return (newType == SheetType::SHEET_SIDE) || (newType == SheetType::SHEET_CONTENT_COVER); 127 } 128 IsSheetObjectBase()129 virtual bool IsSheetObjectBase() const 130 { 131 return true; 132 } 133 134 virtual void FireHeightDidChange(); 135 SetCurrentOffset(float value)136 void SetCurrentOffset(float value) 137 { 138 currentOffset_ = value; 139 } 140 141 protected: 142 float sheetWidth_ = 0.0f; // sheet frameSize Width 143 float sheetHeight_ = 0.0f; // sheet frameSize Height 144 float sheetMaxWidth_ = 0.0f; 145 float currentOffset_ = 0.0f; 146 SheetType sheetType_; 147 WeakPtr<SheetPresentationPattern> pattern_; 148 // not need copy. Data that is not unique to the side style 149 bool isSheetNeedScroll_ = false; // true if Sheet is ready to receive scroll offset. 150 bool isSheetPosChanged_ = false; // UpdateTransformTranslate end 151 }; 152 } // namespace OHOS::Ace::NG 153 154 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_SHEET_SHEET_OBJECT_H 155