Files
react-native/RNTester/js/components/RNTesterExampleContainer.js
T
AndreiCalazans 3945f10561 - Update folder structure of RNTester's JS directory. (#25013)
Summary:
Changes RNTester, first attempt in the direction of improving the RNTester overall. Related ticket: #24647

Changed the `js` directory of the RNTester to have the following structure:
```
- js
    - assets
    - components
    - examples
    - types
    - utils
```
* **assets**
_Any images, gifs, and media content_

* **components**
_All shared components_

* **examples**
_Example View/Components to be rendered by the App_

 * **types**
_Shared flow types_

 * **utils**
_Shared utilities_

## Changelog

[General] [Changed] - Update folder structure of RNTester's JS directory.
Pull Request resolved: https://github.com/facebook/react-native/pull/25013

Differential Revision: D15515773

Pulled By: cpojer

fbshipit-source-id: 0e4b6386127f338dca0ffe8c237073be53a9e221
2019-05-28 08:39:18 -07:00

71 lines
1.7 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const React = require('react');
const {Platform} = require('react-native');
const RNTesterBlock = require('./RNTesterBlock');
const RNTesterExampleFilter = require('./RNTesterExampleFilter');
const RNTesterPage = require('./RNTesterPage');
class RNTesterExampleContainer extends React.Component {
renderExample(example, i) {
// Filter platform-specific examples
const {description, platform} = example;
let {title} = example;
if (platform) {
if (Platform.OS !== platform) {
return null;
}
title += ' (' + platform + ' only)';
}
return (
<RNTesterBlock key={i} title={title} description={description}>
{example.render()}
</RNTesterBlock>
);
}
render(): React.Element<any> {
if (this.props.module.examples.length === 1) {
return (
<RNTesterPage title={this.props.title}>
{this.renderExample(this.props.module.examples[0])}
</RNTesterPage>
);
}
const filter = ({example, filterRegex}) => filterRegex.test(example.title);
const sections = [
{
data: this.props.module.examples,
title: 'EXAMPLES',
key: 'e',
},
];
return (
<RNTesterPage title={this.props.title}>
<RNTesterExampleFilter
testID="example_search"
sections={sections}
filter={filter}
render={({filteredSections}) =>
filteredSections[0].data.map(this.renderExample)
}
/>
</RNTesterPage>
);
}
}
module.exports = RNTesterExampleContainer;