react-native - 从 React Native 的嵌套文本组件中删除 textDecorationLine
问题描述
您好我有一个嵌套的文本组件来显示带有突出显示的文本的搜索结果。我想强调突出显示的查询文本,但我无法删除该文本组件子项的 textDecorationLine。我需要嵌套文本组件,因为我希望文本换行。
这是代码:
<Text style={styles.text}>
Normal Text
<Text style={styles.highlighted}>
Highlighted Text
<Text style={styles.text}>
Normal Text
</Text>
</Text>
</Text>
const styles = StyleSheet.create({
snippet: {
textDecorationLine: 'none',
textDecorationColor: 'orange',
},
highlight: {
textDecorationLine: 'underline',
textDecorationColor: 'orange',
},
});
预期行为:
普通文本(下划线)突出显示文本(下划线) 普通文本
结果:
普通文本(下划线)突出显示文本 普通文本(下划线)
解决方案
You can overcome this issue by setting the textDecorationColor
to transparent for the child text:
Edit
textDecorationColor is a iOS-only prop.
Code:
export default class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.snippet}>
Normal Text
<Text style={styles.highlight}>
Highlighted Text
<Text style={{textDecorationColor: 'transparent'}}>
Normal Text
</Text>
</Text>
</Text>
</View>
);
}
}
Demo:
Important! Make sure to select iOS tab on snack. The web tab does not behave like a real react-native project.
推荐阅读
- azure - 将 Azure 证书移动到另一个订阅时出错:路径 'properties.keyVaultId' 中的属性 ID '' 无效
- flutter - 类'列表
' 在颤振应用程序中没有实例 getter 'docs' - java - 微服务的 GET 请求上的 Servlet.service I/O 错误
- swift - 调用中缺少参数“studyCard”的参数
- javascript - 我可以在 backdraftjs 的复合组件中指定子级的位置吗?
- visual-studio-code - 有没有办法在 Visual Studio Code 中当前打开的选项卡之间进行搜索和选择?
- javascript - 如何创建具有共同道具值的对象数组
- spring-boot - 在 Spring Boot 项目中限制除 GET 之外的其余 API 方法
- angular - 从服务工作者 javascript 文件调用 Angular Service 方法
- c# - 如何围绕不同的解决方案共享 Azure 功能?