Skip to content

Commit a6802bd

Browse files
committed
support expo < 51
1 parent 97848e7 commit a6802bd

File tree

3 files changed

+81
-16
lines changed

3 files changed

+81
-16
lines changed

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ node_modules/
4545
npm-debug.log
4646
Example
4747
yarn.lock
48+
bun.lock
4849

4950
domains.json
5051
endpoints.json
52+
endpoints_cresc.json
5153

5254
tea.yaml
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import ExpoModulesCore
2-
import react_native_update
2+
import React
33

44
public final class ExpoPushyReactDelegateHandler: ExpoReactDelegateHandler {
5-
private weak var reactDelegate: ExpoReactDelegate?
65

7-
public override func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? {
8-
return RCTPushy.bundleURL()
9-
}
6+
#if EXPO_SUPPORTS_BUNDLEURL
7+
// This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is defined
8+
// For expo-modules-core >= 1.12.0
9+
10+
// Override bundleURL, which is the primary mechanism for these versions.
11+
// Expo's default createBridge implementation should respect this.
12+
override public func bundleURL(reactDelegate: ExpoReactDelegate) -> URL? {
13+
let bundleURL = RCTPushy.bundleURL()
14+
print("PushyHandler: Using bundleURL: \(bundleURL?.absoluteString ?? "nil")")
15+
return bundleURL
16+
}
17+
18+
// No createBridge override needed here, rely on default behavior using the bundleURL override.
19+
20+
#else
21+
// This code block compiles only if EXPO_SUPPORTS_BUNDLEURL is NOT defined
22+
// For expo-modules-core < 1.12.0
23+
24+
// No bundleURL override possible here.
25+
26+
// createBridge is the mechanism to customize the URL here.
27+
// We completely override it and do not call super.
28+
override public func createBridge(reactDelegate: ExpoReactDelegate, bridgeDelegate: RCTBridgeDelegate, launchOptions: [AnyHashable: Any]?) -> RCTBridge? {
29+
let bundleURL = RCTPushy.bundleURL()
30+
// Print the URL being provided to the initializer
31+
print("PushyHandler: createBridge bundleURL: \(bundleURL?.absoluteString ?? "nil")")
32+
33+
// Directly create the bridge using the bundleURL initializer.
34+
// Pass nil for moduleProvider, assuming default behavior is sufficient.
35+
// WARNING: If bundleURL is nil, this initialization might fail silently or crash.
36+
return RCTBridge(bundleURL: bundleURL, moduleProvider: nil, launchOptions: launchOptions)
37+
}
38+
39+
#endif // EXPO_SUPPORTS_BUNDLEURL
1040
}

react-native-update.podspec

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'json'
2+
require 'rubygems' # Required for version comparison
23

34
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
45

@@ -33,17 +34,45 @@ Pod::Spec.new do |s|
3334
s.dependency "React-Core"
3435
s.dependency 'SSZipArchive'
3536

36-
project_root = File.expand_path('../../', __dir__)
37-
project_package_json = File.join(project_root, 'package.json')
3837
is_expo_project = false
38+
expo_dependency_added = false
39+
supports_bundle_url_final = false
3940

40-
if (File.exist?(project_package_json))
41-
package_json = JSON.parse(File.read(project_package_json))
42-
has_expo_dependency = package_json['dependencies'] && package_json['dependencies']['expo']
43-
has_expo_modules_core = Dir.exist?('node_modules/expo-modules-core')
44-
is_expo_project = has_expo_dependency || has_expo_modules_core
45-
if is_expo_project
46-
s.dependency 'ExpoModulesCore'
41+
# Use CocoaPods mechanism to find Podfile
42+
begin
43+
podfile_path = File.join(Pod::Config.instance.installation_root, 'Podfile')
44+
if File.exist?(podfile_path)
45+
podfile_content = File.read(podfile_path)
46+
is_expo_project = podfile_content.include?('use_expo_modules!')
47+
end
48+
rescue
49+
# Silently skip if CocoaPods config is not available
50+
end
51+
52+
if is_expo_project
53+
s.dependency 'ExpoModulesCore'
54+
expo_dependency_added = true
55+
56+
# Current directory is in node_modules/react-native-update, so parent is node_modules
57+
expo_core_package_json_path = File.join(__dir__, '..', 'expo-modules-core', 'package.json')
58+
59+
if File.exist?(expo_core_package_json_path)
60+
begin
61+
core_package_json = JSON.parse(File.read(expo_core_package_json_path))
62+
installed_version_str = core_package_json['version']
63+
64+
if installed_version_str
65+
begin
66+
installed_version = Gem::Version.new(installed_version_str)
67+
target_version = Gem::Version.new('1.12.0')
68+
supports_bundle_url_final = installed_version >= target_version
69+
rescue ArgumentError
70+
# Silently skip version parsing errors
71+
end
72+
end
73+
rescue JSON::ParserError, StandardError
74+
# Silently skip file reading and parsing errors
75+
end
4776
end
4877
end
4978

@@ -62,9 +91,13 @@ Pod::Spec.new do |s|
6291
ss.public_header_files = 'ios/RCTPushy/HDiffPatch/**/*.h'
6392
end
6493

65-
if is_expo_project
94+
if expo_dependency_added
6695
s.subspec 'Expo' do |ss|
6796
ss.source_files = 'ios/Expo/**/*.{h,m,mm,swift}'
97+
if supports_bundle_url_final
98+
ss.pod_target_xcconfig = { 'SWIFT_ACTIVE_COMPILATION_CONDITIONS' => 'EXPO_SUPPORTS_BUNDLEURL' }
99+
end
100+
ss.dependency 'ExpoModulesCore'
68101
end
69102
end
70103

@@ -79,7 +112,7 @@ Pod::Spec.new do |s|
79112
s.pod_target_xcconfig = {
80113
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
81114
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
82-
}
115+
}.merge(s.pod_target_xcconfig)
83116
s.dependency "React-Codegen"
84117
s.dependency "RCT-Folly"
85118
s.dependency "RCTRequired"

0 commit comments

Comments
 (0)