|
@@ -5,6 +5,7 @@
|
5
|
5
|
#import <React/UIView+React.h>
|
6
|
6
|
#import <React/RCTUtils.h>
|
7
|
7
|
#import <React/RCTConvert.h>
|
|
8
|
+#import <React/RCTScrollView.h>
|
8
|
9
|
#import <React/RCTUIManager.h>
|
9
|
10
|
#import <React/RCTBridge.h>
|
10
|
11
|
|
|
@@ -54,13 +55,36 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber *)target
|
54
|
55
|
CGSize size = [RCTConvert CGSize:options];
|
55
|
56
|
NSString *format = [RCTConvert NSString:options[@"format"] ?: @"png"];
|
56
|
57
|
NSString *result = [RCTConvert NSString:options[@"result"] ?: @"file"];
|
57
|
|
-
|
|
58
|
+ BOOL snapshotContentContainer = [RCTConvert BOOL:options[@"snapshotContentContainer"] ?: @"false"];
|
|
59
|
+
|
58
|
60
|
// Capture image
|
59
|
|
- if (size.width < 0.1 || size.height < 0.1) {
|
60
|
|
- size = view.bounds.size;
|
|
61
|
+ BOOL success;
|
|
62
|
+ if (snapshotContentContainer) {
|
|
63
|
+ if (![view isKindOfClass:[RCTScrollView class]]) {
|
|
64
|
+ reject(RCTErrorUnspecified, [NSString stringWithFormat:@"snapshotContentContainer can only be used on a RCTScrollView. instead got: %@", view], nil);
|
|
65
|
+ return;
|
|
66
|
+ }
|
|
67
|
+ RCTScrollView* rctScrollView = view;
|
|
68
|
+ UIScrollView* scrollView = rctScrollView.scrollView;
|
|
69
|
+ CGPoint savedContentOffset = scrollView.contentOffset;
|
|
70
|
+ CGRect savedFrame = scrollView.frame;
|
|
71
|
+ scrollView.contentOffset = CGPointZero;
|
|
72
|
+ scrollView.frame = CGRectMake(0, 0, scrollView.contentSize.width, scrollView.contentSize.height);
|
|
73
|
+ if (size.width < 0.1 || size.height < 0.1) {
|
|
74
|
+ size = scrollView.contentSize;
|
|
75
|
+ }
|
|
76
|
+ UIGraphicsBeginImageContextWithOptions(size, NO, 0);
|
|
77
|
+ success = [scrollView drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
|
|
78
|
+ scrollView.contentOffset = savedContentOffset;
|
|
79
|
+ scrollView.frame = savedFrame;
|
|
80
|
+ }
|
|
81
|
+ else {
|
|
82
|
+ if (size.width < 0.1 || size.height < 0.1) {
|
|
83
|
+ size = view.bounds.size;
|
|
84
|
+ }
|
|
85
|
+ UIGraphicsBeginImageContextWithOptions(size, NO, 0);
|
|
86
|
+ success = [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
|
61
|
87
|
}
|
62
|
|
- UIGraphicsBeginImageContextWithOptions(size, NO, 0);
|
63
|
|
- BOOL success = [view drawViewHierarchyInRect:(CGRect){CGPointZero, size} afterScreenUpdates:YES];
|
64
|
88
|
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
|
65
|
89
|
UIGraphicsEndImageContext();
|
66
|
90
|
|