-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Allow overriding style on web #4333
base: master
Are you sure you want to change the base?
Allow overriding style on web #4333
Conversation
I'm just wondering- if you have a react-native app you have one |
If you're referring to the testing, then I've tested it; I assumed the the |
Sorry, I'm not sure why my comment was cut off. What I meant was: if you have a Video component in your app that works for both web and native, do the types work correctly? Do they change, for example, when you use Platform.select? Also, what is the default type in that case? |
If this is about the typing change, then I did not test that, I needed to send an empty style |
style?: CSSProperties; | ||
} | ||
|
||
export type WebReactVideoProps = Omit<ReactVideoProps, 'style'> & WebStyleProp; |
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.
why don't you patch directly ReactVideoProps instead of creating WebStyleProp in this common file ?
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.
something like:
type CustomViewProps = Omit<ViewProps, 'style'> & {
style?: ViewProps['style'] | CSSProperties;
};
export interface ReactVideoProps extends ReactVideoEvents, CustomViewProps {
|
I purposely omitted the style props because this is not compatible with react native styles. this means you'll need a different style for web & native. Since types are different, Maybe we could add a |
Another option is to add a prop that will have |
just a ping on this PR, I think we definitively need to integrate such change ! |
Hi @freeboub, |
@M-i-k-e-l Yes it was for you :) I think you just need to check the patch in Video.ts export interface ReactVideoProps extends ReactVideoEvents, ViewProps { to export interface ReactVideoProps extends ReactVideoEvents, Omit<ViewProps, 'style'> {
style?: CSSProperties | Pick<ViewProps, 'style'> I am not fan of having some Web dedicated interface. I think we should keep the api common (even if here we don't really have the choice) Would that work for you ? |
Wouldn't it make more sense to use https://necolas.github.io/react-native-web/docs/unstable-apis/#use-with-existing-react-dom-components to use the style prop from react-native with the web element? |
@zoriya I am not confident in using unstable apis ... I am not a web dev, what do we gain by using this api ? If it is only to support in 1 line: accessibilityLabel, accessible, style, I would prefer to handle it prop per prop, it gives a thiner control on the api and allow easier integration when we will enable them on android/ios |
This unstable api allows using react native's style prop on the web. Without using it, a lot of style are different. This also means that all native styling libraries (rnw's default, native-wind, tamagui, unistyle...) won't work on the web (and give type errors on native). This api is marked as unstable but it hasn't changed in a lot of years, I think it's safe to use there honestly. |
OK, @zoriya it looks good to me, but not sure on how to integrate it :D @M-i-k-e-l |
Should be as simple as adding import { unstable_createElement } from 'react-native-web';
const Video = (props) => unstable_createElement('video', props); at the top of the file and changing the component from |
Summary
Allow overriding style on web
Motivation
When overriding the
style
with{}
we can allow the (web) video to resize to its real size without further effort.Changes
Sending
style
will now affect video on web.Test plan
I assume that if someone is already sending
style
this can affect them, however the release of the web support was quite recent so I'm not sure how risky this is; not sure how to test it though...