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

WIP: Fix nested text styling not inheriting from parent #4356

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rayan1810
Copy link

This addresses the issue #4351 by adding a React Context with Text Component and checks + reads the parent Text's context to get it's style and merges it with the current Text's style, just like how React Native behaves.

Related issue

#4351

Test plan

Testing is pending, the PR is still a Work in progress!

@callstack-bot
Copy link

Hey @rayan1810, thank you for your pull request 🤗. The documentation from this branch can be viewed here.

Comment on lines +167 to +169
if (parentTextContext) {
Object.assign(textStyle, StyleSheet.flatten(parentTextContext.style));
}
Copy link

@scarletcs scarletcs May 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me as though this will overwrite any element-specific styling with the parent styling, such that this would output both words in blue:

<Text style={{color: "blue"}}>
  Blue!
  <Text style={{color: "red"}}>
    Red!
  </Text>
</Text>

So the following code would be preferable instead:

if (parentTextContext) {
  textStyle = Object.assign(StyleSheet.flatten(parentTextContext.style), textStyle);
}

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

Successfully merging this pull request may close these issues.

None yet

3 participants