While working on one of the projects, we faced a need to dynamically build screens. Previously, all screen display configuration came in JSON because the screen was a constructor form. Further JSON got into our engine, which determined the display of fields in accordance with the type and parameters that were in JSON. The set of fields was fixed, and this functionality was sufficient until we faced a need for dynamics tied to the data content of some fields.
For example, it was necessary to enable the user to add an attachment only if he chose to send documents remotely. Or provide additional fields for entering card data, if the client has chosen to pay in the application in this way. Other types of payment should not require this field when selected.
It was necessary for the visibility condition to be sent by the back, and we could interpret it on the client. Moreover, this had to be wrapped in a common code, since the application is based on KMM. Previously, it was impossible to rebuild an application written in KMM right off the bat. Due to the fixed logic, there was only one way to change the interface: to edit the code, compose a new build, send it to Google Play or the App Store for review and wait for the release. Only two of the five links in this chain of actions are related to development. Therefore, even if you code very quickly, it will take a lot of time from the start of work on changes to the release. It will take at least a week, if there is not much work and the marketplaces have no remarks.
We decided to transfer a string, which will contain the JS code that calculates and returns the result, from the server. Bool in the above mentioned case. That is, we pass this expression, the state of the form and user data to the JS handler, and it gives the result of the visibility of this field or option in the list.
For example, user selects two dates, and a special field displays the difference between them in days to show how many days he has selected. This field cannot be entered manually, but must be displayed. Since the entire form is built simply on JSON configuration, no field knows about the existence of others, let alone that the value of the current field A is the difference in days between fields B and C.