• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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_OVERLAY_SHEET_PRESENTATION_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_PRESENTATION_PATTERN_H
18 
19 #include <functional>
20 #include <utility>
21 
22 #include "base/memory/ace_type.h"
23 #include "base/memory/referenced.h"
24 #include "core/common/autofill/auto_fill_trigger_state_holder.h"
25 #include "core/components/common/properties/alignment.h"
26 #include "core/components_ng/manager/avoid_info/avoid_info_manager.h"
27 #include "core/components_ng/manager/focus/focus_view.h"
28 #include "core/components_ng/pattern/linear_layout/linear_layout_algorithm.h"
29 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
30 #include "core/components_ng/pattern/linear_layout/linear_layout_property.h"
31 #include "core/components_ng/pattern/overlay/popup_base_pattern.h"
32 #include "core/components_ng/pattern/overlay/sheet_presentation_layout_algorithm.h"
33 #include "core/components_ng/pattern/overlay/sheet_presentation_property.h"
34 #include "core/components_ng/pattern/overlay/sheet_style.h"
35 #include "core/components_ng/pattern/scrollable/nestable_scroll_container.h"
36 #include "core/pipeline_ng/pipeline_context.h"
37 
38 namespace OHOS::Ace::NG {
39 
40 enum class BindSheetDismissReason {
41     BACK_PRESSED = 0,
42     TOUCH_OUTSIDE,
43     CLOSE_BUTTON,
44     SLIDE_DOWN,
45 };
46 class ACE_EXPORT SheetPresentationPattern : public LinearLayoutPattern,
47                                             public PopupBasePattern,
48                                             public FocusView,
49                                             public NestableScrollContainer,
50                                             public AutoFillTriggerStateHolder,
51                                             public IAvoidInfoListener {
52     DECLARE_ACE_TYPE(SheetPresentationPattern, LinearLayoutPattern, PopupBasePattern, FocusView,
53         NestableScrollContainer, AutoFillTriggerStateHolder, IAvoidInfoListener);
54 
55 public:
SheetPresentationPattern(int32_t targetId,const std::string & targetTag,std::function<void (const std::string &)> && callback)56     SheetPresentationPattern(
57         int32_t targetId, const std::string& targetTag, std::function<void(const std::string&)>&& callback)
58         : LinearLayoutPattern(true)
59     {
60         targetId_ = targetId;
61         targetTag_ = targetTag;
62         callback_ = std::move(callback);
63     }
64 
65     ~SheetPresentationPattern() override = default;
66 
IsMeasureBoundary()67     bool IsMeasureBoundary() const override
68     {
69         return true;
70     }
71 
SetOverlay(const WeakPtr<OverlayManager> & overlayManager)72     void SetOverlay(const WeakPtr<OverlayManager>& overlayManager)
73     {
74         overlayManager_ = overlayManager;
75     }
76 
IsAtomicNode()77     bool IsAtomicNode() const override
78     {
79         return false;
80     }
81 
CreateLayoutAlgorithm()82     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
83     {
84         return MakeRefPtr<SheetPresentationLayoutAlgorithm>(GetSheetType(), sheetPopupInfo_);
85     }
86 
CreateLayoutProperty()87     RefPtr<LayoutProperty> CreateLayoutProperty() override
88     {
89         return MakeRefPtr<SheetPresentationProperty>();
90     }
91 
GetTargetId()92     int32_t GetTargetId() const override
93     {
94         return targetId_;
95     }
96 
GetTargetTag()97     const std::string& GetTargetTag() const
98     {
99         return targetTag_;
100     }
101 
FireCallback(const std::string & value)102     void FireCallback(const std::string& value)
103     {
104         if (callback_) {
105             callback_(value);
106         }
107     }
108 
UpdateShouldDismiss(std::function<void ()> && shouldDismiss)109     void UpdateShouldDismiss(std::function<void()>&& shouldDismiss)
110     {
111         shouldDismiss_ = std::move(shouldDismiss);
112     }
113 
HasShouldDismiss()114     bool HasShouldDismiss()
115     {
116         if (shouldDismiss_) {
117             return true;
118         }
119         return false;
120     }
121 
CallShouldDismiss()122     void CallShouldDismiss()
123     {
124         if (shouldDismiss_) {
125             shouldDismiss_();
126         }
127     }
128 
UpdateOnDisappear(std::function<void ()> && onDisappear)129     void UpdateOnDisappear(std::function<void()>&& onDisappear)
130     {
131         onDisappear_ = std::move(onDisappear);
132         isExecuteOnDisappear_ = false;
133     }
134 
OnDisappear()135     void OnDisappear()
136     {
137         if (onDisappear_) {
138             TAG_LOGI(AceLogTag::ACE_SHEET, "bindsheet lifecycle change to onDisappear state.");
139             isExecuteOnDisappear_ = true;
140             onDisappear_();
141         }
142         isDismissProcess_ = false;
143     }
144 
UpdateOnWillDisappear(std::function<void ()> && onWillDisappear)145     void UpdateOnWillDisappear(std::function<void()>&& onWillDisappear)
146     {
147         onWillDisappear_ = std::move(onWillDisappear);
148     }
149 
150     void OnWillDisappear();
151 
UpdateOnAppear(std::function<void ()> && onAppear)152     void UpdateOnAppear(std::function<void()>&& onAppear)
153     {
154         onAppear_ = std::move(onAppear);
155     }
156 
OnAppear()157     void OnAppear()
158     {
159         if (onAppear_) {
160             TAG_LOGI(AceLogTag::ACE_SHEET, "bindsheet lifecycle change to onAppear state.");
161             onAppear_();
162         }
163     }
164 
UpdateOnHeightDidChange(std::function<void (const float)> && onHeightDidChange)165     void UpdateOnHeightDidChange(std::function<void(const float)>&& onHeightDidChange)
166     {
167         onHeightDidChange_ = std::move(onHeightDidChange);
168     }
169 
OnHeightDidChange(float currentHeight)170     void OnHeightDidChange(float currentHeight) const
171     {
172         if (onHeightDidChange_) {
173             onHeightDidChange_(currentHeight);
174         }
175     }
176 
177     void FireOnHeightDidChange();
178 
HasOnHeightDidChange()179     bool HasOnHeightDidChange()
180     {
181         if (onHeightDidChange_) {
182             return true;
183         }
184         return false;
185     }
186 
UpdateOnDetentsDidChange(std::function<void (const float)> && onDetentsDidChange)187     void UpdateOnDetentsDidChange(std::function<void(const float)>&& onDetentsDidChange)
188     {
189         onDetentsDidChange_ = std::move(onDetentsDidChange);
190     }
191 
OnDetentsDidChange(float currentHeight)192     void OnDetentsDidChange(float currentHeight) const
193     {
194         if (onDetentsDidChange_) {
195             onDetentsDidChange_(currentHeight);
196         }
197     }
198 
199     void FireOnDetentsDidChange(float height);
200 
UpdateOnWidthDidChange(std::function<void (const float)> && onWidthDidChange)201     void UpdateOnWidthDidChange(std::function<void(const float)>&& onWidthDidChange)
202     {
203         onWidthDidChange_ = std::move(onWidthDidChange);
204     }
205 
onWidthDidChange(float currentWidth)206     void onWidthDidChange(float currentWidth) const
207     {
208         if (onWidthDidChange_) {
209             onWidthDidChange_(currentWidth);
210         }
211     }
212 
213     void FireOnWidthDidChange(RefPtr<FrameNode> sheetNode);
214 
UpdateOnTypeDidChange(std::function<void (const float)> && onTypeDidChange)215     void UpdateOnTypeDidChange(std::function<void(const float)>&& onTypeDidChange)
216     {
217         onTypeDidChange_ = std::move(onTypeDidChange);
218     }
219 
onTypeDidChange(float currentType)220     void onTypeDidChange(float currentType) const
221     {
222         if (onTypeDidChange_) {
223             onTypeDidChange_(currentType);
224         }
225     }
226 
227     void FireOnTypeDidChange();
228 
UpdateOnWillDismiss(std::function<void (const int32_t)> && onWillDismiss)229     void UpdateOnWillDismiss(std::function<void(const int32_t)>&& onWillDismiss)
230     {
231         onWillDismiss_ = std::move(onWillDismiss);
232     }
233 
HasOnWillDismiss()234     bool HasOnWillDismiss() const
235     {
236         if (onWillDismiss_) {
237             return true;
238         }
239         return false;
240     }
241 
CallOnWillDismiss(const int32_t reason)242     void CallOnWillDismiss(const int32_t reason)
243     {
244         if (onWillDismiss_) {
245             onWillDismiss_(reason);
246         }
247     }
248 
UpdateSheetSpringBack(std::function<void ()> && sheetSpringBack)249     void UpdateSheetSpringBack(std::function<void()>&& sheetSpringBack)
250     {
251         sheetSpringBack_ = std::move(sheetSpringBack);
252     }
253 
HasSheetSpringBack()254     bool HasSheetSpringBack() const
255     {
256         if (sheetSpringBack_) {
257             return true;
258         }
259         return false;
260     }
261 
CallSheetSpringBack()262     void CallSheetSpringBack()
263     {
264         if (sheetSpringBack_) {
265             sheetSpringBack_();
266         }
267     }
268 
269     void OverlaySheetSpringBack();
270     void OverlayDismissSheet();
DismissSheet()271     void DismissSheet()
272     {
273         DismissTransition(false);
274     }
275 
SheetSpringBack()276     void SheetSpringBack()
277     {
278         isDismissProcess_ = false;
279         SheetTransition(true);
280     }
281 
282     void InitialLayoutProps();
283 
284     bool IsScrollable() const;
285     void AvoidAiBar();
286 
287     void AvoidSafeArea(bool forceAvoid = false);
288     void CheckBuilderChange();
289     float GetSheetHeightChange();
290     void ScrollTo(float height);
291     bool AdditionalScrollTo(const RefPtr<FrameNode>& scroll, float height);
292     float InitialSingleGearHeight(NG::SheetStyle& sheetStyle);
293     float GetSheetTopSafeArea();
294     float UpdateSheetTransitionOffset();
295 
296     // initial drag gesture event
297     void InitPanEvent();
298     void InitOnkeyEvent(const RefPtr<FocusHub>& focusHub);
299     void HandleFocusEvent();
300     void HandleBlurEvent();
301 
302     void HandleDragStart();
303 
304     void HandleDragUpdate(const GestureEvent& info);
305 
306     void HandleDragEnd(float dragVelocity);
307 
308     void OnCoordScrollStart();
309 
310     bool OnCoordScrollUpdate(float scrollOffset);
311 
312     void OnCoordScrollEnd(float dragVelocity);
313 
314     void SheetTransition(bool isTransitionIn, float dragVelocity = 0.0f);
315 
316     void ModifyFireSheetTransition(float dragVelocity = 0.0f);
317 
318     void SheetInteractiveDismiss(BindSheetDismissReason dismissReason, float dragVelocity = 0.0f);
319 
320     void SetSheetAnimationOption(AnimationOption& option) const;
321 
322     void SetSheetBorderWidth(bool isPartialUpdate = false);
323 
SetCurrentOffset(float currentOffset)324     void SetCurrentOffset(float currentOffset)
325     {
326         currentOffset_ = currentOffset;
327     }
328 
SetCurrentHeight(float currentHeight)329     void SetCurrentHeight(float currentHeight)
330     {
331         if (height_ != currentHeight) {
332             height_ = currentHeight;
333             ChangeScrollHeight(height_);
334         }
335     }
336 
337     bool GetWindowButtonRect(NG::RectF& floatButtons);
338 
SetBottomOffset(const SheetStyle & sheetStyle)339     void SetBottomOffset(const SheetStyle &sheetStyle)
340     {
341         DeviceType deviceType = SystemProperties::GetDeviceType();
342         if (deviceType != DeviceType::TWO_IN_ONE) {
343             TAG_LOGI(AceLogTag::ACE_SHEET, "Bottom offset invalid");
344             return;
345         }
346         if (sheetStyle.bottomOffset.has_value() &&
347             sheetStyle.sheetType.value_or(SheetType::SHEET_BOTTOM) == SheetType::SHEET_BOTTOM) {
348             bottomOffsetX_ = sheetStyle.bottomOffset->GetX();
349             bottomOffsetY_ = sheetStyle.bottomOffset->GetY();
350         } else {
351             bottomOffsetX_ = 0;
352             bottomOffsetY_ = 0;
353         }
354     }
355 
SetCurrentHeightToOverlay(float height)356     void SetCurrentHeightToOverlay(float height)
357     {
358         auto overlayManager = GetOverlayManager();
359         CHECK_NULL_VOID(overlayManager);
360         overlayManager->SetSheetHeight(height);
361     }
362 
363     void ChangeScrollHeight(float height);
364 
GetFocusPattern()365     FocusPattern GetFocusPattern() const override
366     {
367         return { FocusType::SCOPE, true };
368     }
369 
GetRouteOfFirstScope()370     std::list<int32_t> GetRouteOfFirstScope() override
371     {
372         return { 1, 0 };
373     }
374 
IsExecuteOnDisappear()375     bool IsExecuteOnDisappear() const
376     {
377         return isExecuteOnDisappear_;
378     }
379 
AvoidKeyboard()380     bool AvoidKeyboard() const override
381     {
382         return false;
383     }
384 
385     bool IsWindowSizeChangedWithUndefinedReason(int32_t width, int32_t height, WindowSizeChangeReason type);
386 
387     void OnWindowSizeChanged(int32_t width, int32_t height, WindowSizeChangeReason type) override;
388 
HasTitleNode()389     bool HasTitleNode() const
390     {
391         return titleId_.has_value();
392     }
393 
SetTitleId(const int32_t id)394     bool SetTitleId(const int32_t id)
395     {
396         if (HasTitleNode()) {
397             return false;
398         }
399         titleId_ = id;
400         return true;
401     }
402 
GetTitleId()403     int32_t GetTitleId()
404     {
405         if (!titleId_.has_value()) {
406             titleId_ = ElementRegister::GetInstance()->MakeUniqueId();
407         }
408         return titleId_.value();
409     }
410 
HasSubtitleNode()411     bool HasSubtitleNode() const
412     {
413         return titleId_.has_value();
414     }
415 
SetSubtitleId(const int32_t id)416     bool SetSubtitleId(const int32_t id)
417     {
418         if (HasSubtitleNode()) {
419             return false;
420         }
421         subtitleId_ = id;
422         return true;
423     }
424 
GetSubtitleId()425     int32_t GetSubtitleId()
426     {
427         if (!subtitleId_.has_value()) {
428             subtitleId_ = ElementRegister::GetInstance()->MakeUniqueId();
429         }
430         return subtitleId_.value();
431     }
432 
CalculateFriction(float gamma,float ratio)433     static float CalculateFriction(float gamma, float ratio)
434     {
435         if (GreatOrEqual(gamma, 1.0)) {
436             gamma = 1.0f;
437         }
438         return exp(-ratio * gamma);
439     }
440 
441     SheetType GetSheetType();
442     bool IsPhoneInLandScape();
443     bool IsShowCloseIcon();
444     ScrollSizeMode GetScrollSizeMode();
445     void InitSheetMode();
446     void GetSheetTypeWithAuto(SheetType& sheetType);
447     void GetSheetTypeWithPopup(SheetType& sheetType);
448 
449     void SetUIFirstSwitch(bool isFirstTransition, bool isNone);
450 
451     void BubbleStyleSheetTransition(bool isTransitionIn);
452 
453     void StartOffsetEnteringAnimation();
454 
455     void StartAlphaEnteringAnimation(std::function<void()> finish);
456 
457     void StartOffsetExitingAnimation();
458 
459     void StartAlphaExitingAnimation(std::function<void()> finish);
460 
461     void ResetToInvisible();
462 
463     bool IsFoldExpand();
464 
SetSheetKey(const SheetKey & sheetKey)465     void SetSheetKey(const SheetKey& sheetKey)
466     {
467         sheetKey_ = sheetKey;
468     }
469 
GetSheetKey()470     SheetKey GetSheetKey() const
471     {
472         return sheetKey_;
473     }
474 
GetAnimationBreak()475     bool GetAnimationBreak() const
476     {
477         return isAnimationBreak_;
478     }
479 
SetAnimationProcess(bool isProcess)480     void SetAnimationProcess(bool isProcess)
481     {
482         isAnimationProcess_ = isProcess;
483     }
484 
GetAnimationProcess()485     bool GetAnimationProcess()
486     {
487         return isAnimationProcess_;
488     }
489 
SetDismissProcess(bool isProcess)490     void SetDismissProcess(bool isProcess)
491     {
492         isDismissProcess_ = isProcess;
493     }
494 
GetDismissProcess()495     bool GetDismissProcess()
496     {
497         return isDismissProcess_;
498     }
499 
GetPageHeightWithoutOffset()500     float GetPageHeightWithoutOffset() const
501     {
502         return pageHeight_;
503     }
504 
GetPageHeight()505     float GetPageHeight()
506     {
507         // OnTransformTranslateUpdate's offset is the relative to the upper left corner of the father
508         // Therefore, if the father is a PageNode, need to obtain the offsetY of the Page relative to the window
509         // On the basis of the normally calculated offset, move parentOffsetY up,
510         // It can be considered as the offset relative to the window
511         auto parentOffsetY = GetRootOffsetYToWindow();
512         return pageHeight_ - parentOffsetY;
513     }
514 
GetSheetMaxHeight()515     float GetSheetMaxHeight()
516     {
517         // pageHeight - sheetTopSafeArea
518         return sheetMaxHeight_;
519     }
520 
GetSheetMaxWidth()521     float GetSheetMaxWidth()
522     {
523         return sheetMaxWidth_;
524     }
525 
GetSheetOffset()526     float GetSheetOffset()
527     {
528         return sheetOffsetY_;
529     }
530 
531     bool IsShowInSubWindowTwoInOne();
532     bool IsShowInSubWindow();
533     SheetType ComputeSheetTypeInSubWindow();
534     void SheetTransitionAction(float offset, bool isStart, bool isTransitionIn);
535     float ComputeTransitionOffset(float sheetHeight);
536     void InitSheetTransitionAction(float offset);
537     int32_t GetSubWindowId();
538 
GetSheetArrowOffset()539     OffsetF GetSheetArrowOffset() const
540     {
541         return arrowOffset_;
542     }
543 
544     float GetFitContentHeight();
545 
WillSpringBack()546     bool WillSpringBack() const
547     {
548         return isSpringBack_;
549     }
550 
SetShowState(bool show)551     void SetShowState(bool show)
552     {
553         show_ = show;
554     }
555 
GetShowState()556     bool GetShowState() const
557     {
558         return show_;
559     }
560 
SetIsDragging(bool isDrag)561     void SetIsDragging(bool isDrag)
562     {
563         isDrag_ = isDrag;
564     }
565 
IsDragging()566     bool IsDragging() const
567     {
568         return isDrag_;
569     }
570 
571     void UpdateMaskBackgroundColor();
572 
573     void UpdateMaskBackgroundColorRender();
574 
575     void UpdateTitleTextColor();
576 
GetMaskBackgroundColor()577     Color GetMaskBackgroundColor() const
578     {
579         return sheetMaskColor_;
580     }
581 
InitFoldState()582     void InitFoldState()
583     {
584         auto container = Container::Current();
585         CHECK_NULL_VOID(container);
586         container->InitIsFoldable();
587         if (container->IsFoldable()) {
588             currentFoldStatus_ = container->GetCurrentFoldStatus();
589         }
590     }
591 
IsFoldStatusChanged()592     bool IsFoldStatusChanged()
593     {
594         auto container = Container::Current();
595         CHECK_NULL_RETURN(container, false);
596         if (!container->IsFoldable()) {
597             return false;
598         }
599         auto foldStatus = container->GetCurrentFoldStatus();
600         TAG_LOGI(AceLogTag::ACE_SHEET, "newFoldStatus: %{public}d, currentFoldStatus: %{public}d.",
601             static_cast<int32_t>(foldStatus), static_cast<int32_t>(currentFoldStatus_));
602         if (foldStatus != currentFoldStatus_) {
603             currentFoldStatus_ = foldStatus;
604             return true;
605         }
606         return false;
607     }
608 
UpdateHoverModeChangedCallbackId(const std::optional<int32_t> & id)609     void UpdateHoverModeChangedCallbackId(const std::optional<int32_t>& id)
610     {
611         hoverModeChangedCallbackId_ = id;
612     }
613 
HasHoverModeChangedCallbackId()614     bool HasHoverModeChangedCallbackId()
615     {
616         return hoverModeChangedCallbackId_.has_value();
617     }
618 
619     // Get ScrollHeight before avoid keyboard
GetScrollHeight()620     float GetScrollHeight() const
621     {
622         auto titleHeight = GetFirstChildHeight();
623         if (sheetType_ == SheetType::SHEET_CENTER) {
624             return centerHeight_ - titleHeight;
625         }
626         return height_ - titleHeight;
627     }
628 
629     float GetFirstChildHeight() const;
630 
631     RefPtr<OverlayManager> GetOverlayManager();
632     RefPtr<FrameNode> GetOverlayRoot();
633     float GetRootOffsetYToWindow();
634 
IsAvoidingKeyboard()635     bool IsAvoidingKeyboard() const
636     {
637         return Positive(keyboardHeight_);
638     }
639 
640     bool IsTypeNeedAvoidAiBar();
641     void IsNeedPlayTransition(const SheetStyle& sheetStyle);
642 
643     RefPtr<FrameNode> GetFirstFrameNodeOfBuilder() const;
644     void GetBuilderInitHeight();
645     void ChangeSheetPage(float height);
646     void DumpAdvanceInfo() override;
647     void DumpAdvanceInfo(std::unique_ptr<JsonValue>& json) override;
648 
GetDetentsIndex()649     uint32_t GetDetentsIndex() const
650     {
651         return detentsFinalIndex_;
652     }
653     bool IsScrollOutOfBoundary();
654 
UpdateSheetType()655     void UpdateSheetType()
656     {
657         sheetType_ = GetSheetType();
658     }
659 
660     // Used for isolation of SHEET_BOTTOMLANDSPACE after version 12, such as support for height setting callback,
661     // support for detents setting and callback for SHEET_BOTTOMLANDSPACE
IsSheetBottomStyle()662     bool IsSheetBottomStyle()
663     {
664         // sheetType_ is invalid before onModifyDone
665         if (AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_TWELVE)) {
666             return sheetType_ == SheetType::SHEET_BOTTOM || sheetType_ == SheetType::SHEET_BOTTOM_FREE_WINDOW ||
667                    sheetType_ == SheetType::SHEET_BOTTOMLANDSPACE;
668         }
669         return sheetType_ == SheetType::SHEET_BOTTOM || sheetType_ == SheetType::SHEET_BOTTOM_FREE_WINDOW;
670     }
671 
672     // If has dispute about version isolation, suggest use the following. And it does not support SHEET_BOTTOM_OFFSET
IsSheetBottom()673     bool IsSheetBottom()
674     {
675         auto sheetType = GetSheetType();
676         return !(sheetType == SheetType::SHEET_CENTER || sheetType == SheetType::SHEET_POPUP ||
677                  sheetType == SheetType::SHEET_BOTTOM_OFFSET);
678     }
679 
680     // Nestable Scroll
GetAxis()681     Axis GetAxis() const override
682     {
683         return Axis::VERTICAL;
684     }
685     ScrollResult HandleScroll(float scrollOffset, int32_t source,
686         NestedState state = NestedState::GESTURE, float velocity = 0.f) override;
687     void OnScrollStartRecursive(
688         WeakPtr<NestableScrollContainer> child, float position, float dragVelocity = 0.0f) override;
689     void OnScrollEndRecursive (const std::optional<float>& velocity) override;
690     bool HandleScrollVelocity(float velocity, const RefPtr<NestableScrollContainer>& child = nullptr) override;
691     ScrollResult HandleScrollWithSheet(float scrollOffset);
692     Shadow GetShadowFromTheme(ShadowStyle shadowStyle);
693     void SetShadowStyle(bool isFocused);
694     bool IsCurSheetNeedHalfFoldHover();
695     float GetMaxSheetHeightBeforeDragUpdate();
696     float GetSheetHeightBeforeDragUpdate();
697     void FireHoverModeChangeCallback();
698     void InitFoldCreaseRegion();
699     Rect GetFoldScreenRect() const;
700     void RecoverHalfFoldOrAvoidStatus();
701     bool UpdateAccessibilityDetents(float height);
702     void CalculateSheetRadius(BorderRadiusProperty& sheetRadius);
703 
UpdateSheetPopupInfo(const SheetPopupInfo & sheetPopupInfo)704     void UpdateSheetPopupInfo(const SheetPopupInfo& sheetPopupInfo)
705     {
706         sheetPopupInfo_ = sheetPopupInfo;
707     }
708 
GetSheetPopupInfo()709     SheetPopupInfo GetSheetPopupInfo() const
710     {
711         return sheetPopupInfo_;
712     }
713 
714     bool UpdateIndexByDetentSelection(const SheetStyle& sheetStyle, bool isFirstTransition);
715 
GetIsPlayTransition()716     bool GetIsPlayTransition() const
717     {
718         return isPlayTransition_;
719     }
720     void OnFontScaleConfigurationUpdate() override;
721 
722     void FireCommonCallback();
723 
SetCloseButtonNode(const WeakPtr<FrameNode> & node)724     void SetCloseButtonNode(const WeakPtr<FrameNode>& node) {
725         closeButtonNode_ = node;
726     }
727 
SetScrollNode(const WeakPtr<FrameNode> & node)728     void SetScrollNode(const WeakPtr<FrameNode>& node) {
729         scrolNode_ = node;
730     }
731 
SetTitleBuilderNode(const WeakPtr<FrameNode> & node)732     void SetTitleBuilderNode(const WeakPtr<FrameNode>& node) {
733         titleBuilderNode_ = node;
734     }
735 
GetSheetCloseIcon()736     RefPtr<FrameNode> GetSheetCloseIcon() const
737     {
738         auto closeButtonNode = closeButtonNode_.Upgrade();
739         return closeButtonNode;
740     }
741 
GetTitleBuilderNode()742     RefPtr<FrameNode> GetTitleBuilderNode() const
743     {
744         auto titleBuilderNode = titleBuilderNode_.Upgrade();
745         return titleBuilderNode;
746     }
747 
GetSheetScrollNode()748     RefPtr<FrameNode> GetSheetScrollNode() const
749     {
750         auto scrollNode = scrolNode_.Upgrade();
751         return scrollNode;
752     }
753 
754 protected:
755     void OnDetachFromFrameNode(FrameNode* sheetNode) override;
756 
757 private:
758     void OnModifyDone() override;
759     void OnAttachToFrameNode() override;
760     void OnColorConfigurationUpdate() override;
761     bool OnDirtyLayoutWrapperSwap(const RefPtr<LayoutWrapper>& dirty, const DirtySwapConfig& config) override;
762     void OnAvoidInfoChange(const ContainerModalAvoidInfo& info) override;
763     void RegisterAvoidInfoChangeListener(const RefPtr<FrameNode>& hostNode);
764     void UnRegisterAvoidInfoChangeListener(FrameNode* hostNode);
765 
766     void RegisterHoverModeChangeCallback();
767     void InitScrollProps();
768     void InitPageHeight();
769     void TranslateTo(float height);
770     void SetColumnMinSize(bool reset = false);
771     void UpdateDragBarStatus();
772     void UpdateCloseIconStatus();
773     void UpdateTitlePadding();
774     RefPtr<FrameNode> GetTitleNode();
775     float GetCloseIconPosX(const SizeF& sheetSize, const RefPtr<SheetTheme>& sheetTheme);
776     void UpdateSheetTitle();
777     void UpdateFontScaleStatus();
778     RefPtr<RenderContext> GetRenderContext();
779     bool PostTask(const TaskExecutor::Task& task, const std::string& name);
780     void CheckSheetHeightChange();
781     float GetWrapperHeight();
782     bool SheetHeightNeedChanged();
783     void InitSheetDetents();
784     void InitDetents(SheetStyle sheetStyle, float height, double mediumSize, float largeHeightOfTheme,
785         double largeHeight);
786     void HandleFitContontChange(float height);
787     void ChangeSheetHeight(float height);
788     void StartSheetTransitionAnimation(const AnimationOption& option, bool isTransitionIn, float offset);
789     void DismissSheetShadow(const RefPtr<RenderContext>& context);
790     void ClipSheetNode();
791     void CreatePropertyCallback();
792     void ComputeDetentsPos(float currentSheetHeight, float& upHeight, float& downHeight, uint32_t& detentsLowerPos,
793         uint32_t& detentsUpperPos);
794     void IsCustomDetentsChanged(SheetStyle sheetStyle);
795     void CalculateAloneSheetRadius(
796         std::optional<Dimension>& sheetRadius, const std::optional<Dimension>& sheetStyleRadius);
797     std::string GetPopupStyleSheetClipPath(const SizeF& sheetSize, const BorderRadiusProperty& sheetRadius);
798     std::string GetPopupStyleSheetClipPathNew(const SizeF& sheetSize, const BorderRadiusProperty& sheetRadius);
799     std::string GetCenterStyleSheetClipPath(SizeF sheetSize, Dimension sheetRadius);
800     std::string GetBottomStyleSheetClipPath(SizeF sheetSize, Dimension sheetRadius);
801     std::string MoveTo(double x, double y);
802     std::string LineTo(double x, double y);
803     std::string ArcTo(double rx, double ry, double rotation, int32_t arc_flag, double x, double y);
804     void DismissTransition(bool isTransitionIn, float dragVelocity = 0.0f);
805     float GetTopAreaInWindow() const;
806     void MarkSheetPageNeedRender();
807     void SetSheetOuterBorderWidth(const RefPtr<SheetTheme>& sheetTheme, const NG::SheetStyle& sheetStyle);
808     PipelineContext* GetSheetMainPipeline() const;
809     float GetBottomSafeArea();
810     void AvoidKeyboardBySheetMode(bool forceAvoid = false);
811     bool AvoidKeyboardBeforeTranslate();
812     void AvoidKeyboardAfterTranslate(float height);
813     void DecreaseScrollHeightInSheet(float decreaseHeight);
814     bool IsResizeWhenAvoidKeyboard();
GetRadio()815     float GetRadio() const
816     {
817         return sheetType_ == SheetType::SHEET_BOTTOM_OFFSET ? 5.0f : 1.848f;
818     }
819     void ResetClipShape();
820     void UpdateSheetWhenSheetTypeChanged();
821     void GetCurrentScrollHeight();
822     void RecoverAvoidKeyboardStatus();
823     void RecoverScrollOrResizeAvoidStatus();
824 
825     // broadcast
826     void SendTextUpdateEvent();
827     void SendSelectedEvent();
828     void HandleFollowAccessibilityEvent(float currHeight);
829     void HandleDragEndAccessibilityEvent();
830     void RegisterElementInfoCallBack();
831     uint32_t GetCurrentBroadcastDetentsIndex();
832 
833     void GetArrowOffsetByPlacement(const RefPtr<SheetPresentationLayoutAlgorithm>& layoutAlgorithm);
834     std::string DrawClipPathBottom(const SizeF&, const BorderRadiusProperty&);
835     std::string DrawClipPathTop(const SizeF&, const BorderRadiusProperty&);
836     std::string DrawClipPathLeft(const SizeF&, const BorderRadiusProperty&);
837     std::string DrawClipPathRight(const SizeF&, const BorderRadiusProperty&);
838 
839     uint32_t broadcastPreDetentsIndex_ = 0;
840     SheetAccessibilityDetents sheetDetents_ = SheetAccessibilityDetents::HIGH;
841 
842     uint32_t keyboardHeight_ = 0;
843     int32_t targetId_ = -1;
844     SheetKey sheetKey_;
845     std::optional<int32_t> titleId_;
846     std::optional<int32_t> subtitleId_;
847     std::string targetTag_;
848     std::function<void(const std::string&)> callback_;
849     std::function<void()> onDisappear_;
850     std::function<void()> onWillDisappear_;
851     std::function<void()> shouldDismiss_;
852     std::function<void(const int32_t info)> onWillDismiss_;
853     std::function<void()> sheetSpringBack_;
854     std::function<void(const float)> onHeightDidChange_;
855     std::function<void(const float)> onDetentsDidChange_;
856     std::function<void(const float)> onWidthDidChange_;
857     std::function<void(const float)> onTypeDidChange_;
858     std::function<void()> onAppear_;
859     RefPtr<PanEvent> panEvent_;
860     OffsetF arrowOffset_;
861     float currentOffset_ = 0.0f;
862 
863     float preDidHeight_ = 0.0f;
864     float sheetHeightUp_ = 0.0f; // sheet offset to move up when avoiding keyboard
865     float height_ = 0.0f; // sheet height, start from the bottom, before avoiding keyboard
866     float sheetHeight_ = 0.0f; // sheet frameSize Height
867     float wrapperHeight_ = 0.0f; // sheetWrapper frameSize Height
868     float pageHeight_ = 0.0f; // root Height, = maxSize.Height()
869     float scrollHeight_ = 0.0f;
870     float preWidth_ = 0.0f;
871     int32_t preType_ = -1;
872     float sheetTopSafeArea_ = .0f;
873     bool isExecuteOnDisappear_ = false;
874     bool windowRotate_ = false;
875     bool isScrolling_ = false;
876     float builderHeight_ = 0.0f;
877     float sheetMaxHeight_ = 0.0f; // start from the bottom, pageHeight - sheetTopSafeArea
878     float sheetMaxWidth_ = 0.0f;
879     float centerHeight_ = 0.0f; // node height, not translate height
880     float sheetFitContentHeight_ = 0.0f;
881     float sheetOffsetX_ = 0.0f;
882     float sheetOffsetY_ = 0.0f;
883     float bottomOffsetX_ = 0.0f; // offset x with SHEET_BOTTOM_OFFSET
884     float bottomOffsetY_ = 0.0f; // offset y with SHEET_BOTTOM_OFFSET, <= 0
885     bool isFirstInit_ = true;
886     bool isAnimationBreak_ = false;
887     bool isAnimationProcess_ = false;
888     bool isDismissProcess_ = false;
889     SheetType sheetType_ = SheetType::SHEET_BOTTOM;
890     bool windowChanged_ = false;
891     bool isDirectionUp_ = true;
892     bool topSafeAreaChanged_ = false;
893     ScrollSizeMode scrollSizeMode_ = ScrollSizeMode::FOLLOW_DETENT;
894     SheetEffectEdge sheetEffectEdge_ = SheetEffectEdge::ALL;
895 
896     //record sheet sored detent index
897     uint32_t detentsIndex_ = 0;
898 
899     //record sheet unsoreddetent index
900     uint32_t detentsFinalIndex_ = 0;
901     std::string sheetThemeType_ = "auto";
902 
903     WeakPtr<OverlayManager> overlayManager_ = nullptr;
904 
905     std::vector<SheetHeight> preDetents_;
906     std::vector<float> sheetDetentHeight_;
907     std::vector<float> unSortedSheetDentents_;
908     std::vector<Rect> currentFoldCreaseRegion_;
909 
910     std::shared_ptr<AnimationUtils::Animation> animation_;
911     std::optional<int32_t> foldDisplayModeChangedCallbackId_;
912     std::optional<int32_t> hoverModeChangedCallbackId_;
913 
914     bool show_ = true;
915     bool isDrag_ = false;
916     FoldStatus currentFoldStatus_ = FoldStatus::UNKNOWN;
917     bool isNeedProcessHeight_ = false;
918     bool isSheetNeedScroll_ = false; // true if Sheet is ready to receive scroll offset.
919     bool isSheetPosChanged_ = false; // UpdateTransformTranslate end
920     bool isSpringBack_ = false; // sheet rebound
921 
922     double start_ = 0.0; // start position of detents changed
923     RefPtr<NodeAnimatablePropertyFloat> property_;
924 
925     ACE_DISALLOW_COPY_AND_MOVE(SheetPresentationPattern);
926 
927     float preDetentsHeight_ = 0.0f;
928     std::optional<SizeT<int32_t>> windowSize_;
929     float scale_ = 1.0;
930 
931     Color sheetMaskColor_ = Color::TRANSPARENT;
932     SheetKeyboardAvoidMode keyboardAvoidMode_ = SheetKeyboardAvoidMode::TRANSLATE_AND_SCROLL;
933     float resizeDecreasedHeight_ = 0.f;
934     bool isPlayTransition_ = false;
935     Placement finalPlacement_ = Placement::BOTTOM;
936     bool showArrow_ = true;
937     SheetArrowPosition arrowPosition_ = SheetArrowPosition::NONE;
938     SheetPopupInfo sheetPopupInfo_;
939     WeakPtr<FrameNode> closeButtonNode_;
940     WeakPtr<FrameNode> scrolNode_;
941     WeakPtr<FrameNode> titleBuilderNode_;
942 };
943 } // namespace OHOS::Ace::NG
944 
945 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_OVERLAY_SHEET_PRESENTATION_PATTERN_H
946