From 4b4455f8278d8d728d69d84804bbe8fed9b3d972 Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Wed, 24 Feb 2016 09:05:28 -0800 Subject: [PATCH] Removed 'screen' option from snapshot API Summary:Unfortunately the 'screen' option in the `UIManager.takeSnapshot` API appears to work only on the iOS simulator, not on an actual device. This diff removes the 'screen' option until a solution can be found that works on the device. (Taking a snapshot of the window still works fine - it just won't include the status bar, etc.) Reviewed By: javache Differential Revision: D2971091 fb-gh-sync-id: 026b9d4eb2f59f686f58c18a16381ff325df612b shipit-source-id: 026b9d4eb2f59f686f58c18a16381ff325df612b --- Examples/UIExplorer/SnapshotExample.js | 2 +- Libraries/Utilities/UIManager.js | 10 +++++----- React/Modules/RCTUIManager.m | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Examples/UIExplorer/SnapshotExample.js b/Examples/UIExplorer/SnapshotExample.js index f5384c666..d843acee8 100644 --- a/Examples/UIExplorer/SnapshotExample.js +++ b/Examples/UIExplorer/SnapshotExample.js @@ -44,7 +44,7 @@ var ScreenshotExample = React.createClass({ takeScreenshot() { UIManager - .takeSnapshot('screen', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options + .takeSnapshot('window', {format: 'jpeg', quality: 0.8}) // See UIManager.js for options .then((uri) => this.setState({uri})) .catch((error) => alert(error)); } diff --git a/Libraries/Utilities/UIManager.js b/Libraries/Utilities/UIManager.js index 068087a8f..efd8ce5b0 100644 --- a/Libraries/Utilities/UIManager.js +++ b/Libraries/Utilities/UIManager.js @@ -50,8 +50,8 @@ const _takeSnapshot = UIManager.takeSnapshot; * will be stored in a temporary file that will only exist for as long as the * app is running. * - * The `view` argument can be the literal string `screen` or `window` if you - * want to capture the entire screen, or it can be a reference to a specific + * The `view` argument can be the literal string `window` if you want to + * capture the entire window, or it can be a reference to a specific * React Native component. * * The `options` argument may include: @@ -63,7 +63,7 @@ const _takeSnapshot = UIManager.takeSnapshot; * @platform ios */ UIManager.takeSnapshot = async function( - view ?: 'screen' | 'window' | ReactElement | number, + view ?: 'window' | ReactElement | number, options ?: { width ?: number; height ?: number; @@ -75,8 +75,8 @@ UIManager.takeSnapshot = async function( console.warn('UIManager.takeSnapshot is not available on this platform'); return; } - if (typeof view !== 'number' && view !== 'screen' && view !== 'window') { - view = findNodeHandle(view) || 'screen'; + if (typeof view !== 'number' && view !== 'window') { + view = findNodeHandle(view) || 'window'; } return _takeSnapshot(view, options); }; diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 1186ac027..dd7d53448 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1191,9 +1191,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(id /* NSString or NSNumber */)target // Get view UIView *view; - if (target == nil || [target isEqual:@"screen"]) { - view = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES]; - } else if ([target isEqual:@"window"]) { + if (target == nil || [target isEqual:@"window"]) { view = RCTKeyWindow(); } else if ([target isKindOfClass:[NSNumber class]]) { view = viewRegistry[target]; @@ -1217,7 +1215,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(id /* NSString or NSNumber */)target UIGraphicsEndImageContext(); if (!success || !image) { - reject(RCTErrorUnspecified, @"Failed to capture view snapshot", nil); + reject(RCTErrorUnspecified, @"Failed to capture view snapshot.", nil); return; }