Snapshot to use key window size if possible

Summary:
Use the application key window bounds if possible.
In the case where the application is not using the entire screen,
like in Split View on an iPad, the running application is
not using the entire screen thus the snapshot stretches to
fill the screen size which is incorrect.

Reviewed By: LukeDefeo

Differential Revision: D47793033

fbshipit-source-id: d6c7932d35bad13752713772d078f94bad530b09
This commit is contained in:
Lorenzo Blasa
2023-07-26 04:24:07 -07:00
committed by Facebook GitHub Bot
parent f854e9f3f3
commit aba50889f2

View File

@@ -25,6 +25,16 @@ UIImage* UIDViewSnapshot(UIView* view) {
UIImage* UIDApplicationSnapshot(UIApplication* application, NSArray* windows) { UIImage* UIDApplicationSnapshot(UIApplication* application, NSArray* windows) {
CGSize size = [UIScreen mainScreen].bounds.size; CGSize size = [UIScreen mainScreen].bounds.size;
// Use the application key window bounds if possible.
// In the case where the application is not using the entire screen,
// like in Split View on an iPad, the running application is
// not using the entire screen thus the snapshot stretches to
// fill the screen size which is incorrect.
if (application.keyWindow) {
size = application.keyWindow.bounds.size;
}
UIGraphicsImageRenderer* renderer = UIGraphicsImageRenderer* renderer =
[[UIGraphicsImageRenderer alloc] initWithSize:size]; [[UIGraphicsImageRenderer alloc] initWithSize:size];