-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
[Android] Add DisplayP3 background and border support to View #43056
base: main
Are you sure you want to change the base?
[Android] Add DisplayP3 background and border support to View #43056
Conversation
dbe644f
to
1afc4b5
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Method setBackgroundColorMethod = view.getClass().getMethod("setBackgroundColor", long.class); | ||
setBackgroundColorMethod.invoke(view, backgroundColor); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we instead use something like a ColorDrawable
here or avoid using reflection if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cortinico I tried making ColorDrawable
work but I don't think I can make it work with long colors. Instead I think we can just check if the view is an instance of ReactViewGroup
(Is this always true?) and that seems to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can just check if the view is an instance of ReactViewGroup (Is this always true?)
I don't think it's always true sadly
/** | ||
* Class representing CSS spacing border colors. Modified from {@link Spacing} to support long values. | ||
*/ | ||
public class BorderColor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally we'd want new classes to be in Kotlin at this stage
1afc4b5
to
e5c6cb3
Compare
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
if (view instanceof ReactViewGroup) { | ||
((ReactViewGroup) view).setBackgroundColor(backgroundColor); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ryanlntn, using ReactViewGroups
creates a circular dependencies in the internal CI, we have some difference in how modules are structured internally.
Can you refresh my memory and remind me why you need to cast the view
to ReactViewGroup
? Can't we use the same approach we use below for regular views?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cipolleschi Since I updated this to remove the use of reflection we need to cast to a type that supports setBackgroundColor(long color)
or it won't compile. Regular views only support setBackgroundColor(int color)
. Would it be better to create a new subclass of View to extend for T
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ryanlntn We can't do in this way, unfortunately. Due to the circular dependencies, it will not work internally. And a subclass will give us no guarantees that it will be instantiated properly. I think that we need an interface.
The best way to move forward is probably:
- in the
uimanager
folder, let's create an Interface:
public interface ReactWideGamutView extends View {
public void setBackgroundColor(long color);
// other methods required by wide gamut
}
- Make the
ReactViewGroup
implement theReactWideGamutView
interface - Replace the casting to
ReactViewGroup
with a check like:
if (view instanceof ReactWideGamutView) {
((ReactWideGamutView) view).setBackgroundColor(backgroundColor);
In this way, we don't have the circular dependency, because the ReactWideGamutView
will live in the same package as ReactUIManager
and we can safely cast the view to the right interface and avoid any subclass.
Also, all future subclasses of ReactViewGroup will benefit from implementing the same interface out of the box.
We should check whether there are other React componentes that we need to make them implement the same interface.... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also the same approach used for uimanager.ReactZIndexedViewGroup
: as you can see this interface leaves in the uimanager
package.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense to me. I'll get it updated. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
We should check whether there are other React componentes that we need to make them implement the same interface....
AFAIK this isn't the case yet. Implementing this in ReactViewGroup is all I need to get wide gamut backgrounds working for View.
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days. |
Summary:
This builds on previous PRs for the wide gamut color RFC and extends Android views with support for DisplayP3 backgrounds and borders.
Changelog:
[ANDROID] [ADDED] - Add DisplayP3 background and border support to View
Test Plan:
[JS] Add support for CSS4 color() functions #42831
[Android] Update ColorPropConverterto support color function values #43031
[Android] Add isWideColorGamutEnabled to ReactActivityDelegate #43036
cd packages/rn-tester && yarn android