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