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_TOAST_TOAST_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOAST_TOAST_COMPONENT_H 18 19 #include <string> 20 21 #include "base/memory/ace_type.h" 22 #include "base/utils/singleton.h" 23 #include "core/components/box/box_component.h" 24 #include "core/components/common/properties/tween_option.h" 25 #include "core/components/text/text_component.h" 26 #include "core/components/toast/toast_theme.h" 27 #include "core/pipeline/pipeline_context.h" 28 29 namespace OHOS::Ace { 30 using ToastAnimationCallback = std::function<void()>; 31 class ToastComponent final : public Singleton<ToastComponent> { 32 DECLARE_SINGLETON(ToastComponent); 33 34 public: 35 void Show(const RefPtr<PipelineContext>& context, const std::string& message, int32_t duration, 36 const std::string& bottom, bool isRightToLeft); 37 void SetToastStopListenerCallback(std::function<void()>&& stopCallback); 38 39 private: 40 static int32_t GenerateNextToastId(); 41 void BuildToastContent(const RefPtr<TextComponent>& text, const RefPtr<ToastTheme>& toastTheme); 42 void BuildPackageBox(const RefPtr<PipelineContext>& context, const RefPtr<BoxComponent>& box, 43 const RefPtr<TextComponent>& text, const RefPtr<ToastTheme>& toastTheme); 44 void InitToastAnimation(); 45 46 TweenOption tweenOption_; 47 float toastDurationTime_ = 0.0f; 48 ToastAnimationCallback stopCallback_; 49 }; 50 51 } // namespace OHOS::Ace 52 53 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_TOAST_TOAST_COMPONENT_H 54