https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
k

Koneko Toujou

02/05/2023, 2:32 AM
is it possible to import an annotation depending on the platform? for example
androidx.compose.ui.tooling.preview.Preview
for
Android
androidx.compose.desktop.ui.tooling.preview.Preview
for
Desktop
CommonMain
use
@Preview
which resolves to the above at compilation/analysis
👀 1
c

Chrimaeon

02/05/2023, 10:04 AM
you can create you own annotation with
expect
and then have `typealias`’s the
actual
annotation.
k

Koneko Toujou

02/05/2023, 10:04 AM
o.o
can you give an example please?
c

Chrimaeon

02/05/2023, 10:05 AM
commonMain
Copy code
@Target(AnnotationTarget.FUNCTION)
expect annotation class CommonPreview()
androidMain
Copy code
actual typealias CommonPreview = androidx.compose.ui.tooling.preview.Preview
jvmMain
Copy code
actual typealias CommonPreview = androidx.compose.desktop.ui.tooling.preview.Preview
k

Koneko Toujou

02/05/2023, 10:07 AM
o.o awesome
thanks
if i have
Copy code
import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable

actual typealias CommonPreview = androidx.compose.desktop.ui.tooling.preview.Preview
can i use
actual typealias CommonPreview = Preview
c

Chrimaeon

02/05/2023, 10:11 AM
sure, if you import it.
k

Koneko Toujou

02/05/2023, 10:11 AM
🙂
hmm
Copy code
> Task :common:compileKotlinDesktop
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\common\src\commonMain\kotlin\smallville7123\lua\jit\kotlin\common\App.kt: (18, 41): Expecting a top level declaration
e: C:\Users\clark\IdeaProjects\LuaJIT_Kotlin_MultiPlatform\common\src\commonMain\kotlin\smallville7123\lua\jit\kotlin\common\App.kt: (18, 44): Expecting a top level declaration
Copy code
@Target(AnnotationTarget.FUNCTION)
expect annotation class CommonPreview() as Preview
c

Chrimaeon

02/05/2023, 11:37 AM
Remove the
as Preview
- that’s what you want to avoid.
k

Koneko Toujou

02/05/2023, 11:51 AM
yea
2 Views