From 7ee39d6602d293a00c7656aa3313995a8aefcb8a Mon Sep 17 00:00:00 2001 From: Nadav Luzzato Date: Tue, 14 Jul 2020 18:30:40 +0300 Subject: [PATCH 1/2] Added renderButtonsAfterOnLayout prop, to delay the rendering of the buttons to the stage where we have the width of the overlay item. --- src/index.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index d77cf98..3cd82b6 100644 --- a/src/index.js +++ b/src/index.js @@ -74,6 +74,7 @@ export default class Swipeable extends PureComponent { onRef: PropTypes.func, onPanAnimatedValueRef: PropTypes.func, swipeStartMinDistance: PropTypes.number, + renderButtonsAfterOnLayout: PropTypes.bool, // styles style: ViewPropTypes.style, @@ -151,7 +152,9 @@ export default class Swipeable extends PureComponent { // misc onRef: noop, onPanAnimatedValueRef: noop, - swipeStartMinDistance: 15 + swipeStartMinDistance: 15, + renderButtonsAfterOnLayout: false, + }; state = { @@ -560,8 +563,13 @@ export default class Swipeable extends PureComponent { } _renderButtons(buttons, isLeftButtons) { - const {leftButtonContainerStyle, rightButtonContainerStyle} = this.props; + const {leftButtonContainerStyle, rightButtonContainerStyle, renderButtonsAfterOnLayout} = this.props; const {pan, width} = this.state; + + if (renderButtonsAfterOnLayout && width === 0) { + return null; + } + const canSwipeLeft = this._canSwipeLeft(); const canSwipeRight = this._canSwipeRight(); const count = buttons.length; From d27081330b0b88aa2af4194d802a06ad877cef67 Mon Sep 17 00:00:00 2001 From: Nadav Luzzato Date: Tue, 14 Jul 2020 18:43:04 +0300 Subject: [PATCH 2/2] added prepare package json directive --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index cb0e27d..568e07c 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "description": "A powerful React Native swipe component", "main": "lib/index.js", "scripts": { + "prepare": "make build", "build": "make build", "lint": "make lint" },