I haven't performed a deep level of searching to see if this already exists, but I figured I would ask here in case someone knows:
Is there code/tool that would allow me to take layouts and convert them into JSON for dynamically loading them at runtime from a server?
I am trying to build a dynamically configurable UI in the app which would be fed from a server that also includes control events that would also need to be handled at runtime vs compiled, and I Was wondering if this is possible or if it was done already. I would like to do something such as JSON instead of just passing a BAL file down from the server because the goal is to eventually use the same layout data and parse it in Node/React to render out a similar UI to keep things cross-platform.
Edit: Just saw BalConverter and its had a lot of updates, I might be able to use that to be able to bring in JSON, and run it in the LoadLayout function to at least use the layout engine which responds to scaling, anchors, etc.
It is however problematic to load dynamic layout files. During compilation the compiler expects to find the layout files and it reads their headers.
And secondly the layouts are loaded from File.DirAssets, which is read-only.
In the current version - no, because of the input folder being limited to File.DirAssets. This can of course be more flexible in the future, however it will require some additional changes as the compiler expects the layouts to be available during compilation.
You can create an empty layout and then you can do the following:
You can get Root panel dimensions (B4XPages) and have a json file you will create from a B4J app to be downloaded from your server. The json file will be a JSON array of JSON objects. Each JSON object will have six keys: type, name, top, left, width, height. The last four will be fractions in the range of values 0 to 1 which will be multiplied with Root.Width and Root.Height in order to get position and dimensions of each view. Then you will create the environment adding the views and associate the tag of each view with name which will be a value you will check to execute the apropriate code. For XUI views add the tag in {XUIView}.mBase.Tag because their tag represents the classes themselves.