From a7c5e105c7f20cee59d443e1274c1b417dd47914 Mon Sep 17 00:00:00 2001 From: Wojciech Lewicki Date: Wed, 14 Apr 2021 13:59:12 +0200 Subject: [PATCH] fix: whitelist supported platforms (#886) Added checks for Android and iOS in index.native.tsx and setting display: 'none' for inactive screens in the fallback. --- src/index.native.tsx | 46 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/src/index.native.tsx b/src/index.native.tsx index 463f50652a..5c8edf6eef 100644 --- a/src/index.native.tsx +++ b/src/index.native.tsx @@ -3,6 +3,7 @@ import { Animated, Image, ImageProps, + Platform, requireNativeComponent, StyleSheet, UIManager, @@ -23,10 +24,13 @@ import { ScreenStackHeaderConfigProps, } from './types'; -let ENABLE_SCREENS = true; +// web implementation is taken from `index.tsx` +const isPlatformSupported = Platform.OS === 'ios' || Platform.OS === 'android'; + +let ENABLE_SCREENS = isPlatformSupported; function enableScreens(shouldEnableScreens = true): void { - ENABLE_SCREENS = shouldEnableScreens; + ENABLE_SCREENS = isPlatformSupported && shouldEnableScreens; if (ENABLE_SCREENS && !UIManager.getViewManagerConfig('RNSScreen')) { console.error( `Screen native module hasn't been linked. Please check the react-native-screens README for more details` @@ -102,12 +106,15 @@ class Screen extends React.Component { render() { const { enabled = ENABLE_SCREENS } = this.props; - if (enabled) { + if (enabled && isPlatformSupported) { AnimatedNativeScreen = AnimatedNativeScreen || Animated.createAnimatedComponent(ScreensNativeModules.NativeScreen); - // same reason as above + // Filter out active prop in this case because it is unused and + // can cause problems depending on react-native version: + // https://github.com/react-navigation/react-navigation/issues/4886 + // same for enabled prop // eslint-disable-next-line @typescript-eslint/no-unused-vars let { enabled, active, activityState, ...rest } = this.props; if (active !== undefined && activityState === undefined) { @@ -124,15 +131,28 @@ class Screen extends React.Component { /> ); } else { - // Filter out active prop in this case because it is unused and - // can cause problems depending on react-native version: - // https://github.com/react-navigation/react-navigation/issues/4886 - // same for enabled prop - - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const { active, enabled, onComponentRef, ...rest } = this.props; + // same reason as above + let { + active, + activityState, + style, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + enabled, + // eslint-disable-next-line @typescript-eslint/no-unused-vars + onComponentRef, + ...rest + } = this.props; - return ; + if (active !== undefined && activityState === undefined) { + activityState = active !== 0 ? 2 : 0; + } + return ( + + ); } } } @@ -141,7 +161,7 @@ class ScreenContainer extends React.Component { render() { const { enabled = ENABLE_SCREENS, ...rest } = this.props; - if (enabled) { + if (enabled && isPlatformSupported) { return ; }