Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CompositeBackgroundDrawable and BackgroundStyleApplicator #45688

Closed
wants to merge 5 commits into from

Conversation

NickGerleman
Copy link
Contributor

Summary:
Box shadows are handled as part of different drawables. We have other cases where we want to show multiple drawables at once, such as for ripple feedback, or more commonly, for app-wide TextInput styles (which adds padding).

With more multi-background scenarios in the future, and CSSBackgroundDrawable already way overloaded, the arch here I want to go towards is less drawables, as hidden implementation details, with single responsibilities, more often switched out. Once path logic is extracted, this would also allow for better fast-paths, like not needing to create a (heavy) CSSBackgroundDrawable, for simple views with a color background.

CompositeBackgroundDrawable is then a more structured LayerDrawable, which also lets us mutate or retrieve information from specific layers, and enforces the different types of layers are correctly z-ordered.

BackgroundStyleApplicator is the public API for manipulating these styles, inspired by the existing ReactViewBackgroundManager. There are some important design differences.

  1. The only per-view state is the publicly accessible background drawable. This means the applicator can be used on arbitrary views, and eventually used in BaseViewManager for all views (once all the QEs settle)
  2. We have reliable accessors for every setter, which seem to be what folks use externally for animation
  3. We work consistently in DIPs (for the most part...)
  4. More structure/safety in how we refer to edges vs uniform
  5. Overflow state is not kept on the applicator, so views can set/keep their own defaults

Overflow clipping must still be implemented per-view, during drawing unfortunately.

Changelog:
[Android][Added] - Add BackgroundStyleApplicator for managing view backgrounds

Differential Revision: D60252279

Summary:
We built these to be able to parse web style string values, but the types only allow object form, and the TypeScript type is wrong.

Changelog: [Internal]

Differential Revision: D60263730
Differential Revision: D60252277
Differential Revision: D60252276
Differential Revision: D60265329
Summary:
Box shadows are handled as part of different drawables. We have other cases where we want to show multiple drawables at once, such as for ripple feedback, or more commonly, for app-wide TextInput styles (which adds padding).

With more multi-background scenarios in the future, and CSSBackgroundDrawable already way overloaded, the arch here I want to go towards is less drawables, as hidden implementation details, with single responsibilities, more often switched out. Once path logic is extracted, this would also allow for better fast-paths, like not needing to create a (heavy) CSSBackgroundDrawable, for simple views with a color background.

`CompositeBackgroundDrawable` is then a more structured LayerDrawable, which also lets us mutate or retrieve information from specific layers, and enforces the different types of layers are correctly z-ordered.

`BackgroundStyleApplicator` is the public API for manipulating these styles, inspired by the existing `ReactViewBackgroundManager`. There are some important design differences.

1. The only per-view state is the publicly accessible background drawable. This means the applicator can be used on arbitrary views, and eventually used in BaseViewManager for all views (once all the QEs settle)
2. We have reliable accessors for every setter, which seem to be what folks use externally for animation
3. We work consistently in DIPs (for the most part...)
4. More structure/safety in how we refer to edges vs uniform
5. Overflow state is not kept on the applicator, so views can set/keep their own defaults

Overflow clipping must still be implemented per-view, during drawing unfortunately.

Changelog:
[Android][Added] - Add BackgroundStyleApplicator for managing view backgrounds

Differential Revision: D60252279
@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Jul 26, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D60252279

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 1a78477.

@react-native-bot
Copy link
Collaborator

This pull request was successfully merged by @NickGerleman in 1a78477

When will my fix make it into a release? | How to file a pick request?

kkafar added a commit to software-mansion/react-native-screens that referenced this pull request Jan 31, 2025
)

## Description


* facebook/react-native#45688 introduced
`BackgroundStyleApplicator`
* facebook/react-native#47906 removed our
current accessor
* somewhere along the way the `ColorDrawable` used previously by
`ReactViewGroup` has been exchanged for `CompositeBackgroundDrawable`
added in facebook/react-native#45688

> [!caution]
~This PR breaks compatibility with older versions of react-native. While
this is fine on Fabric, this also breaks things for Paper.~
> ~Possible solution is to detect react native version in gradle and add
versioned sourcesets with implementations for given react native
versions.~
>
> Not up to date. I've added versioned source files to ensure
appropriate backward compatibility down to 0.74.

> [!note]
> We need CI to ensure the projects do build on all versions we support.

## Changes

Migrated to `BackgroundStyleApplicator API` to resolve background color
of `contentWrapper`.

## Test code and steps to reproduce

`TestAndroidTransitions` - the form sheet should no longer be cut.

## Checklist

- [ ] Ensured that CI passes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants