workflow-kotlin icon indicating copy to clipboard operation
workflow-kotlin copied to clipboard

Tutorial uses LayoutRunner instead of ScreenViewFactory

Open tom-pratt opened this issue 2 years ago • 2 comments
trafficstars

It seems that ScreenViewFactory is preferred over LayoutRunner these days. It would also be nice if the tutorial mentioned AndroidScreen as an alternative. This would align the tutorials with info here https://square.github.io/workflow/userguide/ui-in-code/#building-views-from-screens.

tom-pratt avatar Dec 21 '22 15:12 tom-pratt

The tutorials are indeed out of date, but ScreenViewFactory and LayoutRunner aren't analogs.

Before Screen and Overlay were introduced:

  • A ViewFactory would create a View to be driven by a LayoutRunner function to show renderings of a particular type.
  • These ViewFactory bindings had to be gathered at runtime in ViewRegistry collections.
  • AndroidViewRendering was introduced to allow a rendering to provide its ViewFactory directly, avoiding the ViewRegistry boilerplate and runtime errors.

This year, the Screen and Overlay marker types were created, along with replacements for most of the above. This was done mainly to simplify Android Dialog management. Today:

  • A ScreenViewFactory creates a View to be driven by a ScreenViewRunner function to show a particular type of Screen.
  • An OverlayDialogFactory creates a Dialog to show a particular type of Overlay. There is no Dialog analog to ScreenViewRunner.
  • AndroidScreen replaces AndroidViewRendering, and an analagous AndroidOverlay has been introduced.

Both before and after, ViewRegistry is still available to allow runtime bindings between rendering types and the view system where needed. These runtime bindings can also be used to override those implemented via AndroidScreen and the like.

There are still shortcomings with the updated Workflow UI -- redundancy and assymetry between View and Dialog support, and some inefficieny in Compose support (#546). In 2023, I'm hoping to roll out VisualFactory as a simpler, more flexible replacement for most of the above (#874).

rjrjr avatar Dec 21 '22 17:12 rjrjr

tl;dr: we should indeed update the tutorials to use non-deprecated interfaces, and also to encourage the use of AndroidScreen.

rjrjr avatar Dec 21 '22 17:12 rjrjr