From 11027351b9637721458546b5b401eb36504bd503 Mon Sep 17 00:00:00 2001 From: Valery Buchinsky Date: Thu, 21 Sep 2017 17:25:12 +0300 Subject: [PATCH 1/4] Allow passing flatListProps. #19 Set the windowSize property of FlatList to default 3. --- src/Gallery.js | 8 ++++++-- src/libraries/ViewPager/index.js | 7 +++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Gallery.js b/src/Gallery.js index 138a0a4..8a2f8db 100644 --- a/src/Gallery.js +++ b/src/Gallery.js @@ -19,13 +19,17 @@ export default class Gallery extends PureComponent { onLongPress: PropTypes.func, removeClippedSubviews: PropTypes.bool, imageComponent: PropTypes.func, - errorComponent: PropTypes.func + errorComponent: PropTypes.func, + flatListProps: PropTypes.object, }; static defaultProps = { removeClippedSubviews: true, imageComponent: undefined, - scrollViewStyle: {} + scrollViewStyle: {}, + flatListProps: { + windowSize: 3, + } }; imageRefs = new Map(); diff --git a/src/libraries/ViewPager/index.js b/src/libraries/ViewPager/index.js index d95314e..31a2115 100644 --- a/src/libraries/ViewPager/index.js +++ b/src/libraries/ViewPager/index.js @@ -18,7 +18,8 @@ export default class ViewPager extends PureComponent { removeClippedSubviews: PropTypes.bool, onPageSelected: PropTypes.func, onPageScrollStateChanged: PropTypes.func, - onPageScroll: PropTypes.func + onPageScroll: PropTypes.func, + flatListProps: PropTypes.object, }; static defaultProps = { @@ -27,7 +28,8 @@ export default class ViewPager extends PureComponent { scrollEnabled: true, pageDataArray: [], initialListSize: 10, - removeClippedSubviews: true + removeClippedSubviews: true, + flatListProps: {}, }; pageCount = 0; // Initialize to avoid undefined error @@ -255,6 +257,7 @@ export default class ViewPager extends PureComponent { style={[style, { flex: 1 }]} {...gestureResponder}> Date: Mon, 25 Sep 2017 11:48:06 +0300 Subject: [PATCH 2/4] Merge flatListProps #19 --- src/Gallery.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Gallery.js b/src/Gallery.js index 8a2f8db..d71525e 100644 --- a/src/Gallery.js +++ b/src/Gallery.js @@ -4,6 +4,10 @@ import { createResponder } from 'react-native-gesture-responder'; import TransformableImage from './libraries/TransformableImage'; import ViewPager from './libraries/ViewPager'; +const DEFAULT_FLAT_LIST_PROPS = { + windowSize: 3, +}; + export default class Gallery extends PureComponent { static propTypes = { ...View.propTypes, @@ -27,9 +31,7 @@ export default class Gallery extends PureComponent { removeClippedSubviews: true, imageComponent: undefined, scrollViewStyle: {}, - flatListProps: { - windowSize: 3, - } + flatListProps: DEFAULT_FLAT_LIST_PROPS, }; imageRefs = new Map(); @@ -265,9 +267,12 @@ export default class Gallery extends PureComponent { gestureResponder = {}; } + const flatListProps = Object.assign(DEFAULT_FLAT_LIST_PROPS, this.props.flatListProps) + return ( Date: Mon, 25 Sep 2017 18:20:49 +0300 Subject: [PATCH 3/4] Follow instructions and use ... instead of Object.assign :art: #19 --- src/Gallery.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gallery.js b/src/Gallery.js index d71525e..981c751 100644 --- a/src/Gallery.js +++ b/src/Gallery.js @@ -267,7 +267,7 @@ export default class Gallery extends PureComponent { gestureResponder = {}; } - const flatListProps = Object.assign(DEFAULT_FLAT_LIST_PROPS, this.props.flatListProps) + const flatListProps = {...DEFAULT_FLAT_LIST_PROPS, ...this.props.flatListProps}; return ( Date: Tue, 26 Sep 2017 12:15:08 +0300 Subject: [PATCH 4/4] Describe the flatListProps prop :bulb: #19 --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 39ac0e2..174cd8c 100644 --- a/README.md +++ b/README.md @@ -66,11 +66,12 @@ Prop | Description | Type | Default `initialPage` | Image displayed first | `number` | `0` `imageComponent` | Custom function to render your images, 1st param is the image props, 2nd is its dimensions | `function` | `` component `errorComponent` | Custom function to render the page of an image that couldn't be displayed | `function` | A `` with a stylized error +`flatListProps` | Props to be passed to the underlying `FlatList` | `object` | `{windowSize: 3}` `pageMargin` | Blank space to show between images | `number` | `0` `onPageSelected` | Fired with the index of page that has been selected | `function` `onPageScrollStateChanged` | Called when page scrolling state has changed, see [scroll state and events](#scroll-state-and-events) | `function` `onPageScroll` | Scroll event, see [scroll state and events](#scroll-state-and-events) | `function` -`scrollViewStyle` | Custom style for the `FlastList` component | `object` | `{}` +`scrollViewStyle` | Custom style for the `FlatList` component | `object` | `{}` `onSingleTapConfirmed` | Fired after a single tap | `function` `onLongPress` | Fire after a long press | `function` @@ -90,4 +91,4 @@ Prop | Description | Type | Default * `'idle'`: there is no interaction with the page scroller happening at the time. * `'dragging'`: there is currently an interaction with the page scroller. - * `'settling'`: there was an interaction with the page scroller, and the page scroller is now finishing it's closing or opening animation. \ No newline at end of file + * `'settling'`: there was an interaction with the page scroller, and the page scroller is now finishing it's closing or opening animation.