Skip to content

Commit 9a613da

Browse files
committed
better error precision when you can't snapshot things (like react-native-video)
1 parent 7e7dedc commit 9a613da

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ios/RNViewShot.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,22 @@ - (NSDictionary *)constantsToExport
9494
}
9595
UIGraphicsBeginImageContextWithOptions(size, NO, 0);
9696
success = [rendered drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
97+
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
98+
UIGraphicsEndImageContext();
99+
97100
if (snapshotContentContainer) {
98101
// Restore scroll & frame
99102
scrollView.contentOffset = savedContentOffset;
100103
scrollView.frame = savedFrame;
101104
}
102-
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
103-
UIGraphicsEndImageContext();
104105

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);
107113
return;
108114
}
109115

0 commit comments

Comments
 (0)