Created
September 9, 2024 12:04
-
-
Save spacesuitdiver/ebc832ebdc0b67221139cbcbdb3f0e95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { ComponentType } from 'react'; | |
import { GestureHandlerRootView } from 'react-native-gesture-handler'; | |
import hoistNonReactStatics from 'hoist-non-react-statics'; | |
// Helper function to get the display name of the wrapped component | |
const getDisplayName = (WrappedComponent: ComponentType<any>): string => | |
WrappedComponent.displayName || WrappedComponent.name || 'Component'; | |
// Create the HOC | |
const withGestureHandlerRootView = <P extends object>( | |
WrappedComponent: ComponentType<P> | |
) => { | |
// Create a new component that wraps the passed component with GestureHandlerRootView | |
const WithGestureHandlerRootView: React.FC<P> = (props: P) => { | |
return ( | |
<GestureHandlerRootView style={{ flex: 1 }}> | |
<WrappedComponent {...props} /> | |
</GestureHandlerRootView> | |
); | |
}; | |
// Set the display name for better debugging | |
WithGestureHandlerRootView.displayName = `withGestureHandlerRootView(${getDisplayName( | |
WrappedComponent | |
)})`; | |
// Hoist non-react statics to preserve static methods | |
hoistNonReactStatics(WithGestureHandlerRootView, WrappedComponent); | |
return WithGestureHandlerRootView; | |
}; | |
export default withGestureHandlerRootView; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment