-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewKey.kt
64 lines (49 loc) · 1.65 KB
/
ViewKey.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.github.gumil.testnavigator.common
import android.content.Intent
import android.os.Parcelable
import android.support.annotation.MenuRes
import android.view.Menu
import android.view.MenuItem
import com.zhuinden.simplestack.navigator.ViewChangeHandler
internal abstract class ViewKey : Parcelable {
val layout by lazy {
layout()
}
abstract protected fun layout(): ViewLayout
abstract fun viewChangeHandler(): ViewChangeHandler
/**
* Lifecycle: When animation is started. By this time view is already attached.
*/
open fun onChangeStarted() {}
/**
* Lifecycle: When animation is ended
*/
open fun onChangeEnded() {}
/**
* Lifecycle: When view is removed
*/
open fun onViewRemoved() {}
open fun onBackPressed() = false
/**
* Lifecycle: Called from host activity, handling for activityResults
*/
open fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {}
override fun describeContents() = hashCode()
/**
* Lifecycle: Called when creating options menu
* @return Menu Resource
*/
@MenuRes
open fun onCreateOptionsMenu(): Int = -1
open fun onOptionsItemSelected(item: MenuItem) = false
/**
* @return flag to know if the Previous View should be removed from the container
* Sometimes we need to make the previous view visible like we do with dialogs
*/
open fun shouldPreviousViewBePersisted() = false
/**
* Lifecycle: Called when view was destroyed and readded immediately
* Only called when shouldPreviousViewBePersisted() is set to true
*/
open fun restoreState() {}
}