callstack / callstack/react-native-paper

Nested Text components do not inherit style

未关闭
#4,351 1 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
TypeScript
星标
14.5k
派生
2.2k
平均合并
5 天 23 小时
30 天内合并 PR
12

描述

### Current behaviour
When nesting `Text` components, the child component does not inherit the style of the parent element.

### Expected behaviour
I would expect the styles to be inherited and overridden by the child component instead of simply overridden. The Text component from react-native exhibits this behavior.

### How to reproduce?
Nest a Text component inside another Text component and apply styles to both (e.g., color on one and fontWeight on the other). Note the nested component ignores the styles set on the parent component.

https://snack.expo.dev/lfm3PI-XWFR_YP56qwbn7

### Preview
![image](https://github.com/callstack/react-native-paper/assets/29152776/bc1d88c0-69de-4651-9014-112f03ef1f9a)

### What have you tried so far?
Replacing the nested Text element with the react-native version (instead of RNP) fixes the inheritance, but you lose the default styles from RNP that you may wish to preserve (e.g., if the nested Text is a different variant from the parent, you need to manually apply all of the variant styles to the nested element).

### Your Environment

| software | version
| --------------------- | -------
| ios | 17.2
| android | 30
| react-native | 0.73.2
| react-native-paper | 4.9.2
| node | 18.17.1
| yarn | 1.22.19
| expo sdk | 50.0.0

贡献指南

打开贡献指南

调研方向

从链接的 Expo Snack 和 Text 组件实现开始;复现带有父级和子级样式(例如 color 和 fontWeight)的嵌套 Text 组件。将其行为与 React Native 的 Text 组件进行比较。当子 Text 保留可从父级继承的样式,同时允许其自身的样式和变体覆盖这些样式时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
react-native, typescript
领域
mobile
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。