This repository was archived by the owner on Jun 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[iOS] Add workaround for using Moko in tests and previews #114
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
ios/PresentationLayer/UIToolkit/Sources/UIToolkit/Extensions/Bundle+Extensions.swift
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
ios/PresentationLayer/UIToolkit/Sources/UIToolkit/Extensions/BundleToken.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // | ||
| // Created by Petr Chmelar on 30.05.2022 | ||
| // Copyright © 2022 Matee. All rights reserved. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| private final class BundleToken {} |
20 changes: 20 additions & 0 deletions
20
ios/PresentationLayer/UIToolkit/Sources/UIToolkit/Utilities/MokoFix.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // Created by Julia Jakubcova on 23/09/2024 | ||
| // Copyright © 2024 Matee. All rights reserved. | ||
| // | ||
|
|
||
| import DevstackKmpShared | ||
|
|
||
| #warning("TODO: Remove this workaround when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved") | ||
| public func fixMokoResourcesForTests() { | ||
| if ProcessInfo.processInfo.processName == "xctest" { | ||
| MokoResourcesPreviewWorkaroundKt.nsBundle = Bundle.init(for: KotlinBase.self) | ||
| } | ||
| } | ||
|
|
||
| #warning("TODO: Remove this workaround when issue [https://github.com/icerockdev/moko-resources/issues/714] is resolved") | ||
| public func fixMokoResourcesForPreviews() { | ||
| if ProcessInfo.processInfo.processName == "XCPreviewAgent" { | ||
| MokoResourcesPreviewWorkaroundKt.nsBundle = Bundle.init(for: KotlinBase.self) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
shared/src/iosMain/kotlin/dev/icerock/moko/resources/utils/MokoResourcesPreviewWorkaround.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package dev.icerock.moko.resources.utils // must be same as in moko-resources to override method | ||
|
|
||
| import platform.Foundation.NSBundle | ||
| import platform.Foundation.NSDirectoryEnumerator | ||
| import platform.Foundation.NSFileManager | ||
| import platform.Foundation.NSURL | ||
| import platform.Foundation.pathExtension | ||
|
|
||
| /** | ||
| * Workaround by MAX-POLKOVNIK from https://github.com/icerockdev/moko-resources/issues/747#issuecomment-2330854244 | ||
| * Remove when https://github.com/icerockdev/moko-resources/issues/747 is resolved | ||
| */ | ||
|
|
||
| var nsBundle: NSBundle = NSBundle.mainBundle // <-- this is where we should looking for resources, by default mainBundle | ||
|
|
||
| fun NSBundle.Companion.loadableBundle(identifier: String): NSBundle { | ||
| val bundlePath: String = nsBundle.bundlePath // <-- path where we should search for bundle with resources | ||
| 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 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 | ||
| } | ||
| } | ||
|
|
||
| throw IllegalArgumentException("bundle with identifier $identifier not found") | ||
| } | ||
|
|
||
| var isBundleSearchLogEnabled = false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.