I am implementing an Emoji picker on Kotlin Multiplatform with Compose Multiplatform. Since there is no multiplatform for androidx.emoji2:emojipicker, I implement this Composable using and expected and actual implementation.
// shared/commonMain/kotlin
@Composable
expect fun EmojiPicker()
// shared/androidMain/kotlin/EmojiPicker.kt
@Composable
actual fun EmojiPicker() {
AndroidView(factory = { context -> EmojiPickerView(context) })
}
This works fine until I try to customize the EmojiPicker as stated in its documentation:
Create your own style to override common theme attributes and apply the style to the EmojiPickerView.
On native Android I would implement this custom style in the styles.xml. This does not work with Kotlin Multiplatform.
// shared/androidMain/res/values/styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="EmojiPicker"/>
</resources>
// shared/androidMain/kotlin/EmojiPicker.kt
@Composable
actual fun EmojiPicker() {
AndroidView(
factory = { context ->
// Error: Unresolved reference 'R'
EmojiPickerView(contex, null, R.style.EmojiPicker)
},
)
}
How do I apply either XML resources on Android Views within an actual declaration or a style without using XML?
Source: View source