From f2ae24b057e39fc5ed81ac614176ecd5e7f4a039 Mon Sep 17 00:00:00 2001 From: Caleb Harrelson Date: Thu, 13 Aug 2020 23:43:57 -0500 Subject: [PATCH 1/3] Fix autoPlay HOC swallowing third parameter of onChangeIndex --- packages/react-swipeable-views-utils/src/autoPlay.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-swipeable-views-utils/src/autoPlay.js b/packages/react-swipeable-views-utils/src/autoPlay.js index 40f92d0d..48d7976e 100644 --- a/packages/react-swipeable-views-utils/src/autoPlay.js +++ b/packages/react-swipeable-views-utils/src/autoPlay.js @@ -82,7 +82,7 @@ export default function autoPlay(MyComponent) { } }; - handleChangeIndex = (index, indexLatest) => { + handleChangeIndex = (index, indexLatest, meta) => { // Is uncontrolled if (this.props.index === undefined) { this.setState({ @@ -91,7 +91,7 @@ export default function autoPlay(MyComponent) { } if (this.props.onChangeIndex) { - this.props.onChangeIndex(index, indexLatest); + this.props.onChangeIndex(index, indexLatest, meta); } }; From 57f909c0abd7baa3d28f076ef669050a2e2af2fc Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 13 Feb 2021 18:36:34 +0100 Subject: [PATCH 2/3] handle all the cases --- packages/react-swipeable-views-utils/src/bindKeyboard.js | 4 ++-- packages/react-swipeable-views-utils/src/virtualize.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/react-swipeable-views-utils/src/bindKeyboard.js b/packages/react-swipeable-views-utils/src/bindKeyboard.js index 4e653174..88cc10f4 100644 --- a/packages/react-swipeable-views-utils/src/bindKeyboard.js +++ b/packages/react-swipeable-views-utils/src/bindKeyboard.js @@ -119,7 +119,7 @@ export default function bindKeyboard(MyComponent) { } }; - handleChangeIndex = (index, indexLatest) => { + handleChangeIndex = (index, indexLatest, meta) => { // Is uncontrolled if (this.props.index === undefined) { this.setState({ @@ -128,7 +128,7 @@ export default function bindKeyboard(MyComponent) { } if (this.props.onChangeIndex) { - this.props.onChangeIndex(index, indexLatest); + this.props.onChangeIndex(index, indexLatest, meta); } }; diff --git a/packages/react-swipeable-views-utils/src/virtualize.js b/packages/react-swipeable-views-utils/src/virtualize.js index 5f7b414e..90369c40 100644 --- a/packages/react-swipeable-views-utils/src/virtualize.js +++ b/packages/react-swipeable-views-utils/src/virtualize.js @@ -96,7 +96,7 @@ export default function virtualize(MyComponent) { }); } - handleChangeIndex = (indexContainer, indexLatest) => { + handleChangeIndex = (indexContainer, indexLatest, meta) => { const { slideCount, onChangeIndex } = this.props; const indexDiff = indexContainer - indexLatest; @@ -112,7 +112,7 @@ export default function virtualize(MyComponent) { } if (onChangeIndex) { - onChangeIndex(index, this.state.index); + onChangeIndex(index, this.state.index, meta); } }; From 3244aa21b6b2824f2361d892a20cca676bebe501 Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Sat, 13 Feb 2021 18:37:44 +0100 Subject: [PATCH 3/3] fix tests --- packages/react-swipeable-views-utils/src/autoPlay.test.js | 2 +- packages/react-swipeable-views-utils/src/bindKeyboard.test.js | 2 +- packages/react-swipeable-views-utils/src/virtualize.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-swipeable-views-utils/src/autoPlay.test.js b/packages/react-swipeable-views-utils/src/autoPlay.test.js index 9aefa8a6..1cf3158f 100644 --- a/packages/react-swipeable-views-utils/src/autoPlay.test.js +++ b/packages/react-swipeable-views-utils/src/autoPlay.test.js @@ -39,7 +39,7 @@ describe('autoPlay', () => { onChangeIndex: handleChangeIndex, }); wrapper.find(Empty).simulate('changeIndex', 1, 0); - assert.deepEqual(handleChangeIndex.args, [[1, 0]]); + assert.deepEqual(handleChangeIndex.args, [[1, 0, undefined]]); assert.strictEqual(wrapper.state().index, 0, 'should not update the state index'); }); }); diff --git a/packages/react-swipeable-views-utils/src/bindKeyboard.test.js b/packages/react-swipeable-views-utils/src/bindKeyboard.test.js index 5cbcc4eb..396978ff 100644 --- a/packages/react-swipeable-views-utils/src/bindKeyboard.test.js +++ b/packages/react-swipeable-views-utils/src/bindKeyboard.test.js @@ -88,7 +88,7 @@ describe('bindKeyboard', () => { onChangeIndex: handleChangeIndex, }); wrapper.find(Empty).simulate('changeIndex', 1, 0); - assert.deepEqual(handleChangeIndex.args, [[1, 0]]); + assert.deepEqual(handleChangeIndex.args, [[1, 0, undefined]]); assert.strictEqual(wrapper.state().index, 0, 'should no update the state index'); }); }); diff --git a/packages/react-swipeable-views-utils/src/virtualize.test.js b/packages/react-swipeable-views-utils/src/virtualize.test.js index b1e8d6ec..dce9ad9b 100644 --- a/packages/react-swipeable-views-utils/src/virtualize.test.js +++ b/packages/react-swipeable-views-utils/src/virtualize.test.js @@ -280,7 +280,7 @@ describe('virtualize', () => { ); wrapper.find(Empty).simulate('changeIndex', 1, 0); - assert.deepEqual(handleChangeIndex.args, [[11, 10]]); + assert.deepEqual(handleChangeIndex.args, [[11, 10, undefined]]); assert.strictEqual(wrapper.state().index, 10, 'should not update the state index'); }); });