ソースを参照

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

Gaëtan Renaudeau 7 年 前
コミット
9a613da4aa
共有1 個のファイルを変更した10 個の追加4 個の削除を含む
  1. 10
    4
      ios/RNViewShot.m

+ 10
- 4
ios/RNViewShot.m ファイルの表示

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