question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistencies between on how the styles are applied in native and web

See original GitHub issue

Bug description There are inconsistencies with the way the styles are applied for web and for mobile.

To Reproduce Steps to reproduce the behavior:

  1. Create a new project that includes nativewind (v2.0.9 in my case)
  2. 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>
  )
}
  1. Set up the className to “text-center” for the styled view
  2. See the differences between native and web versions.
  3. 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=&quot;text-center&quot;
      </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: 2022-12-14 08_42_14-Solito Example App

Android: Screenshot_2022-12-14-08-45-07-38_f73b71075b1de7323614b647fe394240

Additional context I am using Tailwind (Nativewind) with Solito (expo React Native)

Issue Analytics

  • State:closed
  • Created 9 months ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
marklawlorcommented, Dec 14, 2022

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.

1reaction
marklawlorcommented, Dec 14, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found