From e7df03ea35903af9d1a3d6df3799875f358e19f3 Mon Sep 17 00:00:00 2001 From: Brent Vatne Date: Wed, 10 Apr 2019 16:51:21 +0200 Subject: [PATCH] Merge pull request #2 from itsjgf/master Call animateNextTransition only when activeKey has changed --- packages/animated-switch/index.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/animated-switch/index.js b/packages/animated-switch/index.js index 41e67389..35cd8087 100644 --- a/packages/animated-switch/index.js +++ b/packages/animated-switch/index.js @@ -13,9 +13,13 @@ class SwitchView extends React.Component { containerRef = React.createRef(); componentDidUpdate(prevProps) { - if (this.props.navigation.state.index !== prevProps.navigation.state.index) { - this.containerRef.current && - this.containerRef.current.animateNextTransition(); + const { state: prevState } = prevProps.navigation; + const prevActiveKey = prevState.routes[prevState.index].key; + const { state } = this.props.navigation; + const activeKey = state.routes[state.index].key; + + if (activeKey !== prevActiveKey && this.containerRef.current) { + this.containerRef.current.animateNextTransition(); } }