B4J Question [BANano] Custom View Creation Best Practises / Tips

Mashiane

Expert
Licensed User
Longtime User
Hi there

What are the best practices / tips available for one when creating BANano custom views?

I usually use this approach

1. Each component has a ParentID property, this means I can place it anywhere in the abstract designer, if a parent id is specified, it will associate this to mTarget. If no ParentID is specified, the default existing approach done by BANano is followed.
2. I execute a BANano.Exists on the new element using the custom view name, if the name exists, its assigned to mElement, if not, an append to mTarget is done and mElement assigned.
3. Styling the component is done *after* it has been added or retrieved to the DOM and not before, this takes care of RunTime changes to be made where possible.

Example Code

B4X:
'does the parent exist
if mParentID <> "" then
        If BANano.Exists($"#${mParentID}"$) = False Then
            BANano.Throw($"ComponentName.Initialize: '${mParentID}' parent does not exist!"$)
            Return
        else
             mTarget.Initialize($"#${mParentID}"$)
        End If
end if

'does the component exists
If BANano.Exists($"#${mName}"$) Then
     mElement.Initialize($"#${mName}"$)
Else
      mElement = mTarget.Append($"[BANCLEAN]
            <div id="${mName}" class="card bg-base-100"></div>"$).Get($"#${mName}"$)
end if
mElement.AddClass("xxx")
mElement.SetStyle(???)

I'm trying to establish possible pitfalls with this approach and what I need to improve. Any advise is welcome please.

Thanks in advance.
 
Top