Skip to content

Conversation

Doublemme
Copy link

Based on the TurboModule migration work we've been doing in this branch, here's a comprehensive PR description that follows open source contribution best practices:

🚀 Add TurboModule Support with Backward Compatibility

What does this PR do?

This PR migrates the react-native-fast-url library to support React Native's New Architecture (TurboModules) while maintaining full backward compatibility with the legacy architecture. Users can now use this library seamlessly in both old and new React Native projects without any breaking changes.

Why is this change needed?

  • Future-proofing: React Native's New Architecture is the future of React Native development, offering better performance and type safety
  • Performance improvements: TurboModules provide better JavaScript-to-native communication performance
  • Developer experience: Better TypeScript support and compile-time type checking for native methods
  • Ecosystem compatibility: Ensures the library works with the latest React Native versions and upcoming features

What changed?

JavaScript/TypeScript Changes

  • ✅ Added TurboModule specification in src/NativeFastUrl.ts
  • ✅ Updated src/index.tsx to conditionally use TurboModule when available
  • ✅ Added codegenConfig to package.json for automatic code generation
  • ✅ Maintained existing API - no breaking changes for consumers

iOS Changes

  • ✅ Updated react-native-fast-url.podspec to support CodeGen and C++17
  • ✅ Modified ios/FastUrl.mm to implement both legacy and TurboModule interfaces
  • ✅ Added conditional compilation for new architecture features
  • ✅ Ensured proper return types match JavaScript specification

Android Changes

  • ✅ Updated android/build.gradle with conditional React plugin application
  • ✅ Created separate source sets for oldarch and newarch implementations
  • ✅ Refactored code into shared FastUrlModuleImpl for code reuse
  • ✅ Updated FastUrlPackage to be a TurboReactPackage with backward compatibility

How to test

  1. Legacy Architecture Testing:

    cd example
    npm install
    # iOS
    cd ios && pod install && cd ..
    npx react-native run-ios
    # Android
    npx react-native run-android
  2. New Architecture Testing:

    cd example
    # Enable new architecture
    echo "newArchEnabled=true" >> android/gradle.properties
    echo "RCT_NEW_ARCH_ENABLED=1" >> ios/.xccconfig
    # Rebuild and test

Backward Compatibility

  • ✅ No breaking changes to public API
  • ✅ Works with React Native 0.68+
  • ✅ Gracefully falls back to legacy implementation when TurboModules are not available
  • ✅ Existing projects can upgrade without code changes

Technical Details

The implementation follows the official React Native New Architecture guide and uses:

  • Conditional compilation for platform-specific TurboModule features
  • Runtime detection of TurboModule availability in JavaScript
  • Shared implementation pattern to avoid code duplication between architectures
  • Proper TypeScript types for enhanced developer experience

Checklist

  • Code follows the project's coding standards
  • Self-review completed
  • No breaking changes introduced
  • Backward compatibility maintained
  • Both iOS and Android implementations updated
  • TypeScript types are correct and complete
  • Ready for code review

Additional Notes

This migration positions the library for long-term success with React Native's evolution while ensuring current users experience no disruption. The implementation carefully balances modern architecture support with practical backward compatibility needs.


This PR implements TurboModule support following React Native's official migration guidelines and best practices for library maintainers.

@KusStar
Copy link
Owner

KusStar commented Jul 26, 2025

Thank you for contribution, I will test as soon and merge it.

@KusStar KusStar merged commit 1acb668 into KusStar:main Jul 26, 2025
@KusStar
Copy link
Owner

KusStar commented Jul 26, 2025

Merged and published to npm react-native-fast-url/v/1.0.0

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

Successfully merging this pull request may close these issues.

2 participants