B4J Tutorial [ABMaterial] new section and page nav feature (3.02)

ABMaterial 3.02 Maintenance Release will have a new feature, especially useful for 'one page' apps/websites to navigate. It intruduces 'sections' within a page. A section is a logical grouping of rows, which can have its own background and a new extra navigation method/menu.

Sections must be declared at the BuildPage() stage, and are typically created right after the page.BuildGrid() method.

First, let me show you how it works and then I'll explain how this is archieved with just 12 lines of code!

Video:

Code (creating the Theme):
B4X:
theme.Page.AddSection("section1", ABM.COLOR_BLACK, "", ABM.COLOR_WHITE, "")
theme.Page.AddSection("section2", ABM.COLOR_BLACK, "", ABM.COLOR_BROWN, ABM.INTENSITY_LIGHTEN4)
theme.Page.AddSection("section3", ABM.COLOR_WHITE, "", ABM.COLOR_BLUE, ABM.INTENSITY_LIGHTEN3)
theme.Page.AddSection("section4", ABM.COLOR_WHITE, "", ABM.COLOR_GREY, ABM.INTENSITY_DARKEN3)

Code (Adding the sections & the navigation)
B4X:
page.CreateSection("section1", 1,1,ABM.COLOR_WHITE, "", "", "", "","calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL,"Section1")
page.SetSectionNavigation("section1", "section2", "Go to Section 2", ABM.SECTION_BUTTONTYPE_DOWN, "section1", "Section 1" )
page.CreateSection("section2", 2,2,ABM.COLOR_GREEN, "", "../images/bg-1.jpg", ABM.CONTAINERIMAGE_REPEAT_NOREPEAT, ABM.CONTAINERIMAGE_POSITION_COVER, "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL, "Section2")
page.SetSectionNavigation("section2", "section3", "Go to Section 3", ABM.SECTION_BUTTONTYPE_DOWN, "section2", "Section 2")
page.CreateSection("section3", 3,3,ABM.COLOR_BLUE, "", "", "", "", "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL,"Section3")
page.SetSectionNavigation("section3", "section4", "Go to Section 4", ABM.SECTION_BUTTONTYPE_DOWN, "section3", "Section 3")
page.CreateSection("section4", 4,4,ABM.COLOR_BLACK, "", "", "", "", "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL, "Section4")
page.SetSectionNavigation("section4", "section1", "Back to Section 1", ABM.SECTION_BUTTONTYPE_UP, "section4", "Section 4")

In this example each section has only a height of 1 row (hence the from row 1 to row 1, from row 2 to row 2,...)

But, this can be any size, e.g. from row 5 to row 25. Something like:
B4X:
page.CreateSection("section5", 5,25,ABM.COLOR_BLACK, "", "", "", "", "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL, "Section4")

NOTE: Sections cannot be nested or overlapping!

The tricky part are the minHeight and scrollTop params. In the above examples, I'll set the minHeight to the browsers height, minus the height of the TopBar: "calc(100vh - 56px)".
For scrollTop, I've set it the the height of the TopBar so the top of the section is right under the navigation bar: 56

ABMaterial 3.02 Maintenance Release will go out in a couple of days to the donators with 25 bug fixes and implemented wishes.

Alain
 
Last edited:

clarionero

Active Member
Licensed User
Longtime User
Hi. When i define my sections height to 1 row, the page display right, but if i define sections with more rows then it give me an exception. My page and sections definitions are (the error is with first page.CreateSection statement, and i tested with diferent values):

B4X:
' create the page grid
   page.AddRowsM(NumAreas*NumLineasArea,False,0,0, "").AddCells12MP(12,0,0,0,0,"")
   page.BuildGrid 'IMPORTANT once you loaded the complete grid AND before you start adding components
   
   ' La definición del fondo y botones rapidos de cad sección
   page.CreateSection("section1", 1,5,ABM.COLOR_WHITE, "", "../fotografias/1.jpg", ABM.CONTAINERIMAGE_REPEAT_NOREPEAT, ABM.CONTAINERIMAGE_POSITION_COVER,"calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL,"Section1")
   page.SetSectionNavigation("section1", "section2", "Ir a Modelos", ABM.SECTION_BUTTONTYPE_DOWN, "section1", "Inicio de Página" )
   
   page.CreateSection("section2", 6,10,ABM.COLOR_GREY, ABM.INTENSITY_LIGHTEN5, "../fotografias/13.jpg", ABM.CONTAINERIMAGE_REPEAT_NOREPEAT, ABM.CONTAINERIMAGE_POSITION_COVER, "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL, "Section2")
   page.SetSectionNavigation("section2", "section3", "Ir a Fotógrafos", ABM.SECTION_BUTTONTYPE_DOWN, "section2", "Modelos")
   
   page.CreateSection("section3", 11,15,ABM.COLOR_WHITE, "", "../fotografias/10.jpg", ABM.CONTAINERIMAGE_REPEAT_NOREPEAT, ABM.CONTAINERIMAGE_POSITION_COVER, "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL,"Section3")
   page.SetSectionNavigation("section3", "section4", "Ir a Otros Profesionales", ABM.SECTION_BUTTONTYPE_DOWN, "section3", "Fotógrafos")
   
   page.CreateSection("section4", 16,20,ABM.COLOR_GREY, ABM.INTENSITY_LIGHTEN5, "../fotografias/5.jpg", ABM.CONTAINERIMAGE_REPEAT_NOREPEAT, ABM.CONTAINERIMAGE_POSITION_COVER, "calc(100vh - 56px)", 56, 500, ABM.VISIBILITY_ALL, "Section4")
   page.SetSectionNavigation("section4", "section1", "Volver a inicio de la página", ABM.SECTION_BUTTONTYPE_UP, "section4", "Otros Profesionales")

And the exception is

Analysing data from B4J source files... (2/2)
java.lang.NullPointerException
at com.ab.abmaterial.ABMPage.BuildBody(Unknown Source)
at com.ab.abmaterial.ABMPage.Build(Unknown Source)
at com.ab.abmaterial.ABMPage.WritePageToDiskPerTheme(Unknown Source)
at com.ab.abmaterial.ABMPage.WritePageToDisk(Unknown Source)
at com.ab.abmaterial.ABMaterial.WritePageToDisk(Unknown Source)
at com.clarionero.b4x.dirphoto.abmapplication._addpage(abmapplication.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:614)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:231)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:90)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:77)
at com.clarionero.b4x.dirphoto.main.main(main.java:29)
Building core.min.css...

Where is my error?

Thank you

Rubén
 

clarionero

Active Member
Licensed User
Longtime User
hi Alain. Sorry.

NumAreas = 4
NumLineasArea = 5

But if i change the variables by number 20 the error is same.

Edit: The ABMaterial version is 3.20.

Rubén
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…