ios-jsc icon indicating copy to clipboard operation
ios-jsc copied to clipboard

Add setModalInPresentation method for UINavigationController

Open jdnichollsc opened this issue 5 years ago • 4 comments

I'm trying to call this method from a plugin but it throws an exception:

const safariHackVC = UINavigationController.alloc().initWithRootViewController(self.safariVC);
safariHackVC.presentationController.delegate = self;
if (ios.MajorVersion >= 13) {
  safariHackVC['setModalInPresentation'](true); //throws an exception
}

Any help is really appreciated 👍

jdnichollsc avatar Nov 14 '19 00:11 jdnichollsc

Maybe this property is related with that new method https://developer.apple.com/documentation/uikit/uiviewcontroller/3229894-modalinpresentation?language=objc Check some examples:

  • https://github.com/proyecto26/react-native-inappbrowser/blob/master/ios/RNInAppBrowser.m#L220
  • https://github.com/AzureAD/microsoft-authentication-library-common-for-objc/blob/051d106abf51faa0831ab8b6858970abe7a9f1fc/IdentityCore/src/webview/embeddedWebview/ui/ios/MSIDWebviewUIController.m#L125

Thanks in advance! :)

jdnichollsc avatar Nov 14 '19 16:11 jdnichollsc

Hi @jdnichollsc, you are correct. The native Objective-C code that you've found directly calls the setter function of the property. In NativeScript however, the setter is not exposed and what you need to do is use the property itself like this: safariHackVC.modalInPresentation = true;

mbektchiev avatar Nov 18 '19 07:11 mbektchiev

Yes sir, in the meantime I'm using that property but it looks not working as expected (I can close the modal with a swipe back gesture) https://github.com/proyecto26/nativescript-inappbrowser/blob/master/src/InAppBrowser.ios.ts#L138

jdnichollsc avatar Nov 18 '19 15:11 jdnichollsc

To see whether the problem is with the iOS runtime and the setter, I can suggest that you log the property before and after setting it. I believe that it should be correctly assigned.

Are you sure that the swipe back gesture should be disabled with modalInPresentation? From its description (When you set it to YES, UIKit ignores events outside the view controller's bounds and prevents the interactive dismissal of the view controller while it is onscreen.) I'm not quite sure I'd anticipate this...

mbektchiev avatar Nov 19 '19 12:11 mbektchiev