Scoped safe-area insets for multi-surface React Native apps #634
Replies: 2 comments 1 reply
|
I understand the use case, but we don’t plan to support scoped insets for now. This would add quite a bit of complexity and ongoing maintenance cost to support a very uncommon multi-surface brownfield setup. We've introduced ScopedVariables lately so you can built your own safe area utilities around it @utility pb-safe {
padding: var(--my-safe-bottom-inset);
}<ScopedVariables variables={{ '--my-safe-bottom-inset': insets.bottom }}>
<Header />
<ScopedVariables variables={{ '--my-safe-bottom-inset': 0 }}>
<SecondApp />
</ScopedVariables>
</ScopedVariables> |
|
Follow-up: One useful detail: the built-in safe-area utilities resolve With that setup, each mounted root retained its own inset values as expected. Thanks again @Brentlok for pointing us toward the new API, closing this as resolved. |
Uh oh!
There was an error while loading. Please reload this page.
Problem
Uniwind.updateInsets()writes safe-area values to process-global runtime state. This works when an application has one React Native root, but not when multiple React Native surfaces are mounted concurrently.This occurs in brownfield applications where native navigation hosts several React Native surfaces. Each surface can have different safe-area values based on its native container.
For example:
bottom: 64.bottom: 0.When Surface B calls
Uniwind.updateInsets({ bottom: 0, ... }), classes such aspb-safeandpb-safe-offset-*on Surface A also recalculate usingbottom: 0.Restoring Surface A’s insets when it regains focus reduces the visible impact, but does not solve the underlying issue: safe-area state belongs to a surface or React subtree, while Uniwind stores one value for the entire runtime.
This can also affect transition frames and navigation flows that keep covered surfaces mounted.
Proposed direction: scoped insets
Would Uniwind be open to a scoped-insets API, conceptually similar to scoped themes?
One possible API:
Components inside that subtree would resolve
*-safe,*-safe-or-*, and*-safe-offset-*utilities against scoped values.Components outside it would continue using global values configured through
Uniwind.updateInsets(), preserving current single-root behavior.The API does not necessarily need to know about React Native
rootTagor Fabric surface IDs. Brownfield hosts can already obtain per-surface insets using aSafeAreaProvider; they mainly need a way to provide those values to Uniwind for one subtree.Potential semantics:
Uniwind.updateInsets()remains the fallback.Alternative API
If a provider is undesirable, another possibility is a keyed registry:
This could be paired with a provider that selects the active scope.
A context-owned value seems less coupled to Fabric and safer than a process-global registry, but maintainer guidance on what best fits Uniwind’s architecture and Pro native-insets implementation would be appreciated.
Questions
SafeAreaListenerintegration and Pro native insets?If this direction is acceptable, I would be happy to work on an implementation after agreeing on API and expected behavior.
All reactions