Browse Source

better error precision when you can't snapshot things (like react-native-video)

Gaëtan Renaudeau 7 years ago
parent
commit
9a613da4aa
1 changed files with 10 additions and 4 deletions
  1. 10
    4
      ios/RNViewShot.m

+ 10
- 4
ios/RNViewShot.m View File

@@ -94,16 +94,22 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)target
94 94
     }
95 95
     UIGraphicsBeginImageContextWithOptions(size, NO, 0);
96 96
     success = [rendered drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
97
+    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
98
+    UIGraphicsEndImageContext();
99
+    
97 100
     if (snapshotContentContainer) {
98 101
       // Restore scroll & frame
99 102
       scrollView.contentOffset = savedContentOffset;
100 103
       scrollView.frame = savedFrame;
101 104
     }
102
-    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
103
-    UIGraphicsEndImageContext();
104 105
     
105
-    if (!success || !image) {
106
-      reject(RCTErrorUnspecified, @"Failed to capture view snapshot", nil);
106
+    if (!success) {
107
+      reject(RCTErrorUnspecified, @"The view cannot be captured. drawViewHierarchyInRect was not successful. This is a potential technical or security limitation.", nil);
108
+      return;
109
+    }
110
+
111
+    if (!image) {
112
+      reject(RCTErrorUnspecified, @"Failed to capture view snapshot. UIGraphicsGetImageFromCurrentImageContext() returned nil!", nil);
107 113
       return;
108 114
     }
109 115