react-native-actions-sheet
react-native-actions-sheet copied to clipboard
React Native Actions Sheet Not Working with Expo Router
React Native Actions Sheet Not Working with Expo Router
Problem Description
The react-native-actions-sheet library is not functioning properly when used with Expo Router in app directory structure. Sheets registered with registerSheet are not displaying when triggered via SheetManager.show().
Environment
- Expo SDK: Latest version
- Expo Router: Using app directory structure
- react-native-actions-sheet: Latest version
- React Native: Latest version compatible with Expo
Reproduction Steps
- Set up an Expo app with app router structure
- Register sheets using
registerSheetin a sheets.tsx file - Import sheets.tsx in the root _layout.tsx file
- Wrap the app with SheetProvider in the root layout
- Attempt to show a sheet using
SheetManager.show()
Expected Behavior
The registered sheet should display when SheetManager.show() is called.
Actual Behavior
No sheet appears when SheetManager.show() is called. No visible error is shown in the console, but the action sheet fails to render.
Potential Causes
-
Context Isolation: Expo Router creates isolated contexts for different parts of the navigation tree. This may be preventing the SheetProvider context from being accessible across the application.
-
Multiple Provider Instances: The app directory structure might be causing multiple instances of SheetProvider to be created, causing context conflicts.
-
Navigation Framework Interference: The combination of drawer navigation, tab navigation, and stack navigation with Expo Router might be interfering with the proper mounting of action sheets.
-
Component Lifecycle Issues: The lifecycle of components in the app router structure may not align with the expectations of react-native-actions-sheet.
Suggested Solutions to Try
- Move all sheet-related code to a separate component that's mounted directly under the root provider
- Try using the legacy
@react-navigation/nativedirectly instead of Expo Router for specific sections - Investigate using a different modal solution that's more compatible with Expo Router
- Consider creating a custom implementation of action sheets using the standard React Native Modal component
- Check for compatibility issues between the latest versions of all libraries involved
Additional Notes
This issue appears to be specific to the combination of Expo Router app directory structure and react-native-actions-sheet. It may be a deeper architectural issue related to how React contexts work with the nested navigation structure of Expo Router.