-
Notifications
You must be signed in to change notification settings - Fork 1
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
[iOS] Add workaround for using Moko in tests and previews #114
Open
JuliaJakubcova
wants to merge
2
commits into
develop
Choose a base branch
from
fix/moko-resources-workaround
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we still need this? 🤔 It seems to be created in the stencil files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried my best to remove the hack from swiftgen files, but this is the best I can do 😅 I think an iOS developer will know more about how they work and will be able to remove a lot of code and then this will not be needed anymore, but that's beyond my skills
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understandable 😅 I checked it and this file can be safely removed. But you don't have to do it here, I think.. We'll do that in MateeStarter.