-
Notifications
You must be signed in to change notification settings - Fork 112
Description
@bencochran @zach-klippenstein @AquaGeek @dhavalshreyas
I had a chat last week with @helios175, and he schooled me on decoupling modal visual style from layering.
e.g., in Kotlin right now we have a number of samples where the top level rendering type is something like…
AlertContainerScreen<CardContainerScreen<BackstackScreen<Any>>
That is, you can show alerts over cards. Not so bad. But in our prodution app, where we have both a number of modal layers and a number of modal styles, the combinatorics get kind of nuts, something like:
typealias Root =
AlertContainerScreen<
TutorialBarsContainerScreen<
CardContainerScreen<
SheetContainerScreen<
CardContainerScreen<Any, Any>,
Any
>,
Any
>
>
>
because we want
- alerts to be modal over the tutorial bars
- tutorial bars to be outside the area covered by cards and sheets
- the ability to put sheets over cards visually, but then sometimes another card on top of that
Instead of this, the "big idea" (probably obvious to anyone who isn't me) is to have a single container type that is able to make things modal, wrapping others that own the visual style. This works because our modal screens already hold lists to allow visual stacking.
So the above would reduce to something like:
typealias Root =
ModalContainerScreen<
TutorialBarsContainerScreen<
ModalContainerScreen<Any, Any>
>,
Any
>
With AlertModal<T>, CardModal<T>, SheetModal<T>, BottomSheetModal<T>, etc., as possible contituents. If I want to show an alert over a card over a sheet, my root workflow assembles the equivalent of:
ModalContainerScreen(
modals = listOf(AlertModal(...)),
body = TutorialBarsContainerScreen(
ModalContainerScreen(
modals = listOf(
SheetModal(...), CardModal(...)
)
body = ...
)
)
)
The downside here is that some layering rules become slightly more runtime. E.g. we don't want every child workflow that may want to show modals to have to know anything about tutorials, or these layering rules. An inner workflow should be able to render something like:
ModalContainerScreen(
modals = listOf(CardModal(...), AlertModal("Are you sure?", ...)),
body = ...
)
So some tutorial-aware outer workflow will need to filter the modals lists of its children, and move AlertModal instances to an outer layer. But that doesn't seem like a big deal.
Anyway, I'm giving myself permission to play with this today because I need to solve a problem where I'm getting double-darkness when showing cards over cards.
WDYT?