is it possible to import an annotation depending o...
# multiplatform
k
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
you can create you own annotation with
expect
and then have `typealias`’s the
actual
annotation.
k
o.o
can you give an example please?
c
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
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
sure, if you import it.
k
🙂
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
Remove the
as Preview
- that’s what you want to avoid.
k
yea