Skip to content

Commit ee38431

Browse files
authored
Merge pull request #3 from skellock/fix-android-cache-invalidation
Invalidates the Android view cache after each shot.
2 parents 04b319a + 2a42744 commit ee38431

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@ private void captureView (View view, OutputStream os) {
9494
if (w <= 0 || h <= 0) {
9595
throw new RuntimeException("Impossible to snapshot the view: view is invalid");
9696
}
97+
if (!view.isDrawingCacheEnabled())
98+
view.setDrawingCacheEnabled(true);
99+
97100
Bitmap bitmap = view.getDrawingCache();
98-
if (bitmap == null)
99-
view.setDrawingCacheEnabled(true);
100-
bitmap = view.getDrawingCache();
101+
101102
if (width != null && height != null && (width != w || height != h)) {
102103
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
103104
}
104105
if (bitmap == null) {
105106
throw new RuntimeException("Impossible to snapshot the view");
106107
}
107108
bitmap.compress(format, (int)(100.0 * quality), os);
109+
view.setDrawingCacheEnabled(false);
108110
}
109111
}

0 commit comments

Comments
 (0)