mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-10-07 16:33:54 +00:00
Merge branch 'transitition_callbac' of https://gitee.com/XiaoBaiAHui/arkui_ace_engine into HEAD
Change-Id: Id1be94705471b3a944aec560e66f8a7fd327f5ee
This commit is contained in:
commit
efafc864cf
@ -2135,6 +2135,15 @@ RefPtr<FrameNode> FrameNode::FindChildByPosition(float x, float y)
|
||||
return hitFrameNodes.rbegin()->second;
|
||||
}
|
||||
|
||||
RefPtr<NodeAnimatablePropertyBase> FrameNode::GetAnimatablePropertyFloat(const std::string& propertyName) const
|
||||
{
|
||||
auto iter = nodeAnimatablePropertyMap_.find(propertyName);
|
||||
if (iter == nodeAnimatablePropertyMap_.end()) {
|
||||
return nullptr;
|
||||
}
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
void FrameNode::CreateAnimatablePropertyFloat(
|
||||
const std::string& propertyName, float value, const std::function<void(float)>& onCallbackEvent)
|
||||
{
|
||||
@ -2149,6 +2158,17 @@ void FrameNode::CreateAnimatablePropertyFloat(
|
||||
nodeAnimatablePropertyMap_.emplace(propertyName, property);
|
||||
}
|
||||
|
||||
void FrameNode::DeleteAnimatablePropertyFloat(const std::string& propertyName)
|
||||
{
|
||||
auto context = GetRenderContext();
|
||||
CHECK_NULL_VOID(context);
|
||||
RefPtr<NodeAnimatablePropertyBase> propertyRef = GetAnimatablePropertyFloat(propertyName);
|
||||
if (propertyRef) {
|
||||
context->DetachNodeAnimatableProperty(propertyRef);
|
||||
nodeAnimatablePropertyMap_.erase(propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
void FrameNode::UpdateAnimatablePropertyFloat(const std::string& propertyName, float value)
|
||||
{
|
||||
auto iter = nodeAnimatablePropertyMap_.find(propertyName);
|
||||
|
@ -432,8 +432,10 @@ public:
|
||||
|
||||
RefPtr<FrameNode> FindChildByPosition(float x, float y);
|
||||
|
||||
RefPtr<NodeAnimatablePropertyBase> GetAnimatablePropertyFloat(const std::string& propertyName) const;
|
||||
void CreateAnimatablePropertyFloat(
|
||||
const std::string& propertyName, float value, const std::function<void(float)>& onCallbackEvent);
|
||||
void DeleteAnimatablePropertyFloat(const std::string& propertyName);
|
||||
void UpdateAnimatablePropertyFloat(const std::string& propertyName, float value);
|
||||
void CreateAnimatableArithmeticProperty(const std::string& propertyName, RefPtr<CustomAnimatableArithmetic>& value,
|
||||
std::function<void(const RefPtr<CustomAnimatableArithmetic>&)>& onCallbackEvent);
|
||||
|
@ -26,6 +26,7 @@
|
||||
namespace OHOS::Ace::NG {
|
||||
|
||||
namespace {
|
||||
std::string KEY_PAGE_TRANSITION_PROPERTY = "pageTransitionProperty";
|
||||
void IterativeAddToSharedMap(const RefPtr<UINode>& node, SharedTransitionMap& map)
|
||||
{
|
||||
const auto& children = node->GetChildren();
|
||||
@ -79,37 +80,28 @@ bool PagePattern::TriggerPageTransition(PageTransitionType type, const std::func
|
||||
auto wrappedOnFinish = [weak = WeakClaim(this), sharedFinish = pageTransitionFinish_]() {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
auto host = pattern->GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
if (sharedFinish == pattern->pageTransitionFinish_) {
|
||||
// ensure this is exactly the finish callback saved in pagePattern,
|
||||
// otherwise means new pageTransition started
|
||||
pattern->FirePageTransitionFinish();
|
||||
host->DeleteAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY);
|
||||
}
|
||||
};
|
||||
if (effect && effect->GetUserCallback()) {
|
||||
if (!controller_) {
|
||||
controller_ = CREATE_ANIMATOR(PipelineContext::GetCurrentContext());
|
||||
}
|
||||
if (!controller_->IsStopped()) {
|
||||
controller_->Finish();
|
||||
}
|
||||
controller_->ClearInterpolators();
|
||||
RouteType routeType = (type == PageTransitionType::ENTER_POP || type == PageTransitionType::EXIT_POP)
|
||||
? RouteType::POP
|
||||
: RouteType::PUSH;
|
||||
auto floatAnimation = AceType::MakeRefPtr<CurveAnimation<float>>(0.0f, 1.0f, effect->GetCurve());
|
||||
floatAnimation->AddListener(
|
||||
[routeType, handler = effect->GetUserCallback(), weak = WeakClaim(this)](const float& progress) {
|
||||
auto pattern = weak.Upgrade();
|
||||
CHECK_NULL_VOID(pattern);
|
||||
handler(routeType, progress);
|
||||
});
|
||||
if (effect->GetDelay() >= 0) {
|
||||
controller_->SetStartDelay(effect->GetDelay());
|
||||
}
|
||||
controller_->SetDuration(effect->GetDuration());
|
||||
controller_->AddInterpolator(floatAnimation);
|
||||
controller_->AddStopListener(wrappedOnFinish);
|
||||
controller_->Forward();
|
||||
host->CreateAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY, 0.0f,
|
||||
[routeType, handler = effect->GetUserCallback()](const float& progress) { handler(routeType, progress); });
|
||||
auto handler = effect->GetUserCallback();
|
||||
handler(routeType, 0.0f);
|
||||
AnimationOption option(effect->GetCurve(), effect->GetDuration());
|
||||
option.SetDelay(effect->GetDelay());
|
||||
AnimationUtils::OpenImplicitAnimation(option, option.GetCurve(), wrappedOnFinish);
|
||||
host->UpdateAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY, 1.0f);
|
||||
AnimationUtils::CloseImplicitAnimation();
|
||||
return renderContext->TriggerPageTransition(type, nullptr);
|
||||
}
|
||||
return renderContext->TriggerPageTransition(type, wrappedOnFinish);
|
||||
@ -272,10 +264,18 @@ void PagePattern::FirePageTransitionFinish()
|
||||
|
||||
void PagePattern::StopPageTransition()
|
||||
{
|
||||
if (controller_ && !controller_->IsStopped()) {
|
||||
controller_->Finish();
|
||||
auto host = GetHost();
|
||||
CHECK_NULL_VOID(host);
|
||||
auto property = host->GetAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY);
|
||||
if (property) {
|
||||
FirePageTransitionFinish();
|
||||
return;
|
||||
}
|
||||
AnimationOption option(Curves::LINEAR, 0);
|
||||
AnimationUtils::Animate(
|
||||
option, [host]() { host->UpdateAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY, 0.0f); },
|
||||
nullptr);
|
||||
host->DeleteAnimatablePropertyFloat(KEY_PAGE_TRANSITION_PROPERTY);
|
||||
FirePageTransitionFinish();
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,6 @@ private:
|
||||
}
|
||||
|
||||
RefPtr<PageInfo> pageInfo_;
|
||||
RefPtr<Animator> controller_;
|
||||
|
||||
std::function<void()> onPageShow_;
|
||||
std::function<void()> onPageHide_;
|
||||
|
@ -3644,6 +3644,15 @@ void RosenRenderContext::AttachNodeAnimatableProperty(RefPtr<NodeAnimatablePrope
|
||||
}
|
||||
}
|
||||
|
||||
void RosenRenderContext::DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase>& property)
|
||||
{
|
||||
CHECK_NULL_VOID(rsNode_);
|
||||
CHECK_NULL_VOID(property);
|
||||
std::shared_ptr<RSNodeModifierImpl> modifier =
|
||||
std::static_pointer_cast<RSNodeModifierImpl>(property->GetModifyImpl());
|
||||
RemoveModifier(modifier);
|
||||
}
|
||||
|
||||
void RosenRenderContext::InitEventClickEffect()
|
||||
{
|
||||
if (touchListener_) {
|
||||
|
@ -271,6 +271,7 @@ public:
|
||||
#endif
|
||||
void SetActualForegroundColor(const Color& value) override;
|
||||
void AttachNodeAnimatableProperty(RefPtr<NodeAnimatablePropertyBase> property) override;
|
||||
void DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase>& property) override;
|
||||
|
||||
void RegisterSharedTransition(const RefPtr<RenderContext>& other) override;
|
||||
void UnregisterSharedTransition(const RefPtr<RenderContext>& other) override;
|
||||
|
@ -324,6 +324,8 @@ public:
|
||||
|
||||
virtual void AttachNodeAnimatableProperty(RefPtr<NodeAnimatablePropertyBase> modifier) {};
|
||||
|
||||
virtual void DetachNodeAnimatableProperty(const RefPtr<NodeAnimatablePropertyBase>& modifier) {};
|
||||
|
||||
virtual void PaintAccessibilityFocus() {};
|
||||
|
||||
virtual void ClearAccessibilityFocus() {};
|
||||
|
@ -651,8 +651,6 @@ HWTEST_F(StageTestNg, PagePatternTest005, TestSize.Level1)
|
||||
* @tc.steps: step6.change some params ,recall TriggerPageTransition and StopPageTransition.
|
||||
* @tc.expected: The FLAG_FUNC call times meets expectation.
|
||||
*/
|
||||
ASSERT_NE(pattern->controller_, nullptr);
|
||||
pattern->controller_->Stop();
|
||||
auto innerEffect = pattern->FindPageTransitionEffect(PageTransitionType::ENTER_POP);
|
||||
ASSERT_NE(effect, nullptr);
|
||||
innerEffect->animationOption_.delay = -1;
|
||||
|
Loading…
Reference in New Issue
Block a user