mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
Updates from Wed 25 Mar
- [ReactNative] Add snapshot tests for examples | Spencer Ahrens - [ReactNative] bring back some native modules | Spencer Ahrens
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
var React = require('react-native');
|
||||
var {
|
||||
AppRegistry,
|
||||
ListView,
|
||||
PixelRatio,
|
||||
ScrollView,
|
||||
@@ -23,6 +24,8 @@ var {
|
||||
} = React;
|
||||
var ReactNavigatorExample = require('./ReactNavigator/ReactNavigatorExample');
|
||||
|
||||
var { TestModule } = React.addons;
|
||||
|
||||
var createExamplePage = require('./createExamplePage');
|
||||
|
||||
var COMPONENTS = [
|
||||
@@ -69,6 +72,33 @@ var ds = new ListView.DataSource({
|
||||
sectionHeaderHasChanged: (h1, h2) => h1 !== h2,
|
||||
});
|
||||
|
||||
function makeRenderable(example: any): ReactClass<any, any, any> {
|
||||
return example.examples ?
|
||||
createExamplePage(null, example) :
|
||||
example;
|
||||
}
|
||||
|
||||
// Register suitable examples for snapshot tests
|
||||
COMPONENTS.concat(APIS).forEach((Example) => {
|
||||
if (Example.displayName) {
|
||||
var Snapshotter = React.createClass({
|
||||
componentDidMount: function() {
|
||||
// View is still blank after first RAF :\
|
||||
global.requestAnimationFrame(() =>
|
||||
global.requestAnimationFrame(() => TestModule.verifySnapshot(
|
||||
TestModule.markTestCompleted
|
||||
)
|
||||
));
|
||||
},
|
||||
render: function() {
|
||||
var Renderable = makeRenderable(Example);
|
||||
return <Renderable />;
|
||||
},
|
||||
});
|
||||
AppRegistry.registerComponent(Example.displayName, () => Snapshotter);
|
||||
}
|
||||
});
|
||||
|
||||
class UIExplorerList extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
@@ -152,9 +182,7 @@ class UIExplorerList extends React.Component {
|
||||
);
|
||||
return;
|
||||
}
|
||||
var Component = example.examples ?
|
||||
createExamplePage(null, example) :
|
||||
example;
|
||||
var Component = makeRenderable(example);
|
||||
this.props.navigator.push({
|
||||
title: Component.title,
|
||||
component: Component,
|
||||
|
||||
Reference in New Issue
Block a user