-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[change] StyleSheet: news APIs and refactor
This fixes several issues with 'StyleSheet' and simplifies the implementation. 1. The generated style sheet could render after an apps existing style sheets, potentially overwriting certain 'html' and 'body' styles. To fix this, the style sheet is now rendered first in the document head. 2. 'StyleSheet' didn't make it easy to render app shells on the server. The prerendered style sheet would contain classnames that didn't apply to the client-generated style sheet (in part because the class names were not generated as a hash of the declaration). When the client initialized, server-rendered parts of the page could become unstyled. To fix this 'StyleSheet' uses inline styles by default and a few predefined CSS rules where inline styles are not possible. 3. Even with the strategy of mapping declarations to unique CSS rules, very large apps can produce very large style sheets. For example, twitter.com would produce a gzipped style sheet ~30 KB. Issues related to this are also alleviated by using inline styles. 4. 'StyleSheet' didn't really work unless you rendered an app using 'AppRegistry'. To fix this, 'StyleSheet' now handles injection of the DOM style sheet. Using inline styles doesn't appear to have any serious performance problems compared to using single classes (ref #110). Fix #90 Fix #106
- Loading branch information
Showing
26 changed files
with
326 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ const Heading = ({ children, size = 'normal' }) => ( | |
<Text | ||
accessibilityRole='heading' | ||
children={children} | ||
style={{ ...styles.root, ...sizeStyles[size] }} | ||
style={[ styles.root, sizeStyles[size] ]} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
necolas
Author
Owner
|
||
/> | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { AppRegistry } from 'react-native' | ||
import React from 'react' | ||
import ReactNative, { AppRegistry } from 'react-native' | ||
import App from './components/App' | ||
import Game2048 from './2048/Game2048' | ||
import TicTacToeApp from './TicTacToe/TicTacToe' | ||
|
||
const rootTag = document.getElementById('react-root') | ||
AppRegistry.registerComponent('App', () => App) | ||
|
||
AppRegistry.runApplication('App', { | ||
rootTag: document.getElementById('react-root') | ||
}) | ||
AppRegistry.runApplication('App', { rootTag }) | ||
// ReactNative.render(<App />, rootTag) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,16 @@ | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'assert' | ||
import React from 'react' | ||
import { elementId } from '../../StyleSheet' | ||
import { prerenderApplication } from '../renderApplication' | ||
import React from 'react' | ||
|
||
const component = () => <div /> | ||
|
||
suite('apis/AppRegistry/renderApplication', () => { | ||
test('prerenderApplication', () => { | ||
const { html, style, styleElement } = prerenderApplication(component, {}) | ||
const { html, styleElement } = prerenderApplication(component, {}) | ||
|
||
assert.ok(html.indexOf('<div ') > -1) | ||
assert.ok(typeof style === 'string') | ||
assert.equal(styleElement.type, 'style') | ||
assert.equal(styleElement.props.id, elementId) | ||
assert.equal(styleElement.props.dangerouslySetInnerHTML.__html, style) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/apis/StyleSheet/__tests__/createReactStyleObject-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* eslint-env mocha */ | ||
|
||
import assert from 'assert' | ||
import createReactStyleObject from '../createReactStyleObject' | ||
|
||
suite('apis/StyleSheet/createReactStyleObject', () => { | ||
test('converts ReactNative style to ReactDOM style', () => { | ||
const reactNativeStyle = { display: 'flex', marginVertical: 0, opacity: 0 } | ||
const expectedStyle = { display: 'flex', marginTop: '0px', marginBottom: '0px', opacity: 0 } | ||
|
||
assert.deepEqual(createReactStyleObject(reactNativeStyle), expectedStyle) | ||
}) | ||
}) |
Oops, something went wrong.
@necolas any reason why you prefer array to spread (since at the end, it's sort of the same)?