iOS Question Width of a Drawer

Cadenzo

Active Member
Licensed User
Longtime User
B4X:
NavControl.ShowPage(Page1)
   
Drawer.Initialize(Me, "Drawer", Page1.RootPanel, 300dip) 'Page1.RootPanel in B4i
Drawer.CenterPanel.LoadLayout("viewMain")
Drawer.LeftPanel.LoadLayout("viewMainLeft")
I want to adjust the Drawer width to the width of the screen. It looks not good on a iPad, if only 300dip. But before loading the layouts I can not get the screen with, not with "100%x" and not with "Page1.RootPanel.Width". But I have to initialize it before, not after.
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
See this video.

You need to wait for the resize event.


 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Thanks, this is, what I do in the resize event:
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
    Drawer.Resize(Width, Height)
End Sub
But I have to initialize the Drawer (and set the Drawer width) in Application_Start.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
I tried, but to reach the Resize event I have to load a layout. To load a layout I have to initialize the Drawer and to initialize the Drawer I have to tell the size of left panel. Than it seems to be read-only. ?
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
In my case I could solve it, because I show a logo for 500 ms and can take the size after. But is there another solution, without two times loading the layout file?

B4X:
Private Sub Application_Start
    Page1.Initialize("Page1")
    Page1.RootPanel.LoadLayout("viewStartlogo") 'first time load a layout
    NavControl.ShowPage(Page1)
    Sleep(500)
    ShowDrawer
End Sub

Private Sub ShowDrawer
    Drawer.Initialize(Me, "Drawer", Page1.RootPanel, GetIdealDrawerWidth) 'only possible, if allready size known
    Drawer.CenterPanel.LoadLayout("viewMain")
    Drawer.LeftPanel.LoadLayout("viewMainLeft")
    Dim bb As BarButton
    bb.InitializeBitmap(LoadBitmapResize(File.DirAssets, "hamburger.png", 32dip, 32dip, True), "Drawer")
    Page1.TopLeftButtons = Array(bb)
End Sub

Sub GetIdealDrawerWidth() As Int
    Dim iWidth As Int = Min(Page1.RootPanel.Width, Page1.RootPanel.Height) ' Min(100%x, 100%y) 'if in Landscape mode
    iWidth = iWidth - 40dip ' https://blog.sebastiano.dev/material-navigation-drawer-sizing/
    Dim iMaxWidth As Int = 320dip : If iWidth > 500dip Then iMaxWidth = 400dip 'but max 320dp or 400dp with tablets
    iWidth = Min(iWidth, iMaxWidth)
    If iWidth <= 0 Then iWidth = 300dip 'if something went wrong
    Return iWidth
End Sub
 
Last edited:
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
Create a new Default project
Replace Application_Start subroutine to
B4X:
    NavControl = Nav
    Page1.Initialize("Page1")
    '  Page1.RootPanel.LoadLayout("Page1") 
    NavControl.ShowPage (Page1)
    Wait For Page1_Resize (Width As Int, Height As Int)
After Wait For width/height, 100%x/100%y are known and you can create a drawer.

In Page1_Resize use Drawer.Resize.
 
Upvote 0

Cadenzo

Active Member
Licensed User
Longtime User
Thank you, I will try tomorrow. I thought, that the Resize event only fires, if a layout is already loaded.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…