Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Native Portal Component for React Native #845

Open
RameshTigeen opened this issue Dec 13, 2024 · 1 comment
Open

Creating a Native Portal Component for React Native #845

RameshTigeen opened this issue Dec 13, 2024 · 1 comment

Comments

@RameshTigeen
Copy link

Introduction:
React Native Paper is a popular UI library that provides a Portal component to manage rendering of elements outside the main hierarchy, such as modals, tooltips, or dialogs. While React Native Paper offers excellent functionality, its package size can be a concern for projects where lightweight optimization is crucial. To address this, we propose building a native Portal component within our codebase to mimic and optimize the behavior of React Native Paper's Portal without relying on the library.

Benefits of Building a Native Portal Component:

Reduced Package Size:
By eliminating React Native Paper dependency solely for the Portal component, we can reduce the bundle size, improving performance, especially for mobile applications with constrained resources.

Full Customization:
Implementing our own Portal component allows for complete control over its behavior, styling, and integration with our app's ecosystem.

Optimized Performance:
A native implementation can be tailored to specific project requirements, avoiding general-purpose abstractions that might not align with our use cases.

Consistent Development:
Maintaining this functionality in-house ensures alignment with the overall architecture and coding standards of the project.

Proposed Implementation Strategy:

Research Existing Approaches:
Study the behavior and API of React Native Paper’s Portal component. Explore its use cases to ensure our implementation covers the core functionalities.

Design the API:
Define a lightweight API for the component. For example:

import { Portal, PortalProvider } from 'react-native';

function App() {
  return (
    <PortalProvider>
      <YourMainComponent />
      <Portal>
        <YourModalOrDialog />
      </Portal>
    </PortalProvider>
  );
}

Develop Core Features:

Provider and Context: Manage a global registry for components rendered in portals.

Portal Component: Render children outside the parent view hierarchy.

Event Handling: Ensure proper bubbling of gestures and interactions.

Optimize for React Native:

Ensure compatibility with React Native’s rendering cycle and gesture system.

Minimize re-renders and memory usage.

Testing and Validation:

Test with common use cases like modals, tooltips, and alerts.

Validate the implementation on both iOS and Android platforms.

Challenges and Considerations:

Gesture Handling:
Implement robust gesture handling to avoid issues with overlapping elements or misaligned user interactions.

Performance in Complex Views:
Test performance in views with heavy animations or intensive rendering.

Future Maintenance:
Ensure that the implementation is modular and scalable for future enhancements.

Conclusion:
Creating a native Portal component provides significant advantages in terms of optimization, customization, and alignment with project needs. While this involves additional initial effort, the long-term benefits to performance and maintainability make it a worthwhile investment for our React Native project.

@cortinico
Copy link
Member

Is this issue AI generated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants