Quellcode durchsuchen

Invalidates the Android view cache after each shot.

Steve Kellock vor 8 Jahren
Ursprung
Commit
2a42744e73

+ 5
- 3
android/src/main/java/fr/greweb/reactnativeviewshot/ViewShot.java Datei anzeigen

@@ -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
 }