mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 10:14:49 +00:00
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
This commit is contained in:
parent
f538032888
commit
4b4455f827
@ -44,7 +44,7 @@ var ScreenshotExample = React.createClass({
|
|||||||
|
|
||||||
takeScreenshot() {
|
takeScreenshot() {
|
||||||
UIManager
|
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}))
|
.then((uri) => this.setState({uri}))
|
||||||
.catch((error) => alert(error));
|
.catch((error) => alert(error));
|
||||||
}
|
}
|
||||||
|
@ -50,8 +50,8 @@ const _takeSnapshot = UIManager.takeSnapshot;
|
|||||||
* will be stored in a temporary file that will only exist for as long as the
|
* will be stored in a temporary file that will only exist for as long as the
|
||||||
* app is running.
|
* app is running.
|
||||||
*
|
*
|
||||||
* The `view` argument can be the literal string `screen` or `window` if you
|
* The `view` argument can be the literal string `window` if you want to
|
||||||
* want to capture the entire screen, or it can be a reference to a specific
|
* capture the entire window, or it can be a reference to a specific
|
||||||
* React Native component.
|
* React Native component.
|
||||||
*
|
*
|
||||||
* The `options` argument may include:
|
* The `options` argument may include:
|
||||||
@ -63,7 +63,7 @@ const _takeSnapshot = UIManager.takeSnapshot;
|
|||||||
* @platform ios
|
* @platform ios
|
||||||
*/
|
*/
|
||||||
UIManager.takeSnapshot = async function(
|
UIManager.takeSnapshot = async function(
|
||||||
view ?: 'screen' | 'window' | ReactElement | number,
|
view ?: 'window' | ReactElement | number,
|
||||||
options ?: {
|
options ?: {
|
||||||
width ?: number;
|
width ?: number;
|
||||||
height ?: number;
|
height ?: number;
|
||||||
@ -75,8 +75,8 @@ UIManager.takeSnapshot = async function(
|
|||||||
console.warn('UIManager.takeSnapshot is not available on this platform');
|
console.warn('UIManager.takeSnapshot is not available on this platform');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof view !== 'number' && view !== 'screen' && view !== 'window') {
|
if (typeof view !== 'number' && view !== 'window') {
|
||||||
view = findNodeHandle(view) || 'screen';
|
view = findNodeHandle(view) || 'window';
|
||||||
}
|
}
|
||||||
return _takeSnapshot(view, options);
|
return _takeSnapshot(view, options);
|
||||||
};
|
};
|
||||||
|
@ -1191,9 +1191,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(id /* NSString or NSNumber */)target
|
|||||||
|
|
||||||
// Get view
|
// Get view
|
||||||
UIView *view;
|
UIView *view;
|
||||||
if (target == nil || [target isEqual:@"screen"]) {
|
if (target == nil || [target isEqual:@"window"]) {
|
||||||
view = [[UIScreen mainScreen] snapshotViewAfterScreenUpdates:YES];
|
|
||||||
} else if ([target isEqual:@"window"]) {
|
|
||||||
view = RCTKeyWindow();
|
view = RCTKeyWindow();
|
||||||
} else if ([target isKindOfClass:[NSNumber class]]) {
|
} else if ([target isKindOfClass:[NSNumber class]]) {
|
||||||
view = viewRegistry[target];
|
view = viewRegistry[target];
|
||||||
@ -1217,7 +1215,7 @@ RCT_EXPORT_METHOD(takeSnapshot:(id /* NSString or NSNumber */)target
|
|||||||
UIGraphicsEndImageContext();
|
UIGraphicsEndImageContext();
|
||||||
|
|
||||||
if (!success || !image) {
|
if (!success || !image) {
|
||||||
reject(RCTErrorUnspecified, @"Failed to capture view snapshot", nil);
|
reject(RCTErrorUnspecified, @"Failed to capture view snapshot.", nil);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user