c3c891cea0
* enable predictive back gesture * upgrade to rn 85 * remove deprecated * added timeout to theme switch * fix plugin items hit registration * fix SearchbarV2 hit registration * fix loading spinner * migrated to expo * migrated to expo * Fix reader footer animation * working again * added icons back * added splashscreen * clean up * nitro epub * fix * remove .env.local from git tracking * fix rn background actions not working * moving custom permissions to app.json * more cleanup * fix epub import * remove unused deps * Further cleanup for gradle build types * Update build.yml * ignore android/ and ios/ as they are generated by CNG * fix lint * Delete ios directory * Delete android directory * fix lint * fix test mocks * update packages * update eslint * fix ThemeProvider placement * fix test and lint * Add BackgroundTask native module * Add NativeFile changes * first round of fixing compatibility issues * added types for native modules
66 lines
2.2 KiB
Swift
66 lines
2.2 KiB
Swift
import ExpoModulesCore
|
|
import Foundation
|
|
|
|
public class NativeFileModule: Module {
|
|
public func definition() -> ModuleDefinition {
|
|
Name("NativeFile")
|
|
|
|
Function("writeFile") { (path: String, content: String) in
|
|
try content.write(toFile: path, atomically: true, encoding: .utf8)
|
|
}
|
|
|
|
Function("readFile") { (path: String) in
|
|
try String(contentsOfFile: path, encoding: .utf8)
|
|
}
|
|
|
|
Function("copyFile") { (sourcePath: String, destPath: String) in
|
|
try FileManager.default.copyItem(atPath: sourcePath, toPath: destPath)
|
|
}
|
|
|
|
Function("moveFile") { (sourcePath: String, destPath: String) in
|
|
try FileManager.default.moveItem(atPath: sourcePath, toPath: destPath)
|
|
}
|
|
|
|
Function("exists") { (filePath: String) in
|
|
FileManager.default.fileExists(atPath: filePath)
|
|
}
|
|
|
|
Function("mkdir") { (filePath: String) in
|
|
try FileManager.default.createDirectory(atPath: filePath, withIntermediateDirectories: true, attributes: nil)
|
|
}
|
|
|
|
Function("unlink") { (filePath: String) in
|
|
try FileManager.default.removeItem(atPath: filePath)
|
|
}
|
|
|
|
Function("readDir") { (dirPath: String) -> [[String: Any]] in
|
|
let contents = try FileManager.default.contentsOfDirectory(atPath: dirPath)
|
|
return contents.map { fileName in
|
|
let path = (dirPath as NSString).appendingPathComponent(fileName)
|
|
var isDirectory: ObjCBool = false
|
|
FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
|
|
return [
|
|
"name": fileName,
|
|
"path": path,
|
|
"isDirectory": isDirectory.boolValue
|
|
]
|
|
}
|
|
}
|
|
|
|
AsyncFunction("downloadFile") { (url: String, destPath: String, method: String, headers: [String: String], body: String?, promise: Promise) in
|
|
// Stub — download implementation not ported for iOS
|
|
promise.reject("NOT_IMPLEMENTED", "downloadFile is not implemented on iOS")
|
|
}
|
|
|
|
Constant("ExternalDirectoryPath") {
|
|
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
|
|
return paths.first ?? ""
|
|
}
|
|
|
|
Constant("ExternalCachesDirectoryPath") {
|
|
let paths = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)
|
|
return paths.first ?? ""
|
|
}
|
|
}
|
|
}
|