Thread
#compose
    Sergey Y.

    Sergey Y.

    2 years ago
    Hi. Is there any modifier that could work as decoration to the composable views? I want to recreate the SwiftUI's redacted placeholder API. Ideally, I need some modifier that could return me the boundaries of an underlying view hierarchy(only top-level) and be able to draw some geometrical figures ontop. Or what way should I look to create this modifier my own? Thanks.
    jim

    jim

    2 years ago
    The challenge with such a thing is that you largely can't run your composables without the underlying the data, and if you already have the underlying data, why have a placeholder. For this reason, and fidelity reasons, your placeholders are almost certainly going to look better if you have a designer decide what/how the placeholder should look, and you implement a version that draws exactly what you want. It takes more work to design for the places you want to show placeholders, but you'll get the best user experience that way. If you really wanted to generalize this, modifiers are probably the wrong solution. Probably you would want to implement your own RedactionComposer that emits redacted versions of the nodes that the composer tries to emit.
    Sergey Y.

    Sergey Y.

    2 years ago
    and if you already have the underlying data, why have a placeholder.
    True, but I can generate some dummy data while the real one is loading
    What do you mean by RedactionComposer?
    For instance, in SwiftUI it will look similar to this:
    ForEach(
      self.viewModel.isLoading
        ? placeholderArticles // dummy data
        : self.viewModel.articles.filter { !$0.isHidden } // the real data
    ) { article in
    ...
    .redacted(reason: self.viewModel.isLoading ? .placeholder : [])
    ...
    I see it as an ItemDecorator for the RecyclerView. It has access to views and can draw on top or behind them.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    2 years ago
    Using a separate composer seems interesting if you actually want to redact real composables that you're emitting. But it would be really complicated and a lot of work to build, and probably brittle since low level compose APIs are still changing. It would be a lot simpler just to build a composable that draws exactly what you want and compose that instead of your actual view for placeholders
    Sergey Y.

    Sergey Y.

    2 years ago
    I got your point. I need to have a separate composable function which represents a placeholder for that particular type of data.
    Just wondering how SwiftUI handles that. Anyway, thanks for the discussion.
    Timo Drick

    Timo Drick

    2 years ago
    Maybe one easier approach could be creating your own layout components which do have a switch for turning on and off this redacted view. But still much work because you need to change every layout component you are using. E.g.: Row/Column/Box/Stack
    Could start with copying the original components and than extend it to your needs. Maybe when the Google devs like it. It could be merged back upstream