Skip to content

Commit 4eab005

Browse files
committed
Improve style docs
1 parent d6a921e commit 4eab005

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

docs/Style.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ permalink: docs/style.html
77
next: nativemodulesios
88
---
99

10-
## Declaring Styles
10+
React Native doesn't implement CSS but instead relies on JavaScript to let you style your application. This has been a controversial decision and you can read through those slides for the rationale behind it.
11+
12+
<script async class="speakerdeck-embed" data-id="2e15908049bb013230960224c1b4b8bd" data-ratio="2" src="//speakerdeck.com/assets/embed.js"></script>
13+
14+
## Declare Styles
1115

1216
The way to declare styles in React Native is the following:
1317

@@ -29,6 +33,8 @@ var styles = StyleSheet.create({
2933

3034
`StyleSheet.create` construct is optional but provides some key advantages. It ensures that the values are **immutable** and **opaque** by transforming them into plain numbers that reference an internal table. By putting it at the end of the file, you also ensure that they are only created once for the application and not on every render.
3135

36+
All the attribute names and values are a subset of what works on the web. For layout, React Native implements [Flexbox](/react-native/docs/flexbox.html).
37+
3238
## Using Styles
3339

3440
All the core components accept a style attribute
@@ -41,20 +47,20 @@ All the core components accept a style attribute
4147
and also accepts an array of styles
4248

4349
```javascript
44-
<View style={[style.base, style.background]} />
50+
<View style={[styles.base, styles.background]} />
4551
```
4652

4753
The behavior is the same as `Object.assign`: in case of conflicting values, the one from the right-most element will have precedence and falsy values like `false`, `undefined` and `null` will be ignored. A common pattern is to conditionally add a style based on some condition.
4854

4955
```javascript
50-
<View style={[style.base, this.state.active && style.active]} />
56+
<View style={[styles.base, this.state.active && styles.active]} />
5157
```
5258

5359
Finally, if you really have to, you can also create style objects in render, but they are highly discouraged. Put them last in the array definition.
5460

5561
```javascript
5662
<View
57-
style={[style.base, {
63+
style={[styles.base, {
5864
width: this.state.width,
5965
height: this.state.width * this.state.aspectRatio
6066
}]}
@@ -63,13 +69,13 @@ Finally, if you really have to, you can also create style objects in render, but
6369

6470
## Pass Styles Around
6571

66-
In order to let a call site customize the style of your component children, you can pass styles around. Use `View.stylePropType` and `Text.stylePropType` in order to make sure only styles are being passed.
72+
In order to let a call site customize the style of your component children, you can pass styles around. Use `View.propTypes.style` and `Text.propTypes.style` in order to make sure only styles are being passed.
6773

6874
```javascript
6975
var List = React.createClass({
7076
propTypes: {
71-
style: View.stylePropType,
72-
elementStyle: View.stylePropType,
77+
style: View.propTypes.style,
78+
elementStyle: View.propTypes.style,
7379
},
7480
render: function() {
7581
return (

website/core/Marked.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Lexer.prototype.token = function(src, top) {
356356
type: this.options.sanitize
357357
? 'paragraph'
358358
: 'html',
359-
pre: cap[1] === 'pre' || cap[1] === 'script',
359+
pre: cap[1] === 'pre',
360360
text: cap[0]
361361
});
362362
continue;

0 commit comments

Comments
 (0)