120 lines
3.9 KiB
C++
120 lines
3.9 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
|
|
*
|
|
* Description: TjdUiPageTransition.cpp
|
|
*
|
|
* Author: luziquan@ss-tjd.com
|
|
*
|
|
* Create: 2025-06-05
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiPageTransition.h"
|
|
|
|
namespace TJD {
|
|
|
|
UIPageTranslationManager::UIPageTranslationManager()
|
|
{
|
|
translations_.resize(static_cast<int>(PageTransitionType::PAGE_TRANSITION_TRANSLATION_MAX));
|
|
}
|
|
|
|
UIPageTranslationManager &UIPageTranslationManager::GetInstance()
|
|
{
|
|
static UIPageTranslationManager instance;
|
|
return instance;
|
|
}
|
|
|
|
void UIPageTranslationManager::RegisterTranslation(PageTransitionType type, UIPageTranslation *translation)
|
|
{
|
|
translations_[static_cast<int>(type)] = translation;
|
|
}
|
|
|
|
UIPageTranslation *UIPageTranslationManager::GetTranslation(PageTransitionType type)
|
|
{
|
|
return translations_[static_cast<int>(type)];
|
|
}
|
|
|
|
TJD_REGISTER_PAGE_TRANSLATION(PageTransitionType::PAGE_TRANSITION_TRANSLATION_ENTER, TranslationEnter);
|
|
void TranslationEnter::Init(OHOS::UIImageView *target, OHOS::UIImageView *current, OHOS::UIViewGroup *parent,
|
|
uint32_t duration)
|
|
{
|
|
if (target == nullptr || current == nullptr || parent == nullptr) {
|
|
return;
|
|
}
|
|
targetImage_ = target;
|
|
currentImage_ = current;
|
|
duration_ = duration;
|
|
parent_ = parent;
|
|
parent_->Insert(nullptr, targetImage_);
|
|
parent_->Insert(targetImage_, currentImage_);
|
|
}
|
|
|
|
void TranslationEnter::ApplyAnimation(int32_t runTime)
|
|
{
|
|
if (parent_ == nullptr || targetImage_ == nullptr || currentImage_ == nullptr) {
|
|
return;
|
|
}
|
|
int16_t pos = OHOS::EasingEquation::QuadEaseIn(466, 0, runTime, duration_);
|
|
int16_t curPos = OHOS::EasingEquation::QuadEaseIn(0, -100, runTime, duration_);
|
|
int16_t opa = OHOS::EasingEquation::QuadEaseIn(255, 0, runTime, duration_);
|
|
currentImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, opa);
|
|
currentImage_->SetX(curPos);
|
|
targetImage_->SetX(pos);
|
|
if (parent_) {
|
|
parent_->Invalidate();
|
|
}
|
|
}
|
|
|
|
void TranslationEnter::OnStop()
|
|
{
|
|
if (parent_ == nullptr || targetImage_ == nullptr || currentImage_ == nullptr) {
|
|
return;
|
|
}
|
|
currentImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, OHOS::OPA_OPAQUE);
|
|
targetImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, OHOS::OPA_OPAQUE);
|
|
parent_->Remove(currentImage_);
|
|
parent_->Remove(targetImage_);
|
|
}
|
|
|
|
TJD_REGISTER_PAGE_TRANSLATION(PageTransitionType::PAGE_TRANSITION_TRANSLATION_EXIT, TranslationExit);
|
|
void TranslationExit::Init(OHOS::UIImageView *target, OHOS::UIImageView *current, OHOS::UIViewGroup *parent,
|
|
uint32_t duration)
|
|
{
|
|
if (target == nullptr || current == nullptr || parent == nullptr) {
|
|
return;
|
|
}
|
|
targetImage_ = target;
|
|
currentImage_ = current;
|
|
duration_ = duration;
|
|
parent_ = parent;
|
|
parent_->Insert(nullptr, targetImage_);
|
|
parent_->Insert(targetImage_, currentImage_);
|
|
}
|
|
|
|
void TranslationExit::ApplyAnimation(int32_t runTime)
|
|
{
|
|
if (parent_ == nullptr || targetImage_ == nullptr || currentImage_ == nullptr) {
|
|
return;
|
|
}
|
|
int16_t pos = OHOS::EasingEquation::QuadEaseIn(0, 466, runTime, duration_);
|
|
int16_t tarPos = OHOS::EasingEquation::QuadEaseIn(-100, 0, runTime, duration_);
|
|
int16_t opa = OHOS::EasingEquation::QuadEaseIn(0, 255, runTime, duration_);
|
|
targetImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, opa);
|
|
targetImage_->SetX(tarPos);
|
|
currentImage_->SetX(pos);
|
|
if (parent_) {
|
|
parent_->Invalidate();
|
|
}
|
|
}
|
|
|
|
void TranslationExit::OnStop()
|
|
{
|
|
if (parent_ == nullptr || targetImage_ == nullptr || currentImage_ == nullptr) {
|
|
return;
|
|
}
|
|
currentImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, OHOS::OPA_OPAQUE);
|
|
targetImage_->SetStyle(OHOS::STYLE_IMAGE_OPA, OHOS::OPA_OPAQUE);
|
|
parent_->Remove(currentImage_);
|
|
parent_->Remove(targetImage_);
|
|
}
|
|
|
|
} // namespace TJD
|