Inconsistencies between on how the styles are applied in native and web
See original GitHub issueBug description There are inconsistencies with the way the styles are applied for web and for mobile.
To Reproduce Steps to reproduce the behavior:
- Create a new project that includes nativewind (v2.0.9 in my case)
- Create a component that wraps (inside a styled View) different text components. Example code:
import { Text, TextInput, View } from 'react-native'
import { styled } from 'nativewind'
const StyledView = styled(View)
const StyledText = styled(Text)
export function LoginScreen() {
return (
<StyledView className="gap-3 bg-red-100 text-center">
<StyledText>First text</StyledText>
<StyledText>Another text</StyledText>
<StyledText>Last text</StyledText>
</StyledView>
)
}
- Set up the className to “text-center” for the styled view
- See the differences between native and web versions.
- If the className “text-center” is set to one of the StyledText (instead of the StyledView), it will be centered on android and on web. Example code:
<StyledText className="text-center">
This text has className="text-center"
</StyledText>
Expected behavior The style should be the same in all platforms. It should be “propagated” the same way in web and in android. Having differences in how the style is applied makes the cross-platform development much more tedious.
Expo Snack The issue doesn’t seem reproducible with Expo Snack, but at the same time some styles (background color and gap) are not being applied on any version there, but they do in my local machine. Check the snack here.
Screenshots
Web:
Android:
Additional context I am using Tailwind (Nativewind) with Solito (expo React Native)
Issue Analytics
- State:
- Created 9 months ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Handling common HTML and CSS problems - MDN Web Docs
With the scene set, we'll now look specifically at the common cross-browser problems you will come across in HTML and CSS code, and...
Read more >Porting Practice to Web: react-native-web in Production
Learn how DataCamp ported their mobile application to the web using react-native-web.
Read more >5 common errors found in a React Native app (using Expo)
5 common errors found while creating a React Native mobile app. As we mentioned above, we used Expo to filter the main common...
Read more >React Devs, Why don't you use React Native for Web?
I noticed that you said you haven't actually used React Native for web so hopefully I can help respond to a few of...
Read more >Solving the React Error: Not Picking Up CSS Style | Pluralsight
In this guide, you will learn about the errors that can occur while importing a CSS file into your React file.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just wanted to add, I’m am actively thinking about ways to improve the developer experience around this issue. I believe its possible to make an editor/eslint plugin that warns a user when they use a className incorrectly or in a non-cross platform manner - I just need to learn a bit more about Typescript’s compiler API.
There is no RN library that I know of that simulates web complete style inheritance in React Native. I don’t believe Dripsy has any custom inheritance logic?