From c16fce1ad21109eda9064e661e89e0e2a0e2591e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Villeneuve?= Date: Wed, 16 Aug 2017 10:52:01 +0200 Subject: [PATCH] Add custom component overlay and a few more config options --- README.md | 31 ++++++++++++++++++++++++++++--- index.js | 5 +++-- src/BetterList.js | 1 + src/Pagination/SwiperThumb.js | 2 +- src/Slide.js | 13 ++++++++----- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d6d8304..d124e59 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,18 @@ import Gallery from 'react-native-photo-gallery'; class YourGalleryComponent extends Component { render() { const data = [ - { id: 'first image', image: require('./yourImage.jpg') } - { id: 'Second image', image: require('./yourImage2.jpg') } + { + id: 'first image', + image: require('./yourImage.jpg'), + thumb: require('./yourImageThumb.jpg'), + overlay: + }, + { + id: 'Second image', + image: require('./yourImage2.jpg'), + thumb: require('./yourImageThumb2.jpg'), + overlay: + } ]; return ; @@ -36,4 +46,19 @@ It is up to you to render a header, navigation bar, etc. | Props | Type | Description | |-------------------|-----------------|--------------------------------------------------------------------------------------------| | `backgroundColor` | `String` | Changing the background color of gallery and pagination | -| `data` | Array of object | Must match the following format `{ id: uniqueKey, image: (cf react-native image source) }` | +| `data` | Array of object | See `Data` below | +| `initialPaginationSize` | `Number` | Default to 10 | +| `initialNumToRender` | `Number` | Default to 4 | +| `overlay` | `Component` | If present, a view that will be displayed above the image | + +## Data object + +Data prop an array objects that will configure slides. +You can provide the following props. + +| Key | Type | Required | Description | +|-------------------|-----------------|--------------------------------------------------------------------------------------------|----| +| `id` | `String` | Yes | A unique identifier +| `image` | `Image source` | Yes | See `` on react native documentation. | +| `thumb` | `Image source` | No | Will be used as a thumbnail on pagination, will default to `image`if not provided | +| `overlay` | `Component` | No | A view that will be displayed above the image, for metas infos for example | diff --git a/index.js b/index.js index 4c6323c..b98c459 100644 --- a/index.js +++ b/index.js @@ -51,7 +51,7 @@ export default class Gallery extends Component { style={styles.swiper} data={data} horizontal - initialNumToRender={4} + initialNumToRender={this.props.initialNumToRender||4} ref={ref => this.swiper = ref} pagingEnabled onMomentumScrollEnd={this.onScrollEnd.bind(this)} @@ -62,6 +62,7 @@ export default class Gallery extends Component { @@ -76,7 +77,7 @@ Gallery.propTypes = { data: PropTypes.arrayOf((propValue, key) => { if (!propValue[key].id || !propValue[key].image) { return new Error( - 'Data prop is invalid. It must be an object containing "id" and "data" keys.' + 'Data prop is invalid. It must be an object containing "id" and "image" keys.' ); } }) diff --git a/src/BetterList.js b/src/BetterList.js index 4d3a3cc..97bd96c 100644 --- a/src/BetterList.js +++ b/src/BetterList.js @@ -23,6 +23,7 @@ export default class BetterList extends Component { this.pagination = sc} + initialListSize={this.props.initialPaginationSize} dataSource={this.state.dataSource} /> ); diff --git a/src/Pagination/SwiperThumb.js b/src/Pagination/SwiperThumb.js index 468413e..16b51b0 100644 --- a/src/Pagination/SwiperThumb.js +++ b/src/Pagination/SwiperThumb.js @@ -14,7 +14,7 @@ class SwiperThumb extends Component { > ); diff --git a/src/Slide.js b/src/Slide.js index fe85873..f4008be 100644 --- a/src/Slide.js +++ b/src/Slide.js @@ -1,6 +1,6 @@ +import React, { Component } from 'react'; import { ActivityIndicator, Dimensions, View } from 'react-native'; import PhotoView from 'react-native-photo-view'; -import React, { Component } from 'react'; const styles = { slideC: { @@ -22,6 +22,11 @@ const styles = { export class Slide extends Component { render() { + const inside = { + width: Dimensions.get('window').width, + height: Dimensions.get('window').height - 128, + }; + return ( + {this.props.item.overlay} ); }