Skip to content

Commit 55d345c

Browse files
Make Code More Efficient
As pointed out by Zoontek, there is a function to find the top view controller in React Native. Importing that function, and then updated the topViewController to use that function.
1 parent 2a25f5f commit 55d345c

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

ios/PhotoLibrary/RNPermissionHandlerPhotoLibrary.m

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "RNPermissionHandlerPhotoLibrary.h"
2+
#import <React/RCTUtils.h>
23

34
@import Photos;
45
@import PhotosUI;
@@ -57,15 +58,7 @@ - (void)openLimitedPhotoLibraryPickerWithResolver:(RCTPromiseResolveBlock _Nonnu
5758
return reject(@"cannot_open_limited_picker", @"Photo library permission isn't limited", nil);
5859
}
5960

60-
UIViewController* topViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
61-
UIViewController* presentedViewController = topViewController.presentedViewController;
62-
63-
while (presentedViewController = topViewController.presentedViewController) {
64-
topViewController = presentedViewController;
65-
presentedViewController = topViewController.presentedViewController;
66-
}
67-
68-
UIViewController* rootViewController = [[UIApplication sharedApplication].keyWindow rootViewController];
61+
UIViewController *topViewController = RCTPresentedViewController();
6962
[[PHPhotoLibrary sharedPhotoLibrary] presentLimitedLibraryPickerFromViewController:topViewController];
7063

7164
resolve(@(true));

0 commit comments

Comments
 (0)