Popover size

Looking to replace a complex mobilemessagebox with a popover containing various buttons.
I downloaded the Xojo popover example, and their popovers can be either a screen or container.
When they appear, they are pretty sizable - certainly different to the size at design time.

In my own project, I created a dummy screen with a few buttons, and tried the sample code.
However, I just get a tiny popover , and I see no way to control its size.
Does this only work properly on iPhone / portrait layouts?

image

I have never got popover to work as expected on iOS.

Instead, I use a modal screen containing a table of items to select from.
Or a more complex screen such as this:

1 Like

As an alternative, if you have iOSKit in your project, you can use action sheets:

using UIKit

  alertController = UIAlertController.AlertControllerWithTitleMessagePreferredStyle(me.Items(index).title, "", UIAlertController.UIAlertControllerStyle.ActionSheet)


dim alert as UIAlertAction

//actions is a text array containing the name of each action
Dim actions() as Text
actions.Add "Action 1"
actions.Add "Action 2"

For each action as text in actions
  
  alert = UIAlertAction.ActionWithTitleStyleHandler(action, UIAlertAction.UIAlertActionStyle.Default, WeakAddressOf alertHandler)
  alertController.AddAction alert
  
  
Next

//Cancel button
alert = UIAlertAction.ActionWithTitleStyleHandler("Cancel", UIAlertAction.UIAlertActionStyle.Cancel, WeakAddressOf alertHandler)
alertController.AddAction alert

if isIPad then
  Dim x As Integer = (me.Width/(me.items.LastIndex+1) * index) //me is the MobileUIControl that was clicked to display the popover
  alertController.PresentInPopover(self, me, new Foundation.NSRect(x, 0, me.Width, me.Height))
Else
  alertController.PresentInView(self)
end if

with isiPad method

Private Function isIPad() As Boolean
  
  #if TargetIOS
    Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
    declare function currentDevice_ lib "UIKit" selector "currentDevice" (clsRef as ptr) as ptr
    declare function model_ lib "UIKit" selector "model" (obj_id as ptr) as CFStringRef
    dim model as Text = model_(currentDevice_(NSClassFromString("UIDevice")))
    dim isPad as boolean = model.BeginsWith("iPad")
    
    
    
    Return isPad
    
  #endif
End Function

And alertHandler method

Private Sub alertHandler(sender as UIKit.UIAlertAction)
  
  //Cancel button
  if sender.title = "Cancel" then

    Return
  end if
  
  Dim action As Text = sender.title
  
  //Do something depending on action
...
  
  
End Sub

This is how it looks on MacOS

On iPhone:

And on iPad:

Interesting. I’ll experiment.
Popover is disappointing/half baked.

1 Like

Completely agree!

1 Like

Hi Jeremie, how can you solve this with a modal screen so that it only half covers the screen below and can still be resized? Unfortunately, I have only ever been able to solve this with full modal screens. Thank you - would help me a lot.

I’ve just tested a container as a child of the window.

I make it visible or not as I need, and I disable the area behind it, (as for some reason the unused area of the container allows pointer actions to propagate through.)
I’m sure there is a better solution using the modal window approach, but Im still playing at the moment

Yes, using iOSDesignExtensions, MobileScreen.ShowSheetXC method:

Var s as New ScreenSheet //the modal screen you want to show

Var showGrabber as Boolean = True
Var animate As Boolean = True
Var radius as Double = 18
s.ShowSheetXC(self, ViewExtensionsXC.UISheetPresentationControllerDetent.medium_large, showGrabber, animate, radius)

And it will display a half sized popup like this, that can be “maximised” by dragging it to the top.

When using ShowSheetXC, MobileScreen.Close does not work as expected because the screen wasn’t added in Xojo’s screen hierarchy.

Here is an example project with the workaround.

iOSDesignExtensions ShowSheet Example.xojo_binary_project.zip (9.1 KB)

Hi Jeremy, that really helps me a lot, I’ll try it out soon. I’ve been looking for a solution like this for a long time and didn’t know exactly how to implement it.

Thanks again for your time and the example attached.

1 Like

Hi Jeremie, thank you for this solution. Works perfectly. On StackOverflow I read that it is also possible to set custom detents, but I have no idea how to implement this. Could you add this to your example?

Link please :slight_smile: