https://kotlinlang.org logo
Title
r

ribesg

02/07/2020, 4:02 PM
Any idea how I could work around the fact you can’t override
UIView.draw
?
It’s exposed to Kotlin as an
@ObjCMethod external
extension function of
UIView
So obviously this does not work
l

louiscad

02/07/2020, 7:03 PM
@ribesg remove
external
and
@ObjCMethod
, it should work after that. That's a tooling issue, reporting it would make sense.
r

ribesg

02/08/2020, 10:47 AM
Oh, didn't even check if it was an IDE issue and actually compiled
l

louiscad

02/08/2020, 5:13 PM
You confirm it now works?
r

ribesg

02/10/2020, 9:30 AM
It doesn’t seem to work, no. But as the IDE doesn’t help I’m not sure what I write is correct anyway. It says it overrides nothing, as I expected
The function I want to override:
@kotlinx.cinterop.ObjCMethod public external fun platform.UIKit.UIView.drawRect(rect: kotlinx.cinterop.CValue<platform.CoreGraphics.CGRect>): kotlin.Unit { /* compiled code */ }
@louiscad what makes you think it should work? Did you manage to make it work in some case already? https://kotlinlang.org/docs/reference/native/objc_interop.html#category-members
l

louiscad

02/10/2020, 9:43 AM
Oh, that's a category member! I don't recall for which function I made it work, but it seems that is a current limitation of Kotlin/Native. @kpgalligan do you know why there is this limiation, and if there's a workaround?
r

ribesg

02/10/2020, 9:50 AM
Well.
While the use of drawRect is common, it’s a practice that has been discouraged since at least 2002/2003
Apparently you should ‘now’ (and for the last 18 years) use drawLayer, which can be overridden apparently. But yeah the question’s still there, will we be able to override these at some point?