2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-28 05:18:47 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 20:35:08 +00:00
|
|
|
*
|
2015-03-28 05:18:47 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-02-20 04:10:52 +00:00
|
|
|
*
|
|
|
|
* @providesModule createExamplePage
|
2015-03-24 20:25:39 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var React = require('react-native');
|
2015-09-01 12:08:25 +00:00
|
|
|
var {
|
|
|
|
Platform,
|
|
|
|
} = React;
|
2015-05-08 16:45:43 +00:00
|
|
|
var ReactNative = require('ReactNative');
|
2015-02-20 04:10:52 +00:00
|
|
|
var UIExplorerBlock = require('./UIExplorerBlock');
|
|
|
|
var UIExplorerPage = require('./UIExplorerPage');
|
|
|
|
|
|
|
|
var invariant = require('invariant');
|
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
import type { Example, ExampleModule } from 'ExampleTypes';
|
2015-03-24 20:25:39 +00:00
|
|
|
|
|
|
|
var createExamplePage = function(title: ?string, exampleModule: ExampleModule)
|
|
|
|
: ReactClass<any, any, any> {
|
2015-02-20 04:10:52 +00:00
|
|
|
invariant(!!exampleModule.examples, 'The module must have examples');
|
|
|
|
|
|
|
|
var ExamplePage = React.createClass({
|
|
|
|
statics: {
|
|
|
|
title: exampleModule.title,
|
|
|
|
description: exampleModule.description,
|
|
|
|
},
|
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
getBlock: function(example: Example, i) {
|
2015-09-01 12:08:25 +00:00
|
|
|
if (example.platform) {
|
|
|
|
if (Platform.OS !== example.platform) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
example.title += ' (' + example.platform + ' only)';
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
// Hack warning: This is a hack because the www UI explorer requires
|
|
|
|
// renderComponent to be called.
|
|
|
|
var originalRender = React.render;
|
2015-04-30 06:33:19 +00:00
|
|
|
var originalRenderComponent = React.renderComponent;
|
2015-05-08 16:45:43 +00:00
|
|
|
var originalIOSRender = ReactNative.render;
|
|
|
|
var originalIOSRenderComponent = ReactNative.renderComponent;
|
2015-02-20 04:10:52 +00:00
|
|
|
var renderedComponent;
|
2015-03-24 20:25:39 +00:00
|
|
|
// TODO remove typecasts when Flow bug #6560135 is fixed
|
|
|
|
// and workaround is removed from react-native.js
|
2015-04-30 06:33:19 +00:00
|
|
|
(React: Object).render =
|
|
|
|
(React: Object).renderComponent =
|
2015-05-08 16:45:43 +00:00
|
|
|
(ReactNative: Object).render =
|
|
|
|
(ReactNative: Object).renderComponent =
|
2015-04-30 06:33:19 +00:00
|
|
|
function(element, container) {
|
|
|
|
renderedComponent = element;
|
|
|
|
};
|
2015-02-20 04:10:52 +00:00
|
|
|
var result = example.render(null);
|
|
|
|
if (result) {
|
2015-07-24 00:50:16 +00:00
|
|
|
renderedComponent = React.cloneElement(result, {
|
|
|
|
navigator: this.props.navigator,
|
|
|
|
});
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
2015-03-24 20:25:39 +00:00
|
|
|
(React: Object).render = originalRender;
|
2015-04-30 06:33:19 +00:00
|
|
|
(React: Object).renderComponent = originalRenderComponent;
|
2015-05-08 16:45:43 +00:00
|
|
|
(ReactNative: Object).render = originalIOSRender;
|
|
|
|
(ReactNative: Object).renderComponent = originalIOSRenderComponent;
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<UIExplorerBlock
|
|
|
|
key={i}
|
|
|
|
title={example.title}
|
|
|
|
description={example.description}>
|
|
|
|
{renderedComponent}
|
|
|
|
</UIExplorerBlock>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<UIExplorerPage title={title}>
|
|
|
|
{exampleModule.examples.map(this.getBlock)}
|
|
|
|
</UIExplorerPage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return ExamplePage;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = createExamplePage;
|