Removed the fatal error for sheet presentation with non-nil popoverPresentationController without a sourceView. Now using the presenting's view controller view as a source view and the source rect is in its center.
Now it works like this with the styles demo app if I change the sourceView here to nil:
Why?
The example above from the demo app was causing a crash.
The fatal error is redundant and premature.
Redundant because UIKit already crashes with a pretty explanatory message anyway:
Premature because we're checking the source view at the point of initialisation but it might not be used. For example, on iPad with compact horizontal class (half screen, landscape, multitasking) even though the modalPresentationStyle of an UIAlertController created with preferred style actionSheet will be popover, the resulting presentation won't be a popover but a bottom sheet.
I understand that it's better to crash earlier if we know that accessing something at a later point will cause a crash but in this case we don't seem to be getting much from the crash. If we wanted to notify earlier about an API misuse we could make sourceView non optional parameter for the presentation style but that will make the API weird as you can show a sheet without a source rect anyway. Thus I'm adding a fallback for the popover anchor location to be the presenting's view centre.
What?
Removed the fatal error for sheet presentation with non-nil
popoverPresentationController
without a sourceView. Now using the presenting's view controller view as a source view and the source rect is in its center.Now it works like this with the styles demo app if I change the sourceView here to nil:
Why?
The example above from the demo app was causing a crash.
The fatal error is redundant and premature.
Redundant because UIKit already crashes with a pretty explanatory message anyway:
Premature because we're checking the source view at the point of initialisation but it might not be used. For example, on iPad with compact horizontal class (half screen, landscape, multitasking) even though the modalPresentationStyle of an UIAlertController created with preferred style
actionSheet
will bepopover
, the resulting presentation won't be a popover but a bottom sheet.I understand that it's better to crash earlier if we know that accessing something at a later point will cause a crash but in this case we don't seem to be getting much from the crash. If we wanted to notify earlier about an API misuse we could make
sourceView
non optional parameter for the presentation style but that will make the API weird as you can show a sheet without a source rect anyway. Thus I'm adding a fallback for the popover anchor location to be the presenting's view centre.