viewpropertyanimator's invalidate is OK

This commit is contained in:
houzh 2024-01-31 10:16:31 +08:00
parent 02e055009f
commit 76f0ecb49f
5 changed files with 19 additions and 10 deletions

View File

@ -4,11 +4,11 @@ void onClick(View&v){
ViewGroup*root=v.getParent()->getParent();
View*hello=root->findViewById(0x12345);
hello->setLayerType(View::LAYER_TYPE_SOFTWARE);
LOGD("click %d",v.getId());
LOGD("click %d tag=%p",v.getId(),v.getTag());
int* tag=(int*)v.getTag();
switch(v.getId()){
case 1:hello->animate().alpha(0.2f).setDuration(1000).start();break;
case 2:hello->animate().x(tag==0?-600:0).setDuration(1000).start();break;
case 1:hello->animate().alpha(tag==0?0.2f:1.f).setDuration(1000).start();break;
case 2:hello->animate().x((tag==0)?-600:0).setDuration(1000).start();break;
}
v.setTag((tag==0)?(void*)1:(void*)0);
}

View File

@ -104,9 +104,10 @@ void AnimatedImageDrawable::draw(Canvas& canvas){
if (nextDelay > 0) {
if (mRunnable == nullptr) {
mRunnable = [this](){
if(mStarting)
if(mStarting && mAnimatedImageState->mFrameCount){
invalidateSelf();
mCurrentFrame=(mCurrentFrame+1)%mAnimatedImageState->mFrameCount;
mCurrentFrame=(mCurrentFrame+1)%mAnimatedImageState->mFrameCount;
}
if(mCurrentFrame==mAnimatedImageState->mFrameCount-1){
mRepeated++;
mStarting = (mRepeated>=mRepeatCount);

View File

@ -1,4 +1,5 @@
#include <view/view.h>
#include <view/viewgroup.h>
#include <view/viewpropertyanimator.h>
#include "cdlog.h"
@ -96,9 +97,9 @@ ViewPropertyAnimator::ViewPropertyAnimator(View* view){
for (int i = 0; i < count; ++i) {
NameValuesHolder& values = valueList.at(i);
const float value = values.mFromValue + fraction * values.mDeltaValue;
if (values.mNameConstant == ALPHA) {
/*if (values.mNameConstant == ALPHA) {//must be setted in setValue
alphaHandled = mView->setAlphaNoInvalidation(value);
} else {
} else */{
setValue(values.mNameConstant, value);
}
}
@ -449,6 +450,11 @@ void ViewPropertyAnimator::animatePropertyBy(int constantName, float startValue,
void ViewPropertyAnimator::setValue(int propertyConstant, float value) {
View::TransformationInfo* info = mView->mTransformationInfo;
RenderNode* node = mView->mRenderNode;
Matrix matrix;
Rect rect;
node->getMatrix(matrix);
rect.set(mView->getLeft(),mView->getTop(),mView->getWidth(),mView->getHeight());
matrix.transform_rectangle((Cairo::RectangleInt&)rect);
switch (propertyConstant) {
case TRANSLATION_X: node->setTranslationX(value); break;
case TRANSLATION_Y: node->setTranslationY(value); break;
@ -466,6 +472,9 @@ void ViewPropertyAnimator::setValue(int propertyConstant, float value) {
node->setAlpha(value);
break;
}
rect.inflate(1,1);
if(mView->mParent)
mView->mParent->invalidate(rect);
}
float ViewPropertyAnimator::getValue(int propertyConstant)const{

View File

@ -504,7 +504,7 @@ void ImageView::invalidateDrawable(Drawable& dr){
void ImageView::setImageDrawable(Drawable*drawable){
if (mDrawable != drawable) {
//mResource = 0;
mResource.clear();
//mUri = null;
const int oldWidth = mDrawableWidth;
@ -533,7 +533,7 @@ void ImageView::setImageResource(const std::string& resId) {
// try to load the resource even if the resId hasn't changed.
const int oldWidth = mDrawableWidth;
const int oldHeight = mDrawableHeight;
if(mResource==resId)return;
updateDrawable(nullptr);
mResource = resId;
resolveUri();

View File

@ -513,7 +513,6 @@ void NumberPicker::computeScroll() {
} else {
invalidate();
}
}
View& NumberPicker::setEnabled(bool enabled) {