add disappearing animation to start page

Signed-off-by: qpzeng <zengqingpeng6@huawei.com>
Change-Id: I3aeab9004dab94a06baebb1a8d5f237ac1df35e6
This commit is contained in:
qpzeng 2023-07-15 13:58:18 +08:00
parent 71b66d3021
commit efa241a2cf
5 changed files with 46 additions and 10 deletions

View File

@ -31,6 +31,16 @@ namespace OHOS::Ace::NG {
namespace {
constexpr uint32_t COLOR_BLACK = 0xff000000;
constexpr uint32_t COLOR_WHITE = 0xffffffff;
const std::map<std::string, Rosen::RSAnimationTimingCurve> curveMap {
{ "default", Rosen::RSAnimationTimingCurve::DEFAULT },
{ "linear", Rosen::RSAnimationTimingCurve::LINEAR },
{ "ease", Rosen::RSAnimationTimingCurve::EASE },
{ "easeIn", Rosen::RSAnimationTimingCurve::EASE_IN },
{ "easeOut", Rosen::RSAnimationTimingCurve::EASE_OUT },
{ "easeInOut", Rosen::RSAnimationTimingCurve::EASE_IN_OUT },
{ "spring", Rosen::RSAnimationTimingCurve::SPRING },
{ "interactiveSpring", Rosen::RSAnimationTimingCurve::INTERACTIVE_SPRING },
};
} // namespace
class LifecycleListener : public Rosen::ILifecycleListener {
@ -208,9 +218,27 @@ void WindowPattern::BufferAvailableCallback()
{
ContainerScope scope(instanceId_);
const auto& config =
Rosen::SceneSessionManager::GetInstance().GetWindowSceneConfig().startingWindowAnimationConfig_;
if (config.enabled_) {
CHECK_NULL_VOID(startingNode_);
auto context = AceType::DynamicCast<RosenRenderContext>(startingNode_->GetRenderContext());
CHECK_NULL_VOID(context);
auto rsNode = context->GetRSNode();
CHECK_NULL_VOID(rsNode);
auto effect = Rosen::RSTransitionEffect::Create()->Opacity(config.opacityEnd_);
rsNode->SetTransitionEffect(effect);
Rosen::RSAnimationTimingProtocol protocol;
protocol.SetDuration(config.duration_);
auto curve = curveMap.count(config.curve_) ? curveMap.at(config.curve_) :
Rosen::RSAnimationTimingCurve::DEFAULT;
Rosen::RSNode::Animate(protocol, curve, [rsNode, effect] {
rsNode->NotifyTransition(effect, false);
});
}
auto host = GetHost();
CHECK_NULL_VOID(host);
host->RemoveChild(startingNode_);
startingNode_.Reset();
host->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);

View File

@ -46,11 +46,13 @@ void WindowSceneModel::Create(uint64_t persistentId)
auto nodeId = stack->ClaimNodeId();
auto windowNode = WindowNode::GetOrCreateWindowNode(V2::WINDOW_SCENE_ETS_TAG, nodeId,
[sceneSession]() { return AceType::MakeRefPtr<WindowScene>(sceneSession); });
stack->Push(windowNode);
auto windowScene = windowNode->GetPattern<WindowScene>();
windowScene->UpdateSession(sceneSession);
if (windowNode->GetHitTestMode() == HitTestMode::HTMDEFAULT) {
windowNode->SetHitTestMode(HitTestMode::HTMBLOCK);
}
stack->Push(windowNode);
auto windowScene = windowNode->GetPattern<WindowScene>();
windowScene->UpdateSession(sceneSession);
}
} // namespace OHOS::Ace::NG

View File

@ -25,7 +25,7 @@ class ScreenPattern : public StackPattern {
DECLARE_ACE_TYPE(ScreenPattern, StackPattern);
public:
ScreenPattern(const sptr<Rosen::ScreenSession>& screenSession) : screenSession_(screenSession) {}
explicit ScreenPattern(const sptr<Rosen::ScreenSession>& screenSession) : screenSession_(screenSession) {}
~ScreenPattern() override = default;
std::optional<RenderContext::ContextParam> GetContextParam() const override

View File

@ -48,5 +48,10 @@ RefPtr<RenderContext> RenderContext::Create()
return MakeRefPtr<RosenRenderContext>();
}
void RosenRenderContext::SetRSNode(const std::shared_ptr<RSNode>& rsNode) {}
const std::shared_ptr<Rosen::RSNode>& RosenRenderContext::GetRSNode()
{
return nullptr;
}
void RosenRenderContext::SetRSNode(const std::shared_ptr<Rosen::RSNode>& rsNode) {}
} // namespace OHOS::Ace::NG

View File

@ -13,18 +13,19 @@
* limitations under the License.
*/
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H
#ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_RENDER_CONTEXT_H
#define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_RENDER_CONTEXT_H
#include "core/components_ng/render/render_context.h"
namespace OHOS::Ace::NG {
class RosenRenderContext : public RenderContext {
DECLARE_ACE_TYPE(RosenRenderContext, RenderContext)
DECLARE_ACE_TYPE(RosenRenderContext, RenderContext);
public:
const std::shared_ptr<Rosen::RSNode>& GetRSNode();
void SetRSNode(const std::shared_ptr<Rosen::RSNode>& rsNode);
};
} // namespace OHOS::Ace::NG
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_RENDER_CONTEXT_H
#endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_MOCK_ROSEN_RENDER_CONTEXT_H