Skip to content

Commit ad65cf9

Browse files
authored
feat(iOS): RN-77 Swift support (#8037) (#8043)
* feat(iOS): RN-77 Swift support * Tests were added for RN 0.77 Objective-C and Swift * (RN77-NA) feat(iOS): Support Swift integration #8037 * Test were updated to remove older versions of RN. * Fixing podspec file to exclude Swift logic when dealing with Obj-c
1 parent 81aa788 commit ad65cf9

File tree

9 files changed

+162
-526
lines changed

9 files changed

+162
-526
lines changed

ReactNativeNavigation.podspec

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
44

55
fabric_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
66

7+
# Detect if this is a Swift project by looking for user AppDelegate.swift files
8+
dependency_paths = ['/node_modules/', '/Pods/', '/build/', '/Build/', '/DerivedData/']
9+
swift_project = Dir.glob('**/AppDelegate.swift')
10+
.reject { |file| dependency_paths.any? { |path| file.include?(path) } }
11+
.any?
12+
13+
# Debug output
14+
if swift_project
15+
puts "ReactNativeNavigation: Swift AppDelegate detected - enabling Swift-compatible configuration"
16+
else
17+
puts "ReactNativeNavigation: Objective-C AppDelegate detected - using standard configuration"
18+
end
19+
720
Pod::Spec.new do |s|
821
s.name = "ReactNativeNavigation"
922
s.version = package['version']
@@ -21,14 +34,29 @@ Pod::Spec.new do |s|
2134
s.source = { :git => "https://github.com/wix/react-native-navigation.git", :tag => "#{s.version}" }
2235
s.source_files = 'lib/ios/**/*.{h,m,mm,cpp}'
2336
s.exclude_files = "lib/ios/ReactNativeNavigationTests/**/*.*", "lib/ios/OCMock/**/*.*"
37+
# Only expose headers for Swift projects
38+
if swift_project
39+
s.public_header_files = [
40+
'lib/ios/RNNAppDelegate.h'
41+
]
42+
end
2443
end
2544

2645
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32 -DFOLLY_CFG_NO_COROUTINES=1'
27-
s.pod_target_xcconfig = {
46+
47+
# Base xcconfig settings
48+
xcconfig_settings = {
2849
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly" "$(PODS_ROOT)/Headers/Private/React-Core" "$(PODS_ROOT)/Headers/Private/Yoga"',
2950
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
3051
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
3152
}
53+
54+
# Only add DEFINES_MODULE for Swift projects
55+
if swift_project
56+
xcconfig_settings["DEFINES_MODULE"] = "YES"
57+
end
58+
59+
s.pod_target_xcconfig = xcconfig_settings
3260

3361
if fabric_enabled
3462
install_modules_dependencies(s)

autolink/fixtures/rn68/AppDelegate.mm.template

Lines changed: 0 additions & 108 deletions
This file was deleted.

autolink/fixtures/rn69/AppDelegate.mm.template

Lines changed: 0 additions & 133 deletions
This file was deleted.

autolink/fixtures/rn71/AppDelegate.mm.template renamed to autolink/fixtures/rn77/AppDelegate.mm.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
return true;
3434
}
3535

36-
@end
36+
@end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import UIKit
2+
import React
3+
import React_RCTAppDelegate
4+
import ReactAppDependencyProvider
5+
6+
@main
7+
class AppDelegate: RCTAppDelegate {
8+
override func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
9+
self.moduleName = "app"
10+
self.dependencyProvider = RCTAppDependencyProvider()
11+
12+
// You can add your custom initial props in the dictionary below.
13+
// They will be passed down to the ViewController used by React Native.
14+
self.initialProps = [:]
15+
16+
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
17+
}
18+
19+
override func sourceURL(for bridge: RCTBridge) -> URL? {
20+
self.bundleURL()
21+
}
22+
23+
override func bundleURL() -> URL? {
24+
#if DEBUG
25+
RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
26+
#else
27+
Bundle.main.url(forResource: "main", withExtension: "jsbundle")
28+
#endif
29+
}
30+
}

0 commit comments

Comments
 (0)