#Kotlin #Android #delegation #Composition_over_Inh...
# feed
d
#Kotlin #Android #delegation #Composition_over_Inheritance Just wrote this article on Medium, hoping it's appreciated 🙂 “Composition over inheritance on Activity and Fragment” by Davide Giuseppe Farella https://link.medium.com/lhOVEDU6sX
👍 1
m
Imo biggest drawaback here is
initRotationEnabledComponent
. I wish Kotlin would support
by RotatioEnabledDelegate(this)
d
That's half true, because I'm my real case scenario I wanted to save the initial rotation in
onStart
, so going back to the previous activity I will have the right rotation, otherwise if I'm in portrait, go in background, go in landscape, back to my app and press back, I'll be sent back to my old portrait rotation. Even worst, in a
Fragment
you won't have access to the Activity when it's created, you will have lazily when
onActivityCreated
So this is more a platform limitation
You could trick it getting the
LifecycleOwner
in a similar way:
m
Is the delegation really needed here? Wouldn't it be much simpler if
RotationEnabled
was just normal field in activity/fragment?
d
Well, it would be less noisy to have
by Delegate
than have a reference to call in every place
rotationDelegate.rotate( )
👍 1
m
true
t
@Davide Giuseppe Farella how about making
RotatioEnabledDelegate
become a
LifecyclerObserver
d
Yes, it could be an idea. There are many ways to improve it, just wanted to keep the example simple.