How software-mansion/react-native-screens works
Project type and purpose
• The README and file structure show that this is a multi-platform native module for React Native. Its purpose is to provide native “screens” components (for iOS, Android, tvOS, visionOS, Windows, and Web) that optimize navigation performance and integration.
• It is not a standalone application but rather a library that integrates deeply into the React Native runtime and navigation layers.
• There are special sections for Fabric (the new rendering system), legacy “Paper” rendering, and platform-specific adjustments (e.g., Android Activity restart workarounds).
File structure to identify the key architectural layers
• Native Code Directories:
– “ios”, “android”, “windows”: These host the platform-specific native implementations and integration (for example, iOS’s RNSScreen components, Android’s native view managers, and Windows implementations).
– “android/src/main”, “ios/RNScreens.xcodeproj”, “windows/RNScreens”: All these represent the native side that exposes the equivalent native views.
• JavaScript / React Layer:
– “src”, “apps”, “Example”, “FabricExample”, “TVOSExample”: These contain the React components (for example, Screen, ScreenContainer, SearchBar, etc.), higher-level wrappers, and usage examples.
– Directories like “src/fabric”, “src/native-stack”, “src/gesture-handler”, “src/reanimated” show that the library supports both standard and Fabric-based renderers along with native stack implementations and gesture integrations.
• Common and Cross-Platform Code:
– Directories such as “common/cpp” contain bridging implementations between the JavaScript layer and the native rendering systems.
– The “cpp” folder has native code and JNI (for Android) which further demonstrates the multi-platform bridging library design.
• Documentation and Testing:
– “docs” for developer documentation.
– “__tests__”, “e2e”, and “apps/src/tests” directories indicate various test setups and examples.
Main components and the relationships between them
• JavaScript Presentation Layer:
• Core UI components defined in “src/components” (e.g., Screen, ScreenContainer, ScreenStack, SearchBar).
• Components for different rendering systems (Web versions using .web.tsx files, Fabric components in “src/fabric”, and components for native-stack in “src/native-stack”).
• Native Modules / Bridge Layer:
• Native implementation files in “ios”, “android”, and “windows” serve as the bridge between React Native and the underlying platform components. They expose native views (like iOS’s UINavigationController or Android’s Fragment) and native transitions.
• Supporting native code (C++ in “common/cpp” and “cpp”) which manages rendering and performance (especially for Fabric integration).
• Integration with External Navigation Libraries:
• Build and Configuration Components:
• Various configuration files (.buckconfig, .clang-format, .flowconfig, etc.) and CI/CD workflows in .github/workflows provide the build, formatting, and test infrastructure.
• Specific folders like “android/gradle” and “ios/Podfile” indicate native build system integration.
Important architectural patterns and design principles
• Separation of Concerns:
• The library clearly separates the JavaScript presentation layer (React components) from the native view managers and implementations.
• Platform-Specific Implementations:
• There are distinct folders for each platform, showing that while the API is unified, the underlying implementations differ per OS.
• Bridging Architecture:
• Native modules such as those in “src/fabric/NativeScreensModule” and in “android” or “ios” are used to bridge between React Native’s JavaScript thread and native code, using design patterns common to React Native modules.
• Extensibility:
• The presence of guides for library authors and clear separation between core functionality and framework-specific examples suggest a design that is built around extensibility and custom integrations.
• Support for Multiple Renderers:
• Distinction between Paper and Fabric rendering architectures shows adaptability to different React Native rendering paradigms.
Elements
• Clear labels for each major component/layer:
• “JS UI Components” (with subcomponents like Screen, ScreenContainer, etc.)
• “Fabric Integration” (highlighting Fabric-specific folders and components)
• “Platform-Specific Native Implementations” (iOS: RNSScreen, Android: View Managers, Windows: RNScreens, etc.)
• “External Integrations” (react-navigation and react-freeze)
• From external consumers (e.g., react-navigation) to the JS components.
• From JS components to native modules (indicating the bridge).
• From native modules to platform-specific native components.
• “JavaScript/React layer” components (perhaps using rounded rectangles),
• “Native modules/Bridge” (using squares),
• “External integrations” (using different borders).
• Annotations or side notes that mention how build configuration files and testing infrastructure support the development process.