Skip to content

Commit

Permalink
Disable cache images in search
Browse files Browse the repository at this point in the history
  • Loading branch information
isdenmois committed Jun 23, 2019
1 parent 2f2b642 commit b45b98a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
-keep public class com.dylanvann.fastimage.* {*;}
-keep public class com.dylanvann.fastimage.** {*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public class * extends com.bumptech.glide.module.AppGlideModule
-keep public enum com.bumptech.glide.load.ImageHeaderParser$** {
Expand Down
14 changes: 13 additions & 1 deletion src/components/book-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ interface Props extends Partial<NavigationScreenProps> {
record?: Book;
book?: Book;
nextStatus?: BOOK_STATUSES;
cacheThumbnail?: boolean;
}

@withObservables(['book'], ({ book }) => ({
record: book.record || book,
}))
export class BookItem extends React.PureComponent<Props> {
static defaultProps: Props = { cacheThumbnail: true };

get book() {
return this.props.record || this.props.book;
}
Expand All @@ -53,12 +56,21 @@ export class BookItem extends React.PureComponent<Props> {
const nextStatus = this.nextStatus;
const statusIcon = book.status === BOOK_STATUSES.READ ? 'star' : STATUS_ICONS[nextStatus];
const statusColor = STATUS_COLORS[statusIcon];
const cache = this.props.cacheThumbnail;

return (
<View style={s.container}>
<TouchableOpacity style={s.thumbnailView} onPress={this.openBook}>
<View style={s.thumbnail}>
<Thumbnail auto={null} style={s.image} width={65} height={100} title={book.title} url={book.thumbnail} />
<Thumbnail
cache={cache}
auto={null}
style={s.image}
width={65}
height={100}
title={book.title}
url={book.thumbnail}
/>
</View>
</TouchableOpacity>

Expand Down
8 changes: 6 additions & 2 deletions src/components/thumbnail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ interface Props {
auto?: string;
style?: ImageStyle;
resizeMode?: Image.ResizeMode;
cache?: boolean;
}

export function Thumbnail({ auto, style, title, width, height, url, resizeMode }: Props) {
export function Thumbnail({ auto, style, title, width, height, url, resizeMode, cache }: Props) {
if (!url) {
return <Avatar style={style} width={width} height={height} title={title} />;
}
Expand All @@ -28,9 +29,12 @@ export function Thumbnail({ auto, style, title, width, height, url, resizeMode }
return <AutoWithImage width={width} height={height} style={style} url={url} />;
}

return <Image style={[style, { width, height }]} source={{ uri: url }} resizeMode={resizeMode} />;
const source = { uri: url, cache: cache ? Image.cacheControl.immutable : Image.cacheControl.web };

return <Image style={[style, { width, height }]} source={source} resizeMode={resizeMode} />;
}

Thumbnail.defaultProps = {
auto: 'height',
cache: true,
};
2 changes: 1 addition & 1 deletion src/screens/search/search.screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class SearchScreen extends React.Component<NavigationScreenProps, State>
return (
<ScrollView contentContainerStyle={s.scroll}>
{_.map(data, book => (
<BookItem book={book} key={book.id} navigation={this.props.navigation} />
<BookItem cacheThumbnail={false} book={book} key={book.id} navigation={this.props.navigation} />
))}
</ScrollView>
);
Expand Down

0 comments on commit b45b98a

Please sign in to comment.