Using invalidateChildInParent for API levels lower than 26. (flutter/engine#31533)

This commit is contained in:
Rulong Chen(陈汝龙)
2022-02-23 13:49:02 +08:00
committed by GitHub
parent 6ab745a914
commit 2ccc8c1af6
2 changed files with 22 additions and 0 deletions

View File

@@ -11,11 +11,13 @@ import android.graphics.BlendMode;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.os.Build;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.View;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
@@ -175,12 +177,20 @@ class PlatformViewWrapper extends FrameLayout {
return true;
}
/** Used on Android O+, {@link invalidateChildInParent} used for previous versions. */
@SuppressLint("NewApi")
@Override
public void onDescendantInvalidated(@NonNull View child, @NonNull View target) {
super.onDescendantInvalidated(child, target);
invalidate();
}
@Override
public ViewParent invalidateChildInParent(int[] location, Rect dirty) {
invalidate();
return super.invalidateChildInParent(location, dirty);
}
@Override
@SuppressLint("NewApi")
public void draw(Canvas canvas) {

View File

@@ -25,6 +25,18 @@ import org.robolectric.RuntimeEnvironment;
@TargetApi(31)
@RunWith(AndroidJUnit4.class)
public class PlatformViewWrapperTest {
@Test
public void invalidateChildInParent_callsInvalidate() {
final Context ctx = ApplicationProvider.getApplicationContext();
final PlatformViewWrapper wrapper = spy(new PlatformViewWrapper(ctx));
// Mock Android framework calls.
wrapper.invalidateChildInParent(null, null);
// Verify.
verify(wrapper, times(1)).invalidate();
}
@Test
public void setTexture_writesToBuffer() {
final Surface surface = mock(Surface.class);