summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2022-03-04 14:29:27 +0100
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2022-03-05 01:01:34 +0100
commitbb30beb72642bf7c33f502f81e0dc7f4951ba8ec (patch)
treee483a9d6dc30614d6027d5f819c80c025aa4b946 /src/plugins/platforms/ios
parentbf6d313ec89400b82407d7690ff7b0e6098ff486 (diff)
QIOSFileDialog/QIOSDocumentPickerController - handle dismissed view controller
When we use a native view controller for selecting documents, we have two methods to implement from UIDocumentPickerDelegate (a file was selected or the selection was cancelled). Unfortunately, swiping a view away was not handled, so neither 'accept' nor 'reject' was called. Depending on the classes using QIOSFileDialog, this may leave them in some incorrect state, not knowing that they are 'closed' anyway. As suggested by Tor Arne, the solution is to implement UIAdaptivePresentationControllerDelegate's method, namely -presentationControllerDidDismiss:, which never gets called if the controller was dismissed programatically (the case of accept/reject). Pick-to: 6.3 6.2 5.15 Fixes: QTBUG-93505 Change-Id: I28404aa280465ef8eb0f5c26c8c2e4e4a6c66641 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qiosdocumentpickercontroller.h4
-rw-r--r--src/plugins/platforms/ios/qiosdocumentpickercontroller.mm15
2 files changed, 18 insertions, 1 deletions
diff --git a/src/plugins/platforms/ios/qiosdocumentpickercontroller.h b/src/plugins/platforms/ios/qiosdocumentpickercontroller.h
index dba6f24fc5..2fe3c9e382 100644
--- a/src/plugins/platforms/ios/qiosdocumentpickercontroller.h
+++ b/src/plugins/platforms/ios/qiosdocumentpickercontroller.h
@@ -41,6 +41,8 @@
#include "qiosfiledialog.h"
-@interface QIOSDocumentPickerController : UIDocumentPickerViewController <UIDocumentPickerDelegate, UINavigationControllerDelegate>
+@interface QIOSDocumentPickerController : UIDocumentPickerViewController <UIDocumentPickerDelegate,
+ UINavigationControllerDelegate,
+ UIAdaptivePresentationControllerDelegate>
- (instancetype)initWithQIOSFileDialog:(QIOSFileDialog *)fileDialog;
@end
diff --git a/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm b/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
index 476480c488..fcf5e104bd 100644
--- a/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
+++ b/src/plugins/platforms/ios/qiosdocumentpickercontroller.mm
@@ -72,6 +72,7 @@
m_fileDialog = fileDialog;
self.modalPresentationStyle = UIModalPresentationFormSheet;
self.delegate = self;
+ self.presentationController.delegate = self;
if (m_fileDialog->options()->fileMode() == QFileDialogOptions::ExistingFiles)
self.allowsMultipleSelection = YES;
@@ -100,4 +101,18 @@
emit m_fileDialog->reject();
}
+- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
+{
+ Q_UNUSED(presentationController);
+
+ // "Called on the delegate when the user has taken action to dismiss the
+ // presentation successfully, after all animations are finished.
+ // This is not called if the presentation is dismissed programatically."
+
+ // So if document picker's view was dismissed, for example by swiping it away,
+ // we got this method called. But not if the dialog was cancelled or a file
+ // was selected.
+ emit m_fileDialog->reject();
+}
+
@end