Skip to content

Commit fec06c0

Browse files
committed
Keep the iOS pick open when a swipe down is cancelled
presentationControllerWillDismiss finished the request right away, but UIKit calls it as soon as the user starts pulling the sheet down, even if they let it spring back. The pick completed as cancelled while the picker stayed open, and the files selected afterwards were dropped because the request had already been cleared. Wait for the dismissal transition to end and only finish the request if it was not cancelled. A completed dismissal, including the fast swipe from vicajilau#2021 that may never reach presentationControllerDidDismiss, still finishes the request. Without a transition coordinator it finishes right away, as before. Bumps file_picker_darwin to 2.1.4. Fixes vicajilau#2243
1 parent 9f53465 commit fec06c0

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

‎packages/file_picker_darwin/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.4
2+
3+
- Fixed a partial swipe down on the iOS picker sheet completing the pick as cancelled while the picker stayed open, which dropped the files selected afterwards. [#2243](https://github.com/vicajilau/flutter_file_picker/issues/2243)
4+
15
## 2.1.3
26

37
- Fixed `saveFile()` on macOS appending a second, lowercased extension to file names with a custom extension, such as `j.nme2mbAllpreset`. [#2238](https://github.com/vicajilau/flutter_file_picker/issues/2238)

‎packages/file_picker_darwin/darwin/file_picker_darwin/Sources/file_picker_darwin/IOSFilePickerHandler.swift‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,27 @@ final class IOSFilePickerHandler: NSObject,
189189
finishCurrentRequest(nil)
190190
}
191191

192-
func presentationControllerWillDismiss(_: UIPresentationController) {
193-
finishCurrentRequest(nil)
192+
func presentationControllerWillDismiss(
193+
_ presentationController: UIPresentationController
194+
) {
195+
// UIKit calls this as soon as the user starts pulling the sheet down,
196+
// even if they let it spring back, so finishing right away would
197+
// report a cancellation while the picker is still open and drop the
198+
// later selection. Wait for the dismissal to end instead. A fast swipe
199+
// may never reach presentationControllerDidDismiss, so this still
200+
// finishes the request when the dismissal completes.
201+
guard
202+
let coordinator = presentationController.presentedViewController
203+
.transitionCoordinator
204+
else {
205+
finishCurrentRequest(nil)
206+
return
207+
}
208+
coordinator.animate(alongsideTransition: nil) { [weak self] context in
209+
if !context.isCancelled {
210+
self?.finishCurrentRequest(nil)
211+
}
212+
}
194213
}
195214

196215
func presentationControllerDidDismiss(

‎packages/file_picker_darwin/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: file_picker_darwin
22
description: Darwin (iOS and macOS) implementation of the file_picker plugin, supporting native file picking, saving, and directory selection.
3-
version: 2.1.3
3+
version: 2.1.4
44
homepage: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_darwin
55
repository: https://github.com/vicajilau/flutter_file_picker/tree/main/packages/file_picker_darwin
66
topics:

0 commit comments

Comments
 (0)