mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-06 20:03:47 +00:00
[change] prepare for react-dom@15.4.0
Don't depend directly on the 'react-dom' module as it will be prebuilt in 15.4. Leave server-side rendering to 'react-dom/server'.
This commit is contained in:
@@ -13,14 +13,11 @@ into `runApplication`. These should always be used as a pair.
|
|||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
(web) static **prerenderApplication**(appKey:string, appParameters: object)
|
(web) static **getApplication**(appKey:string, appParameters: object)
|
||||||
|
|
||||||
Renders the given application to an HTML string. Use this for server-side
|
Returns the given application element. Use this for server-side rendering.
|
||||||
rendering. Return object is of type `{ html: string; style: string;
|
Return object is of type `{ element: ReactElement; stylesheet: ReactElement }`.
|
||||||
styleElement: ReactComponent }`. `html` is the prerendered HTML, `style` is the
|
It's recommended that you use `sheetsheet` to render the style sheet in an app
|
||||||
prerendered style sheet, and `styleElement` is a React Component. It's
|
|
||||||
recommended that you use `styleElement` to render the style sheet in an app
|
|
||||||
shell.
|
|
||||||
|
|
||||||
static **registerConfig**(config: Array<AppConfig>)
|
static **registerConfig**(config: Array<AppConfig>)
|
||||||
|
|
||||||
|
|||||||
@@ -43,12 +43,7 @@ import ReactNative from 'react-native'
|
|||||||
// component that renders the app
|
// component that renders the app
|
||||||
const AppHeaderContainer = (props) => { /* ... */ }
|
const AppHeaderContainer = (props) => { /* ... */ }
|
||||||
|
|
||||||
// DOM render
|
|
||||||
ReactNative.render(<AppHeaderContainer />, document.getElementById('react-app-header'))
|
ReactNative.render(<AppHeaderContainer />, document.getElementById('react-app-header'))
|
||||||
|
|
||||||
// Server render
|
|
||||||
ReactNative.renderToString(<AppHeaderContainer />)
|
|
||||||
ReactNative.renderToStaticMarkup(<AppHeaderContainer />)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Rendering using the `AppRegistry`:
|
Rendering using the `AppRegistry`:
|
||||||
@@ -63,7 +58,6 @@ const AppContainer = (props) => { /* ... */ }
|
|||||||
// register the app
|
// register the app
|
||||||
AppRegistry.registerComponent('App', () => AppContainer)
|
AppRegistry.registerComponent('App', () => AppContainer)
|
||||||
|
|
||||||
// DOM render
|
|
||||||
AppRegistry.runApplication('App', {
|
AppRegistry.runApplication('App', {
|
||||||
initialProps: {},
|
initialProps: {},
|
||||||
rootTag: document.getElementById('react-app')
|
rootTag: document.getElementById('react-app')
|
||||||
@@ -72,3 +66,22 @@ AppRegistry.runApplication('App', {
|
|||||||
// prerender the app
|
// prerender the app
|
||||||
const { html, styleElement } = AppRegistry.prerenderApplication('App', { initialProps })
|
const { html, styleElement } = AppRegistry.prerenderApplication('App', { initialProps })
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Server-side rendering
|
||||||
|
|
||||||
|
Rendering using the `AppRegistry`:
|
||||||
|
|
||||||
|
```
|
||||||
|
import ReactDOMServer from 'react-dom/server'
|
||||||
|
import ReactNative, { AppRegistry } from 'react-native'
|
||||||
|
|
||||||
|
// component that renders the app
|
||||||
|
const AppContainer = (props) => { /* ... */ }
|
||||||
|
|
||||||
|
// register the app
|
||||||
|
AppRegistry.registerComponent('App', () => AppContainer)
|
||||||
|
|
||||||
|
// prerender the app
|
||||||
|
const { element, stylesheet } = AppRegistry.getApplication('App', { initialProps });
|
||||||
|
const initialHTML = ReactDOMServer.renderToString(element);
|
||||||
|
```
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
/* eslint-env jasmine, jest */
|
/* eslint-env jasmine, jest */
|
||||||
|
|
||||||
import { prerenderApplication } from '../renderApplication';
|
import { getApplication } from '../renderApplication';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const component = () => <div />;
|
const component = () => <div />;
|
||||||
|
|
||||||
describe('apis/AppRegistry/renderApplication', () => {
|
describe('apis/AppRegistry/renderApplication', () => {
|
||||||
test('prerenderApplication', () => {
|
test('getApplication', () => {
|
||||||
const { html, styleElement } = prerenderApplication(component, {});
|
const { element, stylesheet } = getApplication(component, {});
|
||||||
|
|
||||||
expect(html.indexOf('<div ') > -1).toBeTruthy();
|
expect(element).toBeTruthy();
|
||||||
expect(styleElement.type).toEqual('style');
|
expect(stylesheet.type).toEqual('style');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
import invariant from 'fbjs/lib/invariant';
|
import invariant from 'fbjs/lib/invariant';
|
||||||
import ReactDOM from 'react-dom';
|
import { unmountComponentAtNode } from 'react/lib/ReactMount';
|
||||||
import renderApplication, { prerenderApplication } from './renderApplication';
|
import renderApplication, { prerenderApplication } from './renderApplication';
|
||||||
|
|
||||||
const runnables = {};
|
const runnables = {};
|
||||||
@@ -29,20 +29,20 @@ class AppRegistry {
|
|||||||
return Object.keys(runnables);
|
return Object.keys(runnables);
|
||||||
}
|
}
|
||||||
|
|
||||||
static prerenderApplication(appKey: string, appParameters?: Object): string {
|
static getApplication(appKey: string, appParameters?: Object): string {
|
||||||
invariant(
|
invariant(
|
||||||
runnables[appKey] && runnables[appKey].prerender,
|
runnables[appKey] && runnables[appKey].getApplication,
|
||||||
`Application ${appKey} has not been registered. ` +
|
`Application ${appKey} has not been registered. ` +
|
||||||
'This is either due to an import error during initialization or failure to call AppRegistry.registerComponent.'
|
'This is either due to an import error during initialization or failure to call AppRegistry.registerComponent.'
|
||||||
);
|
);
|
||||||
|
|
||||||
return runnables[appKey].prerender(appParameters);
|
return runnables[appKey].getApplication(appParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
static registerComponent(appKey: string, getComponentFunc: ComponentProvider): string {
|
static registerComponent(appKey: string, getComponentFunc: ComponentProvider): string {
|
||||||
runnables[appKey] = {
|
runnables[appKey] = {
|
||||||
run: ({ initialProps, rootTag }) => renderApplication(getComponentFunc(), initialProps, rootTag),
|
getApplication: ({ initialProps } = {}) => getApplication(getComponentFunc(), initialProps),
|
||||||
prerender: ({ initialProps } = {}) => prerenderApplication(getComponentFunc(), initialProps)
|
run: ({ initialProps, rootTag }) => renderApplication(getComponentFunc(), initialProps, rootTag)
|
||||||
};
|
};
|
||||||
return appKey;
|
return appKey;
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ class AppRegistry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unmountApplicationComponentAtRootTag(rootTag) {
|
static unmountApplicationComponentAtRootTag(rootTag) {
|
||||||
ReactDOM.unmountComponentAtNode(rootTag);
|
unmountComponentAtNode(rootTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import invariant from 'fbjs/lib/invariant';
|
import invariant from 'fbjs/lib/invariant';
|
||||||
import ReactDOM from 'react-dom';
|
import { render } from 'react/lib/ReactMount';
|
||||||
import ReactDOMServer from 'react-dom/server';
|
import ReactDOMServer from 'react-dom/server';
|
||||||
import ReactNativeApp from './ReactNativeApp';
|
import ReactNativeApp from './ReactNativeApp';
|
||||||
import StyleSheet from '../../apis/StyleSheet';
|
import StyleSheet from '../../apis/StyleSheet';
|
||||||
@@ -23,17 +23,16 @@ export default function renderApplication(RootComponent: Component, initialProps
|
|||||||
rootTag={rootTag}
|
rootTag={rootTag}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
ReactDOM.render(component, rootTag);
|
render(component, rootTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function prerenderApplication(RootComponent: Component, initialProps: Object): string {
|
export function getApplication(RootComponent: Component, initialProps: Object): Object {
|
||||||
const component = (
|
const element = (
|
||||||
<ReactNativeApp
|
<ReactNativeApp
|
||||||
initialProps={initialProps}
|
initialProps={initialProps}
|
||||||
rootComponent={RootComponent}
|
rootComponent={RootComponent}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
const html = ReactDOMServer.renderToString(component);
|
const stylesheet = StyleSheet.render();
|
||||||
const styleElement = StyleSheet.render();
|
return { element, stylesheet };
|
||||||
return { html, styleElement };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import dismissKeyboard from '../../modules/dismissKeyboard';
|
import dismissKeyboard from '../../modules/dismissKeyboard';
|
||||||
|
import findNodeHandle from '../../modules/findNodeHandle';
|
||||||
import invariant from 'fbjs/lib/invariant';
|
import invariant from 'fbjs/lib/invariant';
|
||||||
import ReactDOM from 'react-dom';
|
|
||||||
import ScrollResponder from '../../modules/ScrollResponder';
|
import ScrollResponder from '../../modules/ScrollResponder';
|
||||||
import ScrollViewBase from './ScrollViewBase';
|
import ScrollViewBase from './ScrollViewBase';
|
||||||
import StyleSheet from '../../apis/StyleSheet';
|
import StyleSheet from '../../apis/StyleSheet';
|
||||||
@@ -55,11 +55,11 @@ const ScrollView = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
getScrollableNode(): any {
|
getScrollableNode(): any {
|
||||||
return ReactDOM.findDOMNode(this._scrollViewRef);
|
return findNodeHandle(this._scrollViewRef);
|
||||||
},
|
},
|
||||||
|
|
||||||
getInnerViewNode(): any {
|
getInnerViewNode(): any {
|
||||||
return ReactDOM.findDOMNode(this._innerViewRef);
|
return findNodeHandle(this._innerViewRef);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-6
@@ -1,6 +1,5 @@
|
|||||||
import findNodeHandle from './modules/findNodeHandle';
|
import findNodeHandle from './modules/findNodeHandle';
|
||||||
import ReactDOM from 'react-dom';
|
import { render, unmountComponentAtNode } from 'react/lib/ReactMount';
|
||||||
import ReactDOMServer from 'react-dom/server';
|
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
import I18nManager from './apis/I18nManager';
|
import I18nManager from './apis/I18nManager';
|
||||||
@@ -14,10 +13,8 @@ import View from './components/View';
|
|||||||
|
|
||||||
const ReactNativeCore = {
|
const ReactNativeCore = {
|
||||||
findNodeHandle,
|
findNodeHandle,
|
||||||
render: ReactDOM.render,
|
render,
|
||||||
renderToStaticMarkup: ReactDOMServer.renderToStaticMarkup,
|
unmountComponentAtNode,
|
||||||
renderToString: ReactDOMServer.renderToString,
|
|
||||||
unmountComponentAtNode: ReactDOM.unmountComponentAtNode,
|
|
||||||
// APIs
|
// APIs
|
||||||
I18nManager,
|
I18nManager,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
|
|||||||
+3
-7
@@ -1,6 +1,5 @@
|
|||||||
import findNodeHandle from './modules/findNodeHandle';
|
import findNodeHandle from './modules/findNodeHandle';
|
||||||
import ReactDOM from 'react-dom';
|
import { render, unmountComponentAtNode } from 'react/lib/ReactMount';
|
||||||
import ReactDOMServer from 'react-dom/server';
|
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
import Animated from './apis/Animated';
|
import Animated from './apis/Animated';
|
||||||
@@ -47,11 +46,8 @@ import PointPropType from './propTypes/PointPropType';
|
|||||||
const ReactNative = {
|
const ReactNative = {
|
||||||
// top-level API
|
// top-level API
|
||||||
findNodeHandle,
|
findNodeHandle,
|
||||||
render: ReactDOM.render,
|
render,
|
||||||
unmountComponentAtNode: ReactDOM.unmountComponentAtNode,
|
unmountComponentAtNode,
|
||||||
// web-only
|
|
||||||
renderToStaticMarkup: ReactDOMServer.renderToStaticMarkup,
|
|
||||||
renderToString: ReactDOMServer.renderToString,
|
|
||||||
|
|
||||||
// APIs
|
// APIs
|
||||||
Animated,
|
Animated,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component } from 'react';
|
import { Component } from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import findNodeHandle from '../findNodeHandle';
|
||||||
import UIManager from '../../apis/UIManager';
|
import UIManager from '../../apis/UIManager';
|
||||||
|
|
||||||
type MeasureInWindowOnSuccessCallback = (
|
type MeasureInWindowOnSuccessCallback = (
|
||||||
@@ -38,7 +38,7 @@ const NativeMethodsMixin = {
|
|||||||
* Removes focus from an input or view. This is the opposite of `focus()`.
|
* Removes focus from an input or view. This is the opposite of `focus()`.
|
||||||
*/
|
*/
|
||||||
blur() {
|
blur() {
|
||||||
UIManager.blur(ReactDOM.findDOMNode(this));
|
UIManager.blur(findNodeHandle(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -46,7 +46,7 @@ const NativeMethodsMixin = {
|
|||||||
* The exact behavior triggered will depend the type of view.
|
* The exact behavior triggered will depend the type of view.
|
||||||
*/
|
*/
|
||||||
focus() {
|
focus() {
|
||||||
UIManager.focus(ReactDOM.findDOMNode(this));
|
UIManager.focus(findNodeHandle(this));
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,7 +54,7 @@ const NativeMethodsMixin = {
|
|||||||
*/
|
*/
|
||||||
measure(callback: MeasureOnSuccessCallback) {
|
measure(callback: MeasureOnSuccessCallback) {
|
||||||
UIManager.measure(
|
UIManager.measure(
|
||||||
ReactDOM.findDOMNode(this),
|
findNodeHandle(this),
|
||||||
mountSafeCallback(this, callback)
|
mountSafeCallback(this, callback)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -76,7 +76,7 @@ const NativeMethodsMixin = {
|
|||||||
*/
|
*/
|
||||||
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
|
measureInWindow(callback: MeasureInWindowOnSuccessCallback) {
|
||||||
UIManager.measureInWindow(
|
UIManager.measureInWindow(
|
||||||
ReactDOM.findDOMNode(this),
|
findNodeHandle(this),
|
||||||
mountSafeCallback(this, callback)
|
mountSafeCallback(this, callback)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -90,7 +90,7 @@ const NativeMethodsMixin = {
|
|||||||
onFail: () => void /* currently unused */
|
onFail: () => void /* currently unused */
|
||||||
) {
|
) {
|
||||||
UIManager.measureLayout(
|
UIManager.measureLayout(
|
||||||
ReactDOM.findDOMNode(this),
|
findNodeHandle(this),
|
||||||
relativeToNativeNode,
|
relativeToNativeNode,
|
||||||
mountSafeCallback(this, onFail),
|
mountSafeCallback(this, onFail),
|
||||||
mountSafeCallback(this, onSuccess)
|
mountSafeCallback(this, onSuccess)
|
||||||
@@ -102,7 +102,7 @@ const NativeMethodsMixin = {
|
|||||||
*/
|
*/
|
||||||
setNativeProps(nativeProps: Object) {
|
setNativeProps(nativeProps: Object) {
|
||||||
UIManager.updateView(
|
UIManager.updateView(
|
||||||
ReactDOM.findDOMNode(this),
|
findNodeHandle(this),
|
||||||
nativeProps,
|
nativeProps,
|
||||||
this
|
this
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Dimensions = require('../../apis/Dimensions');
|
var Dimensions = require('../../apis/Dimensions');
|
||||||
|
var findNodeHandle = require('../findNodeHandle');
|
||||||
var Platform = require('../../apis/Platform');
|
var Platform = require('../../apis/Platform');
|
||||||
var React = require('react');
|
var React = require('react');
|
||||||
var ReactDOM = require('react-dom');
|
|
||||||
// var Subscribable = require('../Subscribable');
|
// var Subscribable = require('../Subscribable');
|
||||||
var TextInputState = require('../../components/TextInput/TextInputState');
|
var TextInputState = require('../../components/TextInput/TextInputState');
|
||||||
var UIManager = require('../../apis/UIManager');
|
var UIManager = require('../../apis/UIManager');
|
||||||
@@ -356,7 +356,7 @@ var ScrollResponderMixin = {
|
|||||||
scrollResponderGetScrollableNode: function(): any {
|
scrollResponderGetScrollableNode: function(): any {
|
||||||
return this.getScrollableNode ?
|
return this.getScrollableNode ?
|
||||||
this.getScrollableNode() :
|
this.getScrollableNode() :
|
||||||
ReactDOM.findDOMNode(this);
|
findNodeHandle(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -423,7 +423,7 @@ var ScrollResponderMixin = {
|
|||||||
this.preventNegativeScrollOffset = !!preventNegativeScrollOffset;
|
this.preventNegativeScrollOffset = !!preventNegativeScrollOffset;
|
||||||
UIManager.measureLayout(
|
UIManager.measureLayout(
|
||||||
nodeHandle,
|
nodeHandle,
|
||||||
ReactDOM.findDOMNode(this.getInnerViewNode()),
|
findNodeHandle(this.getInnerViewNode()),
|
||||||
this.scrollResponderTextInputFocusError,
|
this.scrollResponderTextInputFocusError,
|
||||||
this.scrollResponderInputMeasureAndScrollToKeyboard
|
this.scrollResponderInputMeasureAndScrollToKeyboard
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,3 +1,2 @@
|
|||||||
import ReactDOM from 'react-dom';
|
import findNodeHandle from 'react/lib/findDOMNode';
|
||||||
const findNodeHandle = ReactDOM.findDOMNode;
|
|
||||||
export default findNodeHandle;
|
export default findNodeHandle;
|
||||||
|
|||||||
@@ -8,6 +8,16 @@ module.exports = {
|
|||||||
entry: {
|
entry: {
|
||||||
main: DIST_DIRECTORY
|
main: DIST_DIRECTORY
|
||||||
},
|
},
|
||||||
|
externals: [
|
||||||
|
{
|
||||||
|
react: {
|
||||||
|
root: 'React',
|
||||||
|
commonjs2: 'react',
|
||||||
|
commonjs: 'react',
|
||||||
|
amd: 'react'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
output: {
|
output: {
|
||||||
filename: 'ReactNative.js',
|
filename: 'ReactNative.js',
|
||||||
library: 'ReactNative',
|
library: 'ReactNative',
|
||||||
|
|||||||
Reference in New Issue
Block a user