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

Fix SwiftUI preview crashes when accessing assets from a nested Swift Package. #171

Merged
merged 7 commits into from
Jun 10, 2022

Conversation

y-okudera
Copy link
Contributor

Hi, Thank you for an amazing utility!

Fixed SwiftUI preview crashes when accessing assets from a nested Swift Package.

Crash Info

I have two modules the Presentation and the DesignSystem.
The DesignSystem module has Color extension generated by figma-export.
The Presentation module has SwiftUIView that using Color extension of DesignSystem. As soon as it touches the assets from the DesignSystem module, the preview crashes.

スクリーンショット 2022-05-29 18 49 48

Reference

https://developer.apple.com/forums/thread/664295?login=true#reply-to-this-question

@subdan
Copy link
Collaborator

subdan commented May 30, 2022

Thanks for the PR, @y-okudera. I will review the PR by the end of the week.

@y-okudera
Copy link
Contributor Author

@subdan
Thank you for reply.
I'm sorry, I completely forgot to fix the test code. I will commit it later.

Comment on lines 19 to 20
{% if resourceBundleNames %}
private extension Foundation.Bundle {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have the same private extension Foundation.Bundle... code in four Stencil files. Avoid code duplication by extracting duplicated code in a separate file and use Stencil's include keyword.

Sources/FigmaExport/Resources/iOSConfig.swift Outdated Show resolved Hide resolved
@@ -105,6 +105,7 @@ struct Params: Decodable {
let xcassetsPath: URL
let xcassetsInMainBundle: Bool
let xcassetsInSwiftPackage: Bool?
let resourceBundleNames: [String]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter must be optional to support backward compatibility. If this parameter will be required, current FigmaExport users will need to specify a value to this property. Moreover a lot of users don't store xcassets in the Swift Package and won't specify a value for this property.

@y-okudera
Copy link
Contributor Author

@subdan
Thanks for the review. Those code fixes have been completed.

// Bundle should be present here when the package is linked into a framework.
Bundle(for: BundleFinder.self).resourceURL,
// Bundle should be present here when the package is used in UI Tests.
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test-code must not be included in release build. Use #if DEBUG.

Comment on lines 18 to 20
// Bundle should be present here when running previews from a different package (this is the path to "…/Debug-iphonesimulator/").
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent(),
Bundle(for: BundleFinder.self).resourceURL?.deletingLastPathComponent().deletingLastPathComponent()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@y-okudera
Copy link
Contributor Author

Thanks for the re-review, @subdan . I will fix the stencil file by the end of the week.

@subdan subdan merged commit 8d764c3 into RedMadRobot:master Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants