Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#708 slow first time use of resources ios #715

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package dev.icerock.moko.resources.desc

import kotlin.native.concurrent.ThreadLocal
import platform.Foundation.NSBundle
import platform.Foundation.NSLocale
import platform.Foundation.NSLocaleCountryCode
Expand All @@ -13,6 +12,7 @@ import platform.Foundation.NSLocaleVariantCode
import platform.Foundation.currentLocale
import platform.Foundation.localeIdentifier
import platform.Foundation.localeIdentifierFromComponents
import kotlin.native.concurrent.ThreadLocal

actual interface StringDesc {
fun localized(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ import platform.Foundation.NSURL
import platform.Foundation.pathExtension

fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle {
// try get already loaded bundle
NSBundle.bundleWithIdentifier(identifier)?.let { return it }

val bundlePath: String = NSBundle.mainBundle.bundlePath
val enumerator: NSDirectoryEnumerator = requireNotNull(NSFileManager.defaultManager.enumeratorAtPath(bundlePath))
while (true) {
val relativePath: String = enumerator.nextObject() as? String ?: break
val url = NSURL(fileURLWithPath = relativePath)
if (url.pathExtension == "bundle") {
val fullPath = "$bundlePath/$relativePath"
val loadedIdentifier: String? = NSBundle.bundleWithPath(fullPath)?.bundleIdentifier
val foundedBundle: NSBundle? = NSBundle.bundleWithPath(fullPath)
val loadedIdentifier: String? = foundedBundle?.bundleIdentifier

if (isBundleSearchLogEnabled) {
println("moko-resources auto-load bundle with identifier $loadedIdentifier at path $fullPath")
}

if (foundedBundle?.bundleIdentifier == identifier) return foundedBundle
}
}

return bundleWithIdentifier(identifier)
?: throw IllegalArgumentException("bundle with identifier $identifier not found")
throw IllegalArgumentException("bundle with identifier $identifier not found")
}

var isBundleSearchLogEnabled = false
Loading