React-native-navigation: Can't get overlay interceptTouchOutside option working

Created on 9 Apr 2020  路  6Comments  路  Source: wix/react-native-navigation

Issue Description

I have a little Notification overlay component similar to this one

When it appears, the scroll of the page below is blocked, on both ios and Android.

What did I do wrong?

Steps to Reproduce / Code Snippets / Screenshots

My Code :

const Notification: React.FC<NotificationProps> = (props) => {
    let { message, componentId } = props;

    const _translateY = useRef(new Animated.Value(_initTransY)).current;

    useEffect(() => {

        Animated.spring(
            _translateY,
            {
                toValue: _endTransY
            }
        ).start();

        setTimeout(
            ()=>{
                Animated.spring(
                    _translateY,
                    {
                        toValue: _initTransY
                    }
                ).start(
                    ()=>{ Navigation.dismissOverlay(props.componentId); }
                );
            },
            4000
        );

    }, []);

    return (
            <Animated.View style={[styles.root, { transform: [ { translateY: _translateY } ]}]}>
                <View style={styles.notifWrap}>
                    <Text style={styles.notifText}>{message}</Text>
                </View>
            </Animated.View>
    );
        // <SafeAreaView style={styles.sav}>
        // </SafeAreaView>
};

Notification.options = {
    layout: {
      componentBackgroundColor: 'transparent'
    },
    overlay: {
      interceptTouchOutside: false
    }
}

const styles = StyleSheet.create({
    // sav: {
    //     position : 'absolute',
    //     height: 80, 
    //     backgroundColor: 'red',
    // },
    root: {
        width: '100%',
        height: 80, 
        backgroundColor: 'red',
    },
    notifWrap: {
        height: 60,
        width: '100%',
        elevation: 2,
        backgroundColor: Colors.Bg07,
        alignItems: 'center',
        justifyContent: 'center',
    },
    notifText: {
        fontFamily: Fonts.RobotoRegular,
        color: Colors.Text04,
        textAlign: 'center',
        fontSize: 16,
    }
});

export default Notification;

The way I show the overlay:

export const showNotification = (str:string)=>{
  return Navigation.showOverlay({
    component: {
      name: Screens.Notification,
      passProps: {
        message: str
      },
      options: {
        overlay: {
          interceptTouchOutside: false,
        },
        layout: {
          backgroundColor: 'transparent',
          componentBackgroundColor: 'transparent',
          orientation: ['portrait']
        }
      }
    },
  });
}

@guyca do you see something here?


Environment

  • React Native Navigation version: 6.2.0
  • React Native version: 0.61.5
  • Platform(s) (iOS, Android, or both?): both
  • Device info (Simulator/Device? OS version? Debug/Release?): everywhere

Most helpful comment

ok, I can confirm that not wrapping my Notification component in gestureHandlerRootHOC solves the problem. Thanks a lot @batuhansahan !

All 6 comments

If you registered screens with Gesture Handler its the problem

ah, you mean the gestureHandlerRootHOC from 'react-native-gesture-handler'?

Yes I did.

Isn't it something we should fix (maybe in 'react-native-gesture-handler')?

As a workaround, I could perhaps not wrap the overlay screen with gestureHandlerRootHOC as I actually do not use gestures there...

ok, I can confirm that not wrapping my Notification component in gestureHandlerRootHOC solves the problem. Thanks a lot @batuhansahan !

PS : @guyca that could be added as a note in the documentation as 'react-native-gesture-handler' is used a lot by the community...

SafeAreaProvider from react-native-safe-area-context causes the same problem.

@expo/react-native-action-sheet also causes this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tmaly1980 picture tmaly1980  路  3Comments

bdrobinson picture bdrobinson  路  3Comments

nbolender picture nbolender  路  3Comments

EliSadaka picture EliSadaka  路  3Comments

yedidyak picture yedidyak  路  3Comments