mirror of
				https://gitcode.com/gh_mirrors/re/react-native-pushy.git
				synced 2025-10-31 21:33:12 +08:00 
			
		
		
		
	support expo < 51
This commit is contained in:
		| @@ -45,8 +45,10 @@ node_modules/ | |||||||
| npm-debug.log | npm-debug.log | ||||||
| Example | Example | ||||||
| yarn.lock | yarn.lock | ||||||
|  | bun.lock | ||||||
|  |  | ||||||
| domains.json | domains.json | ||||||
| endpoints.json | endpoints.json | ||||||
|  | endpoints_cresc.json | ||||||
|  |  | ||||||
| tea.yaml | tea.yaml | ||||||
| @@ -1,10 +1,40 @@ | |||||||
| import ExpoModulesCore | import ExpoModulesCore | ||||||
| import react_native_update | import React | ||||||
|  |  | ||||||
| public final class ExpoPushyReactDelegateHandler: ExpoReactDelegateHandler { | public final class ExpoPushyReactDelegateHandler: ExpoReactDelegateHandler { | ||||||
|   private weak var reactDelegate: ExpoReactDelegate? |  | ||||||
|  |  | ||||||
|   public override func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? { |     #if EXPO_SUPPORTS_BUNDLEURL | ||||||
|     return  RCTPushy.bundleURL() |     // This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is defined | ||||||
|   } |     // For expo-modules-core >= 1.12.0 | ||||||
|  |  | ||||||
|  |     // Override bundleURL, which is the primary mechanism for these versions. | ||||||
|  |     // Expo's default createBridge implementation should respect this. | ||||||
|  |     override public func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? { | ||||||
|  |       let bundleURL = RCTPushy.bundleURL() | ||||||
|  |       print("PushyHandler: Using bundleURL: \(bundleURL?.absoluteString ?? "nil")") | ||||||
|  |       return bundleURL | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     // No createBridge override needed here, rely on default behavior using the bundleURL override. | ||||||
|  |  | ||||||
|  |     #else | ||||||
|  |     // This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is NOT defined | ||||||
|  |     // For expo-modules-core < 1.12.0 | ||||||
|  |  | ||||||
|  |     // No bundleURL override possible here. | ||||||
|  |  | ||||||
|  |     // createBridge is the mechanism to customize the URL here. | ||||||
|  |     // We completely override it and do not call super. | ||||||
|  |     override public func createBridge(reactDelegate: ExpoReactDelegate, bridgeDelegate: RCTBridgeDelegate, launchOptions: [AnyHashable: Any]?) -> RCTBridge? { | ||||||
|  |       let bundleURL = RCTPushy.bundleURL() | ||||||
|  |       // Print the URL being provided to the initializer | ||||||
|  |       print("PushyHandler: createBridge bundleURL: \(bundleURL?.absoluteString ?? "nil")") | ||||||
|  |  | ||||||
|  |       // Directly create the bridge using the bundleURL initializer. | ||||||
|  |       // Pass nil for moduleProvider, assuming default behavior is sufficient. | ||||||
|  |       // WARNING: If bundleURL is nil, this initialization might fail silently or crash. | ||||||
|  |       return RCTBridge(bundleURL: bundleURL, moduleProvider: nil, launchOptions: launchOptions) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     #endif // EXPO_SUPPORTS_BUNDLEURL | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,4 +1,5 @@ | |||||||
| require 'json' | require 'json' | ||||||
|  | require 'rubygems' # Required for version comparison | ||||||
|  |  | ||||||
| new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' | new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1' | ||||||
|  |  | ||||||
| @@ -33,17 +34,45 @@ Pod::Spec.new do |s| | |||||||
|   s.dependency "React-Core" |   s.dependency "React-Core" | ||||||
|   s.dependency 'SSZipArchive' |   s.dependency 'SSZipArchive' | ||||||
|  |  | ||||||
|   project_root = File.expand_path('../../', __dir__) |  | ||||||
|   project_package_json = File.join(project_root, 'package.json') |  | ||||||
|   is_expo_project = false |   is_expo_project = false | ||||||
|  |   expo_dependency_added = false | ||||||
|  |   supports_bundle_url_final = false | ||||||
|  |  | ||||||
|   if (File.exist?(project_package_json)) |   # Use CocoaPods mechanism to find Podfile | ||||||
|     package_json = JSON.parse(File.read(project_package_json)) |   begin | ||||||
|     has_expo_dependency = package_json['dependencies'] && package_json['dependencies']['expo'] |     podfile_path = File.join(Pod::Config.instance.installation_root, 'Podfile') | ||||||
|     has_expo_modules_core = Dir.exist?('node_modules/expo-modules-core') |     if File.exist?(podfile_path) | ||||||
|     is_expo_project = has_expo_dependency || has_expo_modules_core |       podfile_content = File.read(podfile_path) | ||||||
|     if is_expo_project |       is_expo_project = podfile_content.include?('use_expo_modules!') | ||||||
|       s.dependency 'ExpoModulesCore' |     end | ||||||
|  |   rescue | ||||||
|  |     # Silently skip if CocoaPods config is not available | ||||||
|  |   end | ||||||
|  |  | ||||||
|  |   if is_expo_project | ||||||
|  |     s.dependency 'ExpoModulesCore' | ||||||
|  |     expo_dependency_added = true | ||||||
|  |  | ||||||
|  |     # Current directory is in node_modules/react-native-update, so parent is node_modules | ||||||
|  |     expo_core_package_json_path = File.join(__dir__, '..', 'expo-modules-core', 'package.json') | ||||||
|  |  | ||||||
|  |     if File.exist?(expo_core_package_json_path) | ||||||
|  |       begin | ||||||
|  |         core_package_json = JSON.parse(File.read(expo_core_package_json_path)) | ||||||
|  |         installed_version_str = core_package_json['version'] | ||||||
|  |  | ||||||
|  |         if installed_version_str | ||||||
|  |           begin | ||||||
|  |             installed_version = Gem::Version.new(installed_version_str) | ||||||
|  |             target_version = Gem::Version.new('1.12.0') | ||||||
|  |             supports_bundle_url_final = installed_version >= target_version | ||||||
|  |           rescue ArgumentError | ||||||
|  |             # Silently skip version parsing errors | ||||||
|  |           end | ||||||
|  |         end | ||||||
|  |       rescue JSON::ParserError, StandardError | ||||||
|  |         # Silently skip file reading and parsing errors | ||||||
|  |       end | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
| @@ -62,9 +91,13 @@ Pod::Spec.new do |s| | |||||||
|     ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' |     ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h' | ||||||
|   end |   end | ||||||
|  |  | ||||||
|   if is_expo_project |   if expo_dependency_added | ||||||
|     s.subspec 'Expo' do |ss| |     s.subspec 'Expo' do |ss| | ||||||
|       ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}' |       ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}' | ||||||
|  |       if supports_bundle_url_final | ||||||
|  |         ss.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'EXPO_SUPPORTS_BUNDLEURL' } | ||||||
|  |       end | ||||||
|  |       ss.dependency 'ExpoModulesCore' | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  |  | ||||||
| @@ -79,7 +112,7 @@ Pod::Spec.new do |s| | |||||||
|       s.pod_target_xcconfig = { |       s.pod_target_xcconfig = { | ||||||
|           "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", |           "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"", | ||||||
|           "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" |           "CLANG_CXX_LANGUAGE_STANDARD" => "c++17" | ||||||
|       } |       }.merge(s.pod_target_xcconfig) | ||||||
|       s.dependency "React-Codegen" |       s.dependency "React-Codegen" | ||||||
|       s.dependency "RCT-Folly" |       s.dependency "RCT-Folly" | ||||||
|       s.dependency "RCTRequired" |       s.dependency "RCTRequired" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 sunnylqm
					sunnylqm