Hi! Any recommendations on providing overrides to ...
# kotlin-native
a
Hi! Any recommendations on providing overrides to methods that are not exposed from Kotlin Native? I’m trying to subclass a UIView and override sizeToFit right now, but it appears like this is purposefully not allowed. Is there a recommended work around for this?
s
Hi Adam, can't you just override -sizeThatFits? -sizeToFit calls that
a
Both don’t appear to be available
It looks like they are exposed as extension functions.
But you are correct, I meant
sizeThatFits
s
Can't find it either, sorry
a
Weird, is that intentional? Maybe I can expose it manually through Swift?
s
sizeThatFits
is declared in a category, so it is currently represented as extension method in Kotlin and thus can’t be overridden.
e
FWIW I would recommend against subclassing these methods even in Swift or (gasp) Obj-C - there’s some serious duct tape and spiders in that method, and anytime I’ve tried to subclass it, it’s ended in pain. If you tell us what you’re trying to accomplish, maybe myself or someone else can recommend an alternative.
a
Thanks!
s
Assuming you're using autolayout, if you have all of your child views constrained properly (height, width, x & y not ambiguous) the view will report a proper
intrinsicContentSize
that will work well with autolayout. To get rid of some of the ambiguities you may also have to set
contentHuggingPriority
and
contentCompressionResistance
on the child views.