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

Text component inline style overrides global style [color] #2634

Closed
1 task done
JinYuSha0 opened this issue Jan 28, 2024 · 3 comments
Closed
1 task done

Text component inline style overrides global style [color] #2634

JinYuSha0 opened this issue Jan 28, 2024 · 3 comments
Labels

Comments

@JinYuSha0
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

image
image

Expected behavior

Why text component's color defaults to black instead of inheriting
This is incompatible with browser specifications
https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/exports/Text/index.js#L189

Steps to reproduce

Add global styles and create text components

Test case

https://codesandbox.io/p/sandbox/fervent-lichterman-jv4n25

Additional comments

In fact, the performance of react-native on Android follows AppTheme, and iOS has Appearance, so it is more reasonable to set it as inheritance.

@JinYuSha0
Copy link
Author

I submitted this PR [#2635]

@necolas
Copy link
Owner

necolas commented Jan 28, 2024

This is how Text works in react native

@necolas necolas closed this as completed Jan 28, 2024
@JinYuSha0
Copy link
Author

JinYuSha0 commented Jan 29, 2024

Well, if anyone encounters this problem, say you want to modify the font color globally in react-native-web, or switch themes, you can try this solution:

import {Platform, Text, View} from 'react-native';
import React from 'react';
import RootStack from './src/navigation/rootStack';

function App(): React.JSX.Element {
  const content = (
    <AppProvider>
      <RootStack />
    </AppProvider>
  );
  if (Platform.OS === 'web') {
    // Why wrapped by Text component?
    // Create a TextAncestorContext, make the color of the child Text component inherited
    // Related issues: https://github.com/necolas/react-native-web/issues/2634
    return (
      <Text style={{flex: 1, display: 'flex', color: 'your target color'}}>
         {content}
      </Text>
    );
  }
  return content;
}

export default App;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants