From 56b11d346cad2c3fbff701fe0a8490e77e6dafa2 Mon Sep 17 00:00:00 2001 From: Hein Rutjes Date: Fri, 30 Aug 2019 14:52:01 +0200 Subject: [PATCH] fix: fixed transitions not triggering in release builds --- src/createSharedElementScene.tsx | 15 ++++++++++++- src/createSharedElementStackNavigator.tsx | 26 ++++++++++------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/createSharedElementScene.tsx b/src/createSharedElementScene.tsx index 791b25e..3355d5f 100644 --- a/src/createSharedElementScene.tsx +++ b/src/createSharedElementScene.tsx @@ -18,6 +18,14 @@ type PropsType = { navigation: any; }; +function getActiveRouteState(route: any): any { + if (!route.routes || route.routes.length === 0 || route.index >= route.routes.length) { + return route; + } else { + return getActiveRouteState(route.routes[route.index]); + } +} + function createSharedElementScene( Component: React.ComponentType, rendererData: ISharedElementRendererData @@ -90,7 +98,12 @@ function createSharedElementScene( }; private onDidFocus = () => { - rendererData.didActivateScene(this.sceneData); + const { navigation } = this.props; + const activeRoute = getActiveRouteState(navigation.state); + if (navigation.state.routeName === activeRoute.routeName) { + // console.log('onDidFocus: ', this.sceneData.name, activeRoute, this.props.navigation.state.routeName); + rendererData.didActivateScene(this.sceneData); + } }; } diff --git a/src/createSharedElementStackNavigator.tsx b/src/createSharedElementStackNavigator.tsx index 35b95b3..f763112 100644 --- a/src/createSharedElementStackNavigator.tsx +++ b/src/createSharedElementStackNavigator.tsx @@ -24,20 +24,17 @@ function createSharedElementEnabledNavigator( typeof routeConfig === 'object' && routeConfig.screen ? routeConfig.screen : routeConfig; - if (component.name !== 'Navigator') { - // console.log('Navigator detected, ignoring: ', component); - const wrappedComponent = createSharedElementScene( - component, - rendererData - ); - if (component === routeConfig) { - wrappedRouteConfigs[key] = wrappedComponent; - } else { - wrappedRouteConfigs[key] = { - ...routeConfig, - screen: wrappedComponent, - }; - } + const wrappedComponent = createSharedElementScene( + component, + rendererData + ); + if (component === routeConfig) { + wrappedRouteConfigs[key] = wrappedComponent; + } else { + wrappedRouteConfigs[key] = { + ...routeConfig, + screen: wrappedComponent, + }; } } @@ -81,7 +78,6 @@ function createSharedElementStackNavigator( ); class SharedElementRenderer extends React.Component { - static displayName = 'SharedElementRenderer'; private rendererData?: SharedElementRendererData; render() { return (