Merge pull request #135 from lbryio/navigation-perf

replaced FeaturedCategory with SectionList on discover page to improve performance
This commit is contained in:
akinwale 2018-05-21 19:02:36 +01:00 committed by GitHub
commit 1b77a8dd8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 53 deletions

View file

@ -1,7 +0,0 @@
import { connect } from 'react-redux';
import FeaturedCategory from './view';
const select = state => ({});
const perform = dispatch => ({});
export default connect(select, perform)(FeaturedCategory);

View file

@ -1,27 +0,0 @@
import React from 'react';
import { Text, View } from 'react-native';
import { normalizeURI } from 'lbry-redux';
import FileItem from '../fileItem';
import discoverStyle from '../../styles/discover';
class FeaturedCategory extends React.PureComponent {
render() {
const { category, names, categoryLink, navigation } = this.props;
return (
<View>
<Text style={discoverStyle.categoryName}>{category}</Text>
{names &&
names.map(name => (
<FileItem
style={discoverStyle.fileItem}
key={name}
uri={normalizeURI(name)}
navigation={navigation} />
))}
</View>
);
}
}
export default FeaturedCategory;

View file

@ -1,8 +1,16 @@
import React from 'react'; import React from 'react';
import FeaturedCategory from '../../component/featuredCategory';
import NavigationActions from 'react-navigation'; import NavigationActions from 'react-navigation';
import { AsyncStorage, NativeModules, ScrollView, Text, View } from 'react-native'; import {
AsyncStorage,
NativeModules,
SectionList,
ScrollView,
Text,
View
} from 'react-native';
import { normalizeURI } from 'lbry-redux';
import moment from 'moment'; import moment from 'moment';
import FileItem from '../../component/fileItem';
import discoverStyle from '../../styles/discover'; import discoverStyle from '../../styles/discover';
import Feather from 'react-native-vector-icons/Feather'; import Feather from 'react-native-vector-icons/Feather';
@ -34,7 +42,7 @@ class DiscoverPage extends React.PureComponent {
} }
render() { render() {
const { featuredUris, fetchingFeaturedUris } = this.props; const { featuredUris, fetchingFeaturedUris, navigation } = this.props;
const hasContent = typeof featuredUris === 'object' && Object.keys(featuredUris).length, const hasContent = typeof featuredUris === 'object' && Object.keys(featuredUris).length,
failedToLoad = !fetchingFeaturedUris && !hasContent; failedToLoad = !fetchingFeaturedUris && !hasContent;
@ -42,22 +50,21 @@ class DiscoverPage extends React.PureComponent {
<View style={discoverStyle.container}> <View style={discoverStyle.container}>
{!hasContent && fetchingFeaturedUris && <Text style={discoverStyle.title}>Fetching content...</Text>} {!hasContent && fetchingFeaturedUris && <Text style={discoverStyle.title}>Fetching content...</Text>}
{hasContent && {hasContent &&
<ScrollView style={discoverStyle.scrollContainer}> <SectionList style={discoverStyle.scrollContainer}
{hasContent && renderItem={ ({item, index, section}) => (
Object.keys(featuredUris).map( <FileItem
category => style={discoverStyle.fileItem}
featuredUris[category].length ? ( key={item}
<FeaturedCategory uri={normalizeURI(item)}
key={category} navigation={navigation} />
category={category} )
names={featuredUris[category]} }
navigation={this.props.navigation} renderSectionHeader={
/> ({section: {title}}) => (<Text style={discoverStyle.categoryName}>{title}</Text>)
) : ( }
'' sections={Object.keys(featuredUris).map(category => ({ title: category, data: featuredUris[category] }))}
) keyExtractor={(item, index) => item}
)} />
</ScrollView>
} }
</View> </View>
); );