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

Andreas Jost

03/03/2020, 2:08 PM
Hi, is there a way to express hierarchy with expect/actual in Multiplatform? Let's say you have an expected class
ViewContainer
, which is a typealias for
View
on Android-side and
UIView
on iOS-side. And an extension function
ViewContainer.setVisibility(isVisible: Boolean)
. And you also have a second expected class
TextField
, which is a typealias for Android
EditText
/ iOS
UITextField
.
EditText
is a subclass of
TextView
, which is a subclass of
View
.
UITextField
is a subclass of
UIControl
, which is a subclass of
UIView
. So both are related to `View`/`UIView` (
ViewContainer
). It would be nice to tell that the compiler, so that you can invoke the function
setVisibility()
not only on
ViewContainer
, but also on
TextField
or other related classes. Obviously
expect class TextField : ViewContainer
won't work, because it isn't a direct child class. So one way is not having a hierarchy and copy/paste the same extension function with the same implementation to
TextField
and every View type. But shouldn't there be any better solution?
a

alex009

03/03/2020, 3:13 PM
also if you want create screens and navigation from common code - you can check https://github.com/icerockdev/moko-widgets/
5 Views