Hi everyone. I'm setting up a MultiPlatform projec...
# multiplatform
z
Hi everyone. I'm setting up a MultiPlatform project with two platforms (JVM and Android). And I have a common UI using Compose. Let's say I also have a function which reads an NFC card connected to the JVM machine/Android. For this, I created a
actual/expect fun readCard()
Now the issue is, the function needs 3 strings of keys to read the card. So, I made the code as
expect fun readCard(k1: String, k2: String, k3: String).
In addition to this, for Android, it needs a
Tag
object as well. Now, how do I pass it to the function. I cannot add the Tag as 4th argument because in common:desktopMain, it doesn't know about what Tag is and it doesn't need. Alternatively I can make it as
Any
. But do you also think that is the only option or is there any better way?
b
Expect/actual tag too and require it for jvm actual too and just don't use it?
Although it sounds like a job for interfaces and DI
z
That Tag class is a part of the Android SDK. So, I cannot put that in arguments
b
You can. actual typealias on android, shell class on jvm
Although I'm not sure how you'd go about obtaining it on common. Maybe another expect provider fun?
z
Yeah. In common for expect function also I cannot add this Tag argument. Even for the provider, we have to declare the return type as well right.
b
Which would be your expect Tag
z
This code is in common module. Tag class not available here.
neither I can put as argument nor I can set as return type. That Tag class is available only in android module or in the common:androidMain
Copy code
// commonMain
expect class Tag

// androidMain
actual typealias Tag = android.nfc.Tag

// jvmMain
actual class Tag
z
Ohh.. that's neat. I failed to understand it without an example 😅. Thank you.
f
@Zeeshan Syed Is there a library for NFC?`Something like https://github.com/revtel/react-native-nfc-manager for react native?