Skip to content

Commit

Permalink
Merge branch 'dev-v2.28'
Browse files Browse the repository at this point in the history
  • Loading branch information
birdofpreyru committed Aug 25, 2024
2 parents eede7c9 + a394322 commit 39762ec
Show file tree
Hide file tree
Showing 48 changed files with 2,051 additions and 1,861 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ example/vendor/
#
node_modules/
npm-debug.log
package.tgz
yarn-debug.log
yarn-error.log

Expand All @@ -78,4 +79,6 @@ android/keystores/debug.keystore
# generated by bob
lib/

package.tgz
# React Native Codegen
ios/generated
android/generated
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v20.14.0
v20.17.0
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MIT License

_Copyright © 2023, Dr. Sergey Pogodin_
_Copyright © 2023–2024, Dr. Sergey Pogodin_
&mdash; <[email protected]> (https://dr.pogodin.studio) \
_Copyright &copy; 2015, Johannes Lumpe_

Expand Down
10 changes: 8 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ buildscript {
}
}

def reactNativeArchitectures() {
def value = rootProject.getProperties().get("reactNativeArchitectures")
return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
}

def isNewArchitectureEnabled() {
return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
}
Expand Down Expand Up @@ -86,8 +91,9 @@ android {
if (isNewArchitectureEnabled()) {
java.srcDirs += [
"src/newarch",
// This is needed to build Kotlin project with NewArch enabled
"${project.buildDir}/generated/source/codegen/java"
// Codegen specs
"generated/java",
"generated/jni"
]
} else {
java.srcDirs += ["src/oldarch"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ import com.facebook.react.module.model.ReactModuleInfo
import java.util.HashMap

class ReactNativeFsPackage : TurboReactPackage() {
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return if (name == ReactNativeFsModule.NAME) {
ReactNativeFsModule(reactContext)
} else {
null
}
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return if (name == ReactNativeFsModule.NAME) {
ReactNativeFsModule(reactContext)
} else {
null
}
}

override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[ReactNativeFsModule.NAME] = ReactModuleInfo(
ReactNativeFsModule.NAME,
ReactNativeFsModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
)
moduleInfos
}
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[ReactNativeFsModule.NAME] = ReactModuleInfo(
ReactNativeFsModule.NAME,
ReactNativeFsModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule // isTurboModule
)
moduleInfos
}
}
}
211 changes: 109 additions & 102 deletions android/src/main/java/com/drpogodin/reactnativefs/Uploader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,117 +55,124 @@ class Uploader : AsyncTask<UploadParams?, IntArray?, UploadResult>() {
var filename: String
var filetype: String
try {
val files: Array<Any> = params!!.files!!.toTypedArray()
val binaryStreamOnly = params.binaryStreamOnly
connection = params.src!!.openConnection() as HttpURLConnection
connection.doOutput = true
val headerIterator = params.headers!!.keySetIterator()
connection.requestMethod = params.method
val files: Array<Any> = params!!.files!!.toTypedArray()
val binaryStreamOnly = params.binaryStreamOnly
connection = params.src!!.openConnection() as HttpURLConnection
connection.doOutput = true
val headerIterator = params.headers!!.keySetIterator()
connection.requestMethod = params.method
if (!binaryStreamOnly) {
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=$boundary")
}
while (headerIterator.hasNextKey()) {
val key = headerIterator.nextKey()
val value = params.headers!!.getString(key)
connection.setRequestProperty(key, value)
}
val fieldsIterator = params.fields!!.keySetIterator()
while (fieldsIterator.hasNextKey()) {
val key = fieldsIterator.nextKey()
val value = params.fields!!.getString(key)
metaData += twoHyphens + boundary + crlf + "Content-Disposition: form-data; name=\"" + key + "\"" + crlf + crlf + value + crlf
}
stringData += metaData
fileHeader = arrayOfNulls(files.size)
for (map in params.files!!) {
name = map.getString("name")!!
filename = map.getString("filename")!!
filetype = map.getString("filetype") ?: getMimeType(map.getString("filepath"))
val file = File(map.getString("filepath"))
val fileLength = file.length()
totalFileLength += fileLength
if (!binaryStreamOnly) {
connection.setRequestProperty("Content-Type", "multipart/form-data;boundary=$boundary")
val fileHeaderType = twoHyphens + boundary + crlf +
"Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"" + crlf +
"Content-Type: " + filetype + crlf
if (files.size - 1 == fileCount) {
totalFileLength += tail.length.toLong()
}
val fileLengthHeader = "Content-length: $fileLength$crlf"
fileHeader[fileCount] = fileHeaderType + fileLengthHeader + crlf
stringData += fileHeaderType + fileLengthHeader + crlf
}
while (headerIterator.hasNextKey()) {
val key = headerIterator.nextKey()
val value = params.headers!!.getString(key)
connection.setRequestProperty(key, value)
}
val fieldsIterator = params.fields!!.keySetIterator()
while (fieldsIterator.hasNextKey()) {
val key = fieldsIterator.nextKey()
val value = params.fields!!.getString(key)
metaData += twoHyphens + boundary + crlf + "Content-Disposition: form-data; name=\"" + key + "\"" + crlf + crlf + value + crlf
}
stringData += metaData
fileHeader = arrayOfNulls(files.size)
for (map in params.files!!) {
name = map.getString("name")!!
filename = map.getString("filename")!!
filetype = map.getString("filetype") ?: getMimeType(map.getString("filepath"))
val file = File(map.getString("filepath"))
val fileLength = file.length()
totalFileLength += fileLength
if (!binaryStreamOnly) {
val fileHeaderType = twoHyphens + boundary + crlf +
"Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"" + crlf +
"Content-Type: " + filetype + crlf
if (files.size - 1 == fileCount) {
totalFileLength += tail.length.toLong()
}
val fileLengthHeader = "Content-length: $fileLength$crlf"
fileHeader[fileCount] = fileHeaderType + fileLengthHeader + crlf
stringData += fileHeaderType + fileLengthHeader + crlf
}
fileCount++
}
fileCount = 0
mParams!!.onUploadBegin?.onUploadBegin()
fileCount++
}
fileCount = 0
mParams!!.onUploadBegin?.onUploadBegin()
if (!binaryStreamOnly) {
var requestLength = totalFileLength
requestLength += (stringData.length + files.size * crlf.length).toLong()
connection.setRequestProperty("Content-length", "" + requestLength.toInt())
connection.setFixedLengthStreamingMode(requestLength.toInt())
}
connection.connect()
request = DataOutputStream(connection.outputStream)
val requestChannel = Channels.newChannel(request)
if (!binaryStreamOnly) {
request.writeBytes(metaData)
}
byteSentTotal = 0
for (map in params.files!!) {
if (!binaryStreamOnly) {
var requestLength = totalFileLength
requestLength += (stringData.length + files.size * crlf.length).toLong()
connection.setRequestProperty("Content-length", "" + requestLength.toInt())
connection.setFixedLengthStreamingMode(requestLength.toInt())
request.writeBytes(fileHeader[fileCount])
}
connection.connect()
request = DataOutputStream(connection.outputStream)
val requestChannel = Channels.newChannel(request)
if (!binaryStreamOnly) {
request.writeBytes(metaData)
}
byteSentTotal = 0
for (map in params.files!!) {
if (!binaryStreamOnly) {
request.writeBytes(fileHeader[fileCount])
}
val file = File(map.getString("filepath"))
val fileLength = file.length()
val bufferSize = ceil((fileLength / 100f).toDouble()).toLong()
var bytesRead: Long = 0
val fileStream = FileInputStream(file)
val fileChannel = fileStream.channel
while (bytesRead < fileLength) {
val transferredBytes = fileChannel.transferTo(bytesRead, bufferSize, requestChannel)
bytesRead += transferredBytes
byteSentTotal += transferredBytes.toInt()
mParams!!.onUploadProgress?.onUploadProgress(totalFileLength.toInt(), byteSentTotal)
}
if (!binaryStreamOnly) {
request.writeBytes(crlf)
}
fileCount++
fileStream.close()
val file = File(map.getString("filepath"))
val fileLength = file.length()
val bufferSize = ceil((fileLength / 100f).toDouble()).toLong()
var bytesRead: Long = 0
val fileStream = FileInputStream(file)
val fileChannel = fileStream.channel
while (bytesRead < fileLength) {
val transferredBytes = fileChannel.transferTo(bytesRead, bufferSize, requestChannel)
bytesRead += transferredBytes
byteSentTotal += transferredBytes.toInt()
mParams!!.onUploadProgress?.onUploadProgress(totalFileLength.toInt(), byteSentTotal)
}
if (!binaryStreamOnly) {
request.writeBytes(tail)
}
request.flush()
request.close()
if (connection.errorStream != null) {
responseStream = BufferedInputStream(connection.errorStream)
} else {
responseStream = BufferedInputStream(connection.inputStream)
}
responseStreamReader = BufferedReader(InputStreamReader(responseStream))
val responseHeaders = Arguments.createMap()
val map = connection.headerFields
for ((key, value) in map) {
val count = 0
responseHeaders.putString(key, value[count])
request.writeBytes(crlf)
}
val stringBuilder = StringBuilder()
var line: String?
while (responseStreamReader.readLine().also { line = it } != null) {
stringBuilder.append(line).append("\n")
fileCount++
fileStream.close()
}
if (!binaryStreamOnly) {
request.writeBytes(tail)
}
request.flush()
request.close()
if (connection.errorStream != null) {
responseStream = BufferedInputStream(connection.errorStream)
} else {
responseStream = BufferedInputStream(connection.inputStream)
}
responseStreamReader = BufferedReader(InputStreamReader(responseStream))
val responseHeaders = Arguments.createMap()
val map = connection.headerFields
for ((key, value) in map) {
// NOTE: Although the type of key is evaluated as non-nullable by the compiler,
// somehow it may become `null` after the upgrade to [email protected], thus this guard for now.
if (key !== null) {
val count = 0
responseHeaders.putString(key, value[count])
}
val response = stringBuilder.toString()
statusCode = connection.responseCode
res!!.headers = responseHeaders
res!!.body = response
res!!.statusCode = statusCode
}
val stringBuilder = StringBuilder()
var line: String?
while (responseStreamReader.readLine().also { line = it } != null) {
stringBuilder.append(line).append("\n")
}
val response = stringBuilder.toString()
statusCode = connection.responseCode
res!!.headers = responseHeaders
res!!.body = response
res!!.statusCode = statusCode
} catch (e: Exception) {
e.printStackTrace()
throw e
} finally {
connection?.disconnect()
request?.close()
responseStream?.close()
responseStreamReader?.close()
connection?.disconnect()
request?.close()
responseStream?.close()
responseStreamReader?.close()
}
}

Expand Down
4 changes: 3 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
presets: ['module:@react-native/babel-preset'],
presets: [
['module:react-native-builder-bob/babel-preset', { modules: 'commonjs' }],
],
};
33 changes: 16 additions & 17 deletions dr-pogodin-react-native-fs.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,29 @@ Pod::Spec.new do |s|
s.source = { :git => "https://github.com/birdofpreyru/react-native-fs.git", :tag => "#{s.version}" }

s.resource_bundles = { 'RNFS_PrivacyInfo' => 'ios/PrivacyInfo.xcprivacy' }
s.source_files = "ios/**/*.{h,m,mm}"

s.frameworks = "Photos"
s.source_files = "ios/**/*.{h,m,mm,cpp}"

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
if respond_to?(:install_modules_dependencies, true)
install_modules_dependencies(s)
else
s.dependency "React-Core"
s.dependency "React-Core"

# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
# Don't install the dependencies when we run `pod install` in the old architecture.
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
}
s.dependency "React-Codegen"
s.dependency "RCT-Folly"
s.dependency "RCTRequired"
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end
7 changes: 3 additions & 4 deletions example/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ source 'https://rubygems.org'
# You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
ruby ">= 2.6.10"

# Cocoapods 1.15 introduced a bug which break the build. We will remove the upper
# bound in the template on Cocoapods with next React Native release.
gem 'cocoapods', '>= 1.13', '< 1.15'
gem 'activesupport', '>= 6.1.7.5', '< 7.1.0'
# Exclude problematic versions of cocoapods and activesupport that causes build failures.
gem 'cocoapods', '>= 1.13', '!= 1.15.0', '!= 1.15.1'
gem 'activesupport', '>= 6.1.7.5', '!= 7.1.0'
Loading

0 comments on commit 39762ec

Please sign in to comment.