react-native-safe-area-context
react-native-safe-area-context copied to clipboard
Fix the `pointerEvents` prop on SafeAreaProvider (fixes #432 #130)
Summary
This PR fixes #432 / #130, where the pointerEvents prop has no effect when applied to the SafeAreaProvider. I share the same use-case as the creator of the issue: I wish to use a SafeAreaProvider as part of an overlay, where touch events should be passed to views underneath it, as is expected when setting pointerEvents="box-none".
It seems the behavior described was working until the library was migrated to the new architecture. Here are my findings:
- When running with paper, all props are set via the codegen-created
RNCSafeAreaProviderManagerDelegate#setPropertymethod. This method will invoke the appropriate@ReactPropsetter method defined in its corresponding ViewManager. - If the
setPropertymethod does not include a case to handle a prop, it will not be passed to the ViewManager. Note that react-native does provide cases for mostViewprops with the BaseViewManagerInterface. However,pointerEventsis not included. - In order to add the case during codegen, I simply add the
pointerEventsprop to theNativePropsspecs definition. Unfortunately, because the definition requires a specific format to pass codegen, it also clashes with the inheritedViewProps. I add a@ts-ignorecomment as a workaround. - Lastly, I update the
SafeAreaProviderManagerto inherit fromReactViewManagerto handle the newly defined prop.
Test Plan
As a test, I modified the example app by styling a SafeAreaProvider with StyleSheet.absoluteFill, and placing a Touchable button underneath/behind the view. When adding pointerEvents="none" to the SafeAreaProvider, the button can be pressed with this fix. Without this fix, the button cannot be pressed.