``` override fun onBackPressed() { dra...
# announcements
m
Copy code
override fun onBackPressed() {
        drawer?.run {
            if (!isDrawerOpen) {
                openDrawer()
                this
            } else null
        } ?: super.onBackPressed()
    }
n
maybe
drawer?.takeIf { !isDrawerOpen }?.apply { openDrawer() }
to avoid if else null and you can also ret rid of the run block then
m
Looks good, but
isDrawerOpen
is a method of the
drawer
, so it won't work inside the
takeIf
(and I can't do
drawer.isDrawerOpen
inside since it can be null).
c
Doesn't takeif provide the object as a lambda parameter?
i.e. I think you should be able to write takeif { !it.isdraweropen }
And I'd use takeunless instead of takeif with negation
k
isDrawerOpen
doesn't seem to be a member function of
drawer
m
drawer?.takeUnless { it.isDrawerOpen }?.apply { openDrawer() } ?: super.onBackPressed()
works great! Thank you Jerzy, pozdrawiam. 🙂 Karel:
drawer
is the receiver in
run
which is why
isDrawerOpen
doesn't look like it uses it.
🤦‍♂️ 1