Javascript 有没有办法从React Native中的子组件更改父组件上文本元素的文本颜色?
是否有办法从React Native中的子组件更改父组件上的文本元素的文本颜色 我已经用下面代码中的图标完成了,我可以用文本完成吗 发现更多父组件Javascript 有没有办法从React Native中的子组件更改父组件上文本元素的文本颜色?,javascript,reactjs,react-native,parent-child,react-props,Javascript,Reactjs,React Native,Parent Child,React Props,是否有办法从React Native中的子组件更改父组件上的文本元素的文本颜色 我已经用下面代码中的图标完成了,我可以用文本完成吗 发现更多父组件 从“React”导入React; 从“react native”导入{文本、视图、TouchableOpacity、样式表}; 从“@miniclementine:common/appearance/Colors”导入颜色; 从“@miniclementine:common/components/ClementineIcon”导入Clementine
从“React”导入React;
从“react native”导入{文本、视图、TouchableOpacity、样式表};
从“@miniclementine:common/appearance/Colors”导入颜色;
从“@miniclementine:common/components/ClementineIcon”导入ClementineIcon;
导出默认函数DiscoverMore({title,onPress,color}){
返回(
{title}
);
}
const styles=StyleSheet.create({
BTN容器样式:{
填充垂直:16,
flexDirection:“行”,
辩护内容:“中心”,
对齐项目:“中心”,
},
btnTextStyle:{
颜色:颜色。矢车菊,
尺寸:16,
textAlign:'中心',
}
});
主页引入DiscoveryMore组件并使用道具更改图标颜色
export default function SessionHomepage({navigation, passData, onPress}) {
const onPressSectionHeader = ({onPress}) => {
navigation.navigate(SESSIONS_LIST_PAGE, passData)
// @TODO: navigate to a page using navigation.navigate(pageName, params);
};
const onPressSectionHeaderInvalid = () => {
alert('Out of scope for this task')
// @TODO: navigate to a page using navigation.navigate(pageName, params);
};
const onContactPress = () => {
Linking.openURL('mailto:alina@clementineapp.co.uk?subject=SendMail&body=Description')
}
return (
<SafeAreaView style={styles.container}>
<ScrollView>
<View style={styles.content}>
<SectionHeader
title="Morning Sessions"
onPress={onPressSectionHeaderInvalid}
/>
<DiscoverMore
title="Discover more sessions"
onPress={onPressSectionHeaderInvalid}
color={Colors.cornflower}
/>
<SectionHeader
title="Pick-me-ups"
onPress={onPressSectionHeader}
/>
<DiscoverMore
title="Discover more sessions"
onPress={onPressSectionHeader}
color={Colors.cornflower}
/>
</View>
<View style={styles.sleepSection}>
<Image
source={require('../../assets/illustrations/sleep_section.png')}
style={{height: 250, width: '100%'}}
/>
</View>
<View style={styles.content}>
<View style={styles.sleepSection}>
<SectionHeader
title="Sleep Sessions"
onPress={onPressSectionHeaderInvalid}
/>
<Text>test</Text>
<DiscoverMore
title="Discover more sessions"
onPress={onPressSectionHeaderInvalid}
color={Colors.powderBlue}
/>
</View>
</View>
<BlueButton title="Leave us feedback" onPress={onContactPress}/>
</ScrollView>
</SafeAreaView>
);
}
导出默认函数SessionHomepage({navigation,passData,onPress}){
const onPressSectionHeader=({onPress})=>{
导航。导航(会话\列表\页面,passData)
//@TODO:使用导航导航到页面。导航(pageName,params);
};
const onpress sectionheaderinvalid=()=>{
警报('超出此任务的范围')
//@TODO:使用导航导航到页面。导航(pageName,params);
};
const onContactPress=()=>{
Linking.openURL('mailto:alina@clementineapp.co.uk?主题=发送邮件&正文=说明')
}
返回(
测试
);
}
试试这种方法
发现页面
export default function DiscoverMore({title, onPress, color, textColor}) {
return (
<TouchableOpacity onPress={onPress}>
<View style={styles.btnContainerStyle}>
<ClementineIcon name="add-circle-bold" color={color} size={24} />
<Text style={[styles.btnTextStyle,{color: textColor}]}> {title} </Text>
</View>
</TouchableOpacity>
);
}
导出默认函数DiscoverMore({title,onPress,color,textColor}){
返回(
{title}
);
}
主页
<DiscoverMore
title="Discover more sessions"
onPress={onPressSectionHeaderInvalid}
color={Colors.cornflower}
textColor={Colors.cornflower} // add text color here
/>
<DiscoverMore
title="Discover more sessions"
onPress={onPressSectionHeaderInvalid}
color={Colors.cornflower}
textColor={Colors.cornflower} // add text color here
/>