Piggybacking off this. Is it possible to create a ...
# ios
b
Piggybacking off this. Is it possible to create a cocoapod/SPM that depends on a KMP library? Essentially a wrapper around it to abstract away the Kotlin <-> object interop and make it a cleaner DX for iOS devs?
t
KMP code may be exported as an xcframework which can be vendored as a
binaryTarget
in an SPM package or a
spec.vendored_frameworks
in a CocoaPods spec. Could this be what you are looking for?
b
Yep that’s the route I’m going through right now. Happy to see I’m on the right track. Just need to see if my resources will be accessible
ok stood up a framework in XCode and built an XCFramework depending the KMM one. Created an app project that uses cocoapods and uses that pod but getting an immediate crash in ComposeContainer.uikit
Containing pod/framework is one class/struct that calls a ComposeUIViewController
Copy code
public struct Badge : UIViewControllerRepresentable {

    @State public var count: Int32

    @MainActor public init(count: Int32) {
        _count = State(initialValue: count)
    }

    public func makeUIViewController(context: Context) -> UIViewController {
        ComponentsKt._Badge(count: count)
    }

    public func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        
    }
}
example app is simply
Copy code
struct ContentView: View {
    var body: some View {
        VStack {
            Image(systemName: "globe")
                .imageScale(.large)
                .foregroundStyle(.tint)
            HStack {
                Text("Hello, world!")
                Badge(count: 3)
            }
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
i see line 428 called out in the stack trace from XCode which points to this in ComposeContainer.uikit
Copy code
internal val uiContentSizeCategoryToFontScaleMap = mapOf(
+   UIContentSizeCategoryExtraSmall to 0.8f,
    UIContentSizeCategorySmall to 0.85f,
    UIContentSizeCategoryMedium to 0.9f,
    UIContentSizeCategoryLarge to 1f, // default preference
    UIContentSizeCategoryExtraLarge to 1.1f,
    UIContentSizeCategoryExtraExtraLarge to 1.2f,
    UIContentSizeCategoryExtraExtraExtraLarge to 1.3f,

    // These values don't work well if they match scale shown by
    // Text Size control hint, because iOS uses non-linear scaling
    // calculated by UIFontMetrics, while Compose uses linear.
    UIContentSizeCategoryAccessibilityMedium to 1.4f, // 160% native
    UIContentSizeCategoryAccessibilityLarge to 1.5f, // 190% native
    UIContentSizeCategoryAccessibilityExtraLarge to 1.6f, // 235% native
    UIContentSizeCategoryAccessibilityExtraExtraLarge to 1.7f, // 275% native
    UIContentSizeCategoryAccessibilityExtraExtraExtraLarge to 1.8f, // 310% native

    // UIContentSizeCategoryUnspecified
)
p
Just guessing a bit, is the compose-mp binaries being packed into the Xcframework?
Judging by the stacktrace, seems that a function reference from compose wasn't found or changed signature maybe. Indicating probably the compose library wasn't loaded in the Xcf
b
Yeah XCF added to the iOS framework and and an xcf built from that. That vendored in a podspec to the app
p
When you created the kmm Xcf pod, did you use dynamic linking maybe 🤔. I think only static is supported.
b
Static since I’m depending on other pods
p
Ah ok, cool. Well, good luck is all I can wish you 😀
b
Haha I’m sure there is way to make this work
💯 1
Thinking it’s a transitiveExport thing maybe 🤔
p
I believe so, that is why I would ensure the compose-mp binaries are inside the framework. Because CMP has no way to be resolved either in SPM or cocoapods repos. AFAIK jetbrains don't have it hosted anywhere. So the only way is doing local compilation, so the kmp plugin includes compose in the podframework, and then you host this podframework in a cocoapods repo. But I guess only hosting this binary will work, not the code itself
b
Ya may have to export all/some/one of the compose dependencies too
👆 1
1
interestingly if I skip the container framework and add Badge() directly to the Example it compiles and runs w/o a crash
so it's something outside of the KMP xcf thats the issue
and is an issue in the xcf generation/build for the abstract
p
Humm 🧐🤔 interesting