Reedyuk / blue-falcon

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android
https://bluefalcon.dev
Apache License 2.0
321 stars 43 forks source link

Addition of Compose Multiplatform example project #115

Closed neelratanguria closed 6 months ago

neelratanguria commented 6 months ago

It would be really helpful if this repository provided an example of Compose Multiplatfrom project as well. FYI, I managed to get the CMP project running fine, but it costed me more than 4hrs. I would love to contribute the boilerplate this repo.

Quick note: I was really confused when initializing the BlueFalcon object on iOS side, because the way it was inject directly into the ViewModel in KMP project. Then, I realised that ContextApplication can be garbage for initializing the iOS implementation. Here is how it looks like

AppModule.ios.kt

actual class AppModule {
    actual val blueFalcon: BlueFalcon
        get() = BlueFalcon(ApplicationContext(), null)
}

AppModule.android.kt

actual class AppModule(
    private val context: Context
) {
    actual val blueFalcon: BlueFalcon
        get() = BlueFalcon(context as ApplicationContext, null)
}
Reedyuk commented 6 months ago

Hi @neelratanguria - i dont have the time to do a compose multiplatform example but welcome any pr's that introduce one. As for the context, its probably not very clear in the docs. You can pass null, nsbundle or even UIApplication.

neelratanguria commented 6 months ago

I will do it then i guess

neelratanguria commented 6 months ago

Hi @Reedyuk, I have created a pull request for the discussed example. Please do review it.

Reedyuk commented 6 months ago

Many thanks for your change, i have merged in.