Scenes are platform agnostic, and cannot (at least, should not) refer to
Android's View
classes directly.
Instead, specialized Container interfaces form a boundary
between the Navigational layer on the one side, and the Android View layer on
the other side.
This View layer needs to implement the Container, usually using View
classes.
Often, it is not feasible or wanted to let the the root View of the layout
implement this container directly, thus the need for an adapter-like class
arises: The ViewController.
The ViewController acts as the bridge between the Scene and the View: it 'controls' the View if you like. It implements the commands the Scene executes on the Container, and redirects them to the view:
1 class MyScene<MyContainer> : Scene {
2
3 override fun attach(myContainer: MyContainer) {
4 myContainer.text = "Hello, world!"
5 }
6 }
7
8 interface MyContainer: Container {
9
10 var text: String
11 }
12
13 class MyViewController(override val view: View) : ViewController, MyContainer {
14
15 override var text: String = ""
16 set(value) {
17 view.findViewById<TextView>(R.id.myTextView).text = value
18 }
19 }