Browse Source

Merge pull request #3 from skellock/fix-android-cache-invalidation

Invalidates the Android view cache after each shot.
Gaëtan Renaudeau 8 years ago
parent
commit
ee3843166f
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java

+ 5
- 3
android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java View File

@@ -94,10 +94,11 @@ public class ViewShot implements UIBlock {
94 94
         if (w <= 0 || h <= 0) {
95 95
             throw new RuntimeException("Impossible to snapshot the view: view is invalid");
96 96
         }
97
+        if (!view.isDrawingCacheEnabled())
98
+          view.setDrawingCacheEnabled(true);
99
+
97 100
         Bitmap bitmap = view.getDrawingCache();
98
-        if (bitmap == null)
99
-            view.setDrawingCacheEnabled(true);
100
-        bitmap = view.getDrawingCache();
101
+
101 102
         if (width != null && height != null && (width != w || height != h)) {
102 103
             bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
103 104
         }
@@ -105,5 +106,6 @@ public class ViewShot implements UIBlock {
105 106
             throw new RuntimeException("Impossible to snapshot the view");
106 107
         }
107 108
         bitmap.compress(format, (int)(100.0 * quality), os);
109
+        view.setDrawingCacheEnabled(false);
108 110
     }
109 111
 }