From: Richard Huang Date: Tue, 24 Jun 2014 15:09:07 +0000 (+0100) Subject: Stop caching extra items while activating layout in ItemView X-Git-Tag: dali_1.0.0~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F87%2F24187%2F1;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git Stop caching extra items while activating layout in ItemView [problem] While activating new layout, ItemView tries to cache extra items. But this can block the event thread if it takes very long time to create these extra items. [solution] Only create visible items while activating layout, and cache extra items only when scrolling. Change-Id: I04eba3ae0d1f05c470d330dac52bd602a406df56 Signed-off-by: Adeel Kazmi --- diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp index 42254a9..14bd8fc 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.cpp @@ -404,7 +404,7 @@ ItemView::ItemView(ItemFactory& factory) mAnimateOvershootOff(false), mAnchoringEnabled(true), mAnchoringDuration(DEFAULT_ANCHORING_DURATION), - mRefreshIntervalLayoutPositions(DEFAULT_REFRESH_INTERVAL_LAYOUT_POSITIONS), + mRefreshIntervalLayoutPositions(0.0f), mRefreshOrderHint(true/*Refresh item 0 first*/), mMinimumSwipeSpeed(DEFAULT_MINIMUM_SWIPE_SPEED), mMinimumSwipeDistance(DEFAULT_MINIMUM_SWIPE_DISTANCE), @@ -456,7 +456,7 @@ void ItemView::OnInitialize() mMouseWheelEventFinishedTimer = Timer::New( MOUSE_WHEEL_EVENT_FINISHED_TIME_OUT ); mMouseWheelEventFinishedTimer.TickSignal().Connect( this, &ItemView::OnMouseWheelEventFinished ); - SetRefreshInterval(mRefreshIntervalLayoutPositions); + SetRefreshInterval(DEFAULT_REFRESH_INTERVAL_LAYOUT_POSITIONS); } ItemView::~ItemView() @@ -509,6 +509,8 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz { DALI_ASSERT_ALWAYS(layoutIndex < mLayouts.size()); + mRefreshEnabled = false; + Actor self = Self(); // The ItemView size should match the active layout size @@ -562,7 +564,7 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz } // Refresh the new layout - ItemRange range = GetItemRange(*mActiveLayout, targetSize, GetCurrentLayoutPosition(0), true/*reserve extra*/); + ItemRange range = GetItemRange(*mActiveLayout, targetSize, GetCurrentLayoutPosition(0), false/* don't reserve extra*/); AddActorsWithinRange( range, durationSeconds ); // Scroll to an appropriate layout position @@ -591,6 +593,7 @@ void ItemView::ActivateLayout(unsigned int layoutIndex, const Vector3& targetSiz mScrollAnimation = Animation::New(durationSeconds); mScrollAnimation.AnimateTo( Property( mScrollPositionObject, ScrollConnector::SCROLL_POSITION ), firstItemScrollPosition, AlphaFunctions::EaseOut ); mScrollAnimation.AnimateTo( Property(self, mPropertyPosition), GetScrollPosition(firstItemScrollPosition, targetSize), AlphaFunctions::EaseOut ); + mScrollAnimation.FinishedSignal().Connect(this, &ItemView::OnLayoutActivationScrollFinished); mScrollAnimation.Play(); } @@ -704,14 +707,17 @@ float ItemView::GetAnchoringDuration() const void ItemView::SetRefreshInterval(float intervalLayoutPositions) { - mRefreshIntervalLayoutPositions = intervalLayoutPositions; - - if(mRefreshNotification) + if(mRefreshIntervalLayoutPositions != intervalLayoutPositions) { - mScrollPositionObject.RemovePropertyNotification(mRefreshNotification); + mRefreshIntervalLayoutPositions = intervalLayoutPositions; + + if(mRefreshNotification) + { + mScrollPositionObject.RemovePropertyNotification(mRefreshNotification); + } + mRefreshNotification = mScrollPositionObject.AddPropertyNotification( ScrollConnector::SCROLL_POSITION, StepCondition(mRefreshIntervalLayoutPositions, 0.0f) ); + mRefreshNotification.NotifySignal().Connect( this, &ItemView::OnRefreshNotification ); } - mRefreshNotification = mScrollPositionObject.AddPropertyNotification( ScrollConnector::SCROLL_POSITION, StepCondition(mRefreshIntervalLayoutPositions, 0.0f) ); - mRefreshNotification.NotifySignal().Connect( this, &ItemView::OnRefreshNotification ); } float ItemView::GetRefreshInterval() const @@ -1121,6 +1127,7 @@ bool ItemView::OnMouseWheelEvent(const MouseWheelEvent& event) mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); self.SetProperty(mPropertyPosition, GetScrollPosition(firstItemScrollPosition, layoutSize)); mScrollStartedSignalV2.Emit(GetCurrentScrollPosition()); + mRefreshEnabled = true; } if (mMouseWheelEventFinishedTimer.IsRunning()) @@ -1347,6 +1354,8 @@ void ItemView::OnPan(PanGesture gesture) case Gesture::Started: // Fall through { mTotalPanDisplacement = Vector2::ZERO; + mScrollStartedSignalV2.Emit(GetCurrentScrollPosition()); + mRefreshEnabled = true; } case Gesture::Continuing: @@ -1363,7 +1372,6 @@ void ItemView::OnPan(PanGesture gesture) mScrollPositionObject.SetProperty( ScrollConnector::SCROLL_POSITION, firstItemScrollPosition ); self.SetProperty(mPropertyPosition, GetScrollPosition(firstItemScrollPosition, layoutSize)); - mScrollStartedSignalV2.Emit(GetCurrentScrollPosition()); mTotalPanDisplacement += gesture.displacement; mScrollOvershoot = layoutPositionDelta - firstItemScrollPosition; @@ -1504,6 +1512,12 @@ void ItemView::OnScrollFinished(Animation& source) mScrollOvershoot = 0.0f; } +void ItemView::OnLayoutActivationScrollFinished(Animation& source) +{ + mRefreshEnabled = true; + DoRefresh(GetCurrentLayoutPosition(0), true); +} + void ItemView::OnOvershootOnFinished(Animation& animation) { mAnimatingOvershootOn = false; @@ -1537,6 +1551,7 @@ void ItemView::ScrollToItem(unsigned int itemId, float durationSeconds) } mScrollStartedSignalV2.Emit(GetCurrentScrollPosition()); + mRefreshEnabled = true; } void ItemView::RemoveAnimation(Animation& animation) @@ -1668,6 +1683,7 @@ void ItemView::ScrollTo(const Vector3& position, float duration) } mScrollStartedSignalV2.Emit(GetCurrentScrollPosition()); + mRefreshEnabled = true; } void ItemView::SetOvershootEffectColor( const Vector4& color ) diff --git a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h index 76a0c26..1f33626 100644 --- a/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h +++ b/base/dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h @@ -477,6 +477,12 @@ private: void OnScrollFinished(Animation& animation); /** + * Callback from layout activation scroll animations + * @param[in] animation The scroll-animation which has finished. + */ + void OnLayoutActivationScrollFinished(Animation& animation); + + /** * Called by animation system when overshoot has finished animating to maximum (either -1.0f or 1.0f) * * @param[in] animation the animation that has finished