官术网_书友最值得收藏!

Surprising styles inheritance

As we start to use styles, it is vital to understand that React Native styles do not work as a website's CSS. Especially when it comes to inheritance.

Styles of the parent component are not inherited unless it is a Text component. If it is a Text component, it will inherit from parent, only if parent is another Text component:

// src/ Chapter_3/ Example_2_Inheritance_of_Text_component/ App.js

export default
() => (
<View style={styles.container}>
<Text style={styles.green}>
some green text
<Text style={styles.big}>
some big green text
</Text>
</Text>
</View>
);

const styles = StyleSheet.create({
container: {
marginTop: 40
},
green: {
color: 'green'
},
big: {
fontSize: 35
}
});

If you run this code, you will see that the displayed text is green and that the later part is also big. Text with a big style inherited the green colour from the parent Text component. Please also note that the whole text is rendered inside of a View component that has a margin top of 40 dp that is density-independent pixels. Jump to the Learning unitless dimensions section to learn more.

主站蜘蛛池模板: 应用必备| 苗栗县| 富蕴县| 巴林右旗| 金山区| 连江县| 巧家县| 兴国县| 青州市| 石景山区| 七台河市| 柏乡县| 乌鲁木齐市| 吐鲁番市| 筠连县| 嵩明县| 东山县| 宜宾市| 北京市| 尉犁县| 吴旗县| 忻州市| 云浮市| 中超| 竹山县| 临夏县| 民和| 盐山县| 泾源县| 南江县| 钟祥市| 远安县| 高清| 广西| 三穗县| 广南县| 比如县| 那坡县| 洪洞县| 滕州市| 芜湖市|