mirror of
https://github.com/status-im/react-native.git
synced 2025-02-24 15:18:10 +00:00
Summary: Fixes a bug introduced with the example filtering in D13561744 causing the Camera Roll example to not show any pictures Reviewed By: JoshuaGross Differential Revision: D13622124 fbshipit-source-id: a5863dcdd9f89ae1373910f25b38e4a322796dbe
71 lines
1.7 KiB
JavaScript
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;
|