Skip to content

Commit b743a48

Browse files
committed
fix: correct method signatures in macOS RNDocumentPicker.mm to resolve build errors
1 parent c0a5a55 commit b743a48

13 files changed

+185
-69
lines changed

packages/document-picker/ios/RNDocumentPicker.mm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
// this header file is generated by Xcode: https://developer.apple.com/documentation/swift/importing-swift-into-objective-c
88
// if it cannot be found, try cleaning the build folder and Xcode derived data folder
99

10-
// When using use_frameworks! :linkage => :static in Podfile
11-
#if __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
10+
// Import Swift module header with multiple fallback options
11+
#if __has_include("react_native_document_picker-Swift.h")
12+
#import "react_native_document_picker-Swift.h"
13+
#elif __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
1214
#import <react_native_document_picker/react_native_document_picker-Swift.h>
15+
#elif __has_include("react-native-document-picker-Swift.h")
16+
#import "react-native-document-picker-Swift.h"
17+
#elif __has_include(<react-native-document-picker/react-native-document-picker-Swift.h>)
18+
#import <react-native-document-picker/react-native-document-picker-Swift.h>
1319
#else
14-
#import "react_native_document_picker-Swift.h"
20+
#warning "Swift bridging header not found. Make sure Swift files are compiled and module is properly configured."
1521
#endif
1622

1723
// for UIModalPresentationStyle conversion
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// react-native-document-picker-umbrella.h
3+
// react-native-document-picker
4+
//
5+
// Created for module compatibility
6+
//
7+
8+
#ifdef __OBJC__
9+
#import <Foundation/Foundation.h>
10+
#import <UIKit/UIKit.h>
11+
12+
#import "RNDocumentPicker.h"
13+
#import "RCTConvert+RNDocumentPicker.h"
14+
15+
#endif
16+
17+
FOUNDATION_EXPORT double react_native_document_pickerVersionNumber;
18+
FOUNDATION_EXPORT const unsigned char react_native_document_pickerVersionString[];

packages/document-picker/ios/swift/PickerOptions.swift

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,26 @@ import UIKit
55
import UniformTypeIdentifiers
66

77
@objc public class PickerOptions: NSObject {
8-
let allowedTypes: Array<UTType>
9-
let mode: String // "import" or "open"
10-
let allowMultiSelection: Bool
11-
let transitionStyle: UIModalTransitionStyle
12-
let presentationStyle: UIModalPresentationStyle
13-
let initialDirectoryUrl: URL?
14-
let shouldShowFileExtensions: Bool
15-
let requestLongTermAccess: Bool
8+
@objc public var allowedTypes: Array<UTType>
9+
@objc public var mode: String // "import" or "open"
10+
@objc public var allowMultiSelection: Bool
11+
@objc public var transitionStyle: UIModalTransitionStyle
12+
@objc public var presentationStyle: UIModalPresentationStyle
13+
@objc public var initialDirectoryUrl: URL?
14+
@objc public var shouldShowFileExtensions: Bool
15+
@objc public var requestLongTermAccess: Bool
16+
17+
@objc public override init() {
18+
allowedTypes = []
19+
mode = "import"
20+
allowMultiSelection = false
21+
transitionStyle = .coverVertical
22+
presentationStyle = .fullScreen
23+
initialDirectoryUrl = nil
24+
shouldShowFileExtensions = true
25+
requestLongTermAccess = false
26+
super.init()
27+
}
1628

1729
@objc public init(types: Array<String>, mode: String = "import", initialDirectoryUrl: String? = nil, allowMultiSelection: Bool, shouldShowFileExtensions: Bool, transitionStyle: UIModalTransitionStyle = .coverVertical, presentationStyle: UIModalPresentationStyle = .fullScreen, requestLongTermAccess: Bool = false) {
1830
// TODO check if types were valid

packages/document-picker/ios/swift/SaverOptions.swift

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ import UIKit
55
import UniformTypeIdentifiers
66

77
@objc public class SaverOptions: NSObject {
8-
let transitionStyle: UIModalTransitionStyle
9-
let presentationStyle: UIModalPresentationStyle
10-
let initialDirectoryUrl: URL?
11-
let sourceUrls: [URL]
12-
let shouldShowFileExtensions: Bool
13-
let asCopy: Bool
8+
@objc public var transitionStyle: UIModalTransitionStyle
9+
@objc public var presentationStyle: UIModalPresentationStyle
10+
@objc public var initialDirectoryUrl: URL?
11+
@objc public var sourceUrls: [URL]
12+
@objc public var shouldShowFileExtensions: Bool
13+
@objc public var asCopy: Bool
14+
@objc public var fileName: String?
15+
@objc public var data: String?
16+
@objc public var uri: String?
17+
18+
@objc public override init() {
19+
transitionStyle = .coverVertical
20+
presentationStyle = .fullScreen
21+
initialDirectoryUrl = nil
22+
sourceUrls = []
23+
shouldShowFileExtensions = true
24+
asCopy = true
25+
fileName = nil
26+
data = nil
27+
uri = nil
28+
super.init()
29+
}
1430

1531
@objc public init(sourceUrlStrings: [String], asCopy: Bool, initialDirectoryUrl: String? = nil, shouldShowFileExtensions: Bool, transitionStyle: UIModalTransitionStyle = .coverVertical, presentationStyle: UIModalPresentationStyle = .fullScreen) {
1632
self.sourceUrls = sourceUrlStrings.map({ it in

packages/document-picker/macos/RCTConvert+RNDocumentPicker.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
#import <React/RCTConvert.h>
44

5-
// When using use_frameworks! :linkage => :static in Podfile
6-
#if __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
7-
#import <react_native_document_picker/react_native_document_picker-Swift.h>
8-
#else
9-
#import "react_native_document_picker-Swift.h"
10-
#endif
5+
// Forward declarations for Swift classes
6+
@class PickerOptions;
7+
@class SaverOptions;
118

129
@interface RCTConvert (RNDocumentPicker)
1310

packages/document-picker/macos/RCTConvert+RNDocumentPicker.mm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
#import "RCTConvert+RNDocumentPicker.h"
44
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>
55

6+
// Import Swift module header with multiple fallback options
7+
#if __has_include("react_native_document_picker-Swift.h")
8+
#import "react_native_document_picker-Swift.h"
9+
#elif __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
10+
#import <react_native_document_picker/react_native_document_picker-Swift.h>
11+
#elif __has_include("react-native-document-picker-Swift.h")
12+
#import "react-native-document-picker-Swift.h"
13+
#elif __has_include(<react-native-document-picker/react-native-document-picker-Swift.h>)
14+
#import <react-native-document-picker/react-native-document-picker-Swift.h>
15+
#else
16+
#warning "Swift bridging header not found. Make sure Swift files are compiled and module is properly configured."
17+
#endif
18+
619
@implementation RCTConvert (RNDocumentPicker)
720

821
+ (PickerOptions *)PickerOptions:(id)json

packages/document-picker/macos/RNDocumentPicker.mm

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@
77
// this header file is generated by Xcode: https://developer.apple.com/documentation/swift/importing-swift-into-objective-c
88
// if it cannot be found, try cleaning the build folder and Xcode derived data folder
99

10-
// When using use_frameworks! :linkage => :static in Podfile
11-
#if __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
10+
// Import Swift module header with multiple fallback options
11+
#if __has_include("react_native_document_picker-Swift.h")
12+
#import "react_native_document_picker-Swift.h"
13+
#elif __has_include(<react_native_document_picker/react_native_document_picker-Swift.h>)
1214
#import <react_native_document_picker/react_native_document_picker-Swift.h>
15+
#elif __has_include("react-native-document-picker-Swift.h")
16+
#import "react-native-document-picker-Swift.h"
17+
#elif __has_include(<react-native-document-picker/react-native-document-picker-Swift.h>)
18+
#import <react-native-document-picker/react-native-document-picker-Swift.h>
1319
#else
14-
#import "react_native_document_picker-Swift.h"
20+
#warning "Swift bridging header not found. Make sure Swift files are compiled and module is properly configured."
1521
#endif
1622

1723
@interface RNDocumentPicker ()
@@ -44,7 +50,7 @@ + (BOOL)requiresMainQueueSetup {
4450
(RCTPromiseRejectBlock) reject)
4551
{
4652
PickerOptions *pickerOptions = [RCTConvert PickerOptions:options];
47-
[docPicker present:pickerOptions resolve:resolve reject:reject];
53+
[docPicker presentWithOptions:pickerOptions resolve:resolve reject:reject];
4854
}
4955

5056
RCT_EXPORT_METHOD(pickDirectory:
@@ -55,7 +61,8 @@ + (BOOL)requiresMainQueueSetup {
5561
(RCTPromiseRejectBlock) reject)
5662
{
5763
PickerOptions *pickerOptions = [RCTConvert PickerOptions:options];
58-
[docPicker presentDirectory:pickerOptions resolve:resolve reject:reject];
64+
pickerOptions.isDirectoryPicker = YES;
65+
[docPicker presentWithOptions:pickerOptions resolve:resolve reject:reject];
5966
}
6067

6168
RCT_EXPORT_METHOD(saveDocument:
@@ -66,7 +73,7 @@ + (BOOL)requiresMainQueueSetup {
6673
(RCTPromiseRejectBlock) reject)
6774
{
6875
SaverOptions *saverOptions = [RCTConvert SaverOptions:options];
69-
[docSaver present:saverOptions resolve:resolve reject:reject];
76+
[docSaver presentWithOptions:saverOptions resolve:resolve reject:reject];
7077
}
7178

7279
RCT_EXPORT_METHOD(releaseSecurityScopedResource:
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// react-native-document-picker-umbrella.h
3+
// react-native-document-picker
4+
//
5+
// Created for module compatibility
6+
//
7+
8+
#ifdef __OBJC__
9+
#import <Foundation/Foundation.h>
10+
#import <Cocoa/Cocoa.h>
11+
12+
#import "RNDocumentPicker.h"
13+
#import "RCTConvert+RNDocumentPicker.h"
14+
15+
#endif
16+
17+
FOUNDATION_EXPORT double react_native_document_pickerVersionNumber;
18+
FOUNDATION_EXPORT const unsigned char react_native_document_pickerVersionString[];

packages/document-picker/macos/swift/DocPicker.swift

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import AppKit
1818
let openPanel = NSOpenPanel()
1919

2020
openPanel.allowsMultipleSelection = options.allowMultiSelection
21-
openPanel.canChooseDirectories = false
22-
openPanel.canChooseFiles = true
21+
openPanel.canChooseDirectories = options.isDirectoryPicker
22+
openPanel.canChooseFiles = !options.isDirectoryPicker
2323
openPanel.canCreateDirectories = false
2424

2525
// Set allowed file types
@@ -45,28 +45,6 @@ import AppKit
4545
}
4646
}
4747

48-
@objc public func presentDirectory(options: PickerOptions, resolve: @escaping RNDPPromiseResolveBlock, reject: @escaping RNDPPromiseRejectBlock) {
49-
if (!promiseWrapper.trySetPromiseRejectingIncoming(resolve, rejecter: reject, fromCallSite: "pickDirectory")) {
50-
return;
51-
}
52-
currentOptions = options;
53-
DispatchQueue.main.async {
54-
let openPanel = NSOpenPanel()
55-
56-
openPanel.allowsMultipleSelection = options.allowMultiSelection
57-
openPanel.canChooseDirectories = true
58-
openPanel.canChooseFiles = false
59-
openPanel.canCreateDirectories = false
60-
61-
openPanel.begin { (result) in
62-
if result == .OK {
63-
self.handlePickerResult(urls: openPanel.urls)
64-
} else {
65-
self.promiseWrapper.reject(fromCallSite: "pickDirectory", code: "DOCUMENT_PICKER_CANCELED", message: "User canceled directory picker", error: nil)
66-
}
67-
}
68-
}
69-
}
7048

7149
public func getMetadataFor(url: URL) throws -> DocumentMetadataBuilder {
7250
return if (currentOptions?.isOpenMode() == true) {

packages/document-picker/macos/swift/PickerOptions.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@ import Foundation
44
import UniformTypeIdentifiers
55

66
@objc public class PickerOptions: NSObject {
7-
let allowedTypes: Array<UTType>
8-
let mode: String // "import" or "open"
9-
let allowMultiSelection: Bool
10-
let initialDirectoryUrl: URL?
11-
let shouldShowFileExtensions: Bool
12-
let requestLongTermAccess: Bool
13-
let copyTo: String
7+
@objc public var allowedTypes: Array<UTType>
8+
@objc public var mode: String // "import" or "open"
9+
@objc public var allowMultiSelection: Bool
10+
@objc public var initialDirectoryUrl: URL?
11+
@objc public var shouldShowFileExtensions: Bool
12+
@objc public var requestLongTermAccess: Bool
13+
@objc public var copyTo: String
14+
@objc public var isDirectoryPicker: Bool = false
15+
16+
@objc public override init() {
17+
allowedTypes = []
18+
mode = "import"
19+
allowMultiSelection = false
20+
initialDirectoryUrl = nil
21+
shouldShowFileExtensions = true
22+
requestLongTermAccess = false
23+
copyTo = "cachesDirectory"
24+
isDirectoryPicker = false
25+
super.init()
26+
}
1427

1528
@objc public init(types: Array<String>, mode: String = "import", initialDirectoryUrl: String? = nil, allowMultiSelection: Bool, shouldShowFileExtensions: Bool, requestLongTermAccess: Bool = false, copyTo: String = "cachesDirectory") {
1629
// TODO check if types were valid

0 commit comments

Comments
 (0)