On Android we have the `BackHandler`. Is there something similar (or even the same) for iOS? And wha...
m
On Android we have the
BackHandler
. Is there something similar (or even the same) for iOS? And what is the equivalent of
Activity.finish()
?
d
1. "fun BackHandler" for now located in android source set. And can be used only inside android code. On UiKit we can use button in topLeft corner with onClick handlers. I think, we can provide screen template like a Scaffold with common parts of UiKit screen. Do you have some expectations, or suggestions? 2. We don't have equivalent of
Activity.finish()
yet
m
Such a UIKit specific Scaffold sounds nice but before I can make any suggestions I first have to learn more about the iOS navigation concepts. I just realise that it is not so easy to write a Compose app which is also expected to work on iOS if you have never had an actual iPhone in your hand 😉.
l
It seems like the iOS equivalent of Activities is UIViewController. There’s not a ‘finish’ or ‘result’ concept like in Android. Looks like you call
dismiss
on the parent of the view controller you want to dismiss. If you want results, there’s no API like in Android. You have to implement a callback.
However, Compose on Android seems to be wanting to replace multiple Activities, so I could see Compose on iOS doing the same.
d
Having worked on both platforms I would say that UIViewController is more like a full-screen Fragment, and that there simply is no concept that matches Activities.
l
That’s fair. I worked on a legacy system during the time when fragments were supposedly good, so I never really worked with them.
d
Every iOS App is in a sense like a single Activity Android App.
I suspect Activities were originally devised with very memory constrained devices in mind, since (at least before Fragments existed) they coerce you to break your App up into units so that memory can be completely reclaimed when moving from one part of the App to another (and only what you Parcel out survives).
This actually felt weirdly restrictive to me when I first came from iOS to Android many years ago.
iOS always gave you a strict memory budget but let you do whatever you wanted within that.
...in terms of passing objects by reference between UIViewControllers.
l
I’d imagine Activities were an early answer to intents from another app. If I’m passing objects around, it makes it hard to start from a specific screen. Activities create a path of least resistance that allows you to start from any Activity.
a
Yeah, the hierarchy is your UIWindow which contains a UIView that is most likely a UIViewController, and those UIViewControllers can be nested, etc
Whereas ofcourse, Android is Window -> Activity -> View or Fragment -> View