-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewExtensions.kt
84 lines (75 loc) · 1.94 KB
/
ViewExtensions.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package io.zenandroid.rxanimationexample.extensions
/**
* Created by alex on 21/11/2017.
*/
import android.view.View
import android.view.animation.OvershootInterpolator
import io.reactivex.Completable
fun View.showIf(show: Boolean) {
if (show) {
show()
} else {
hide()
}
}
fun View.show() {
this.visibility = View.VISIBLE
}
fun View.hide() {
this.visibility = View.GONE
}
fun View.slideIn(offset: Float): Completable {
return Completable.create {
visibility = View.VISIBLE
alpha = 0f
scaleX = 0f
scaleY = 0f
translationY = offset
animate().alpha(1f)
.translationY(0f)
.scaleX(1f)
.scaleY(1f)
.setDuration(200)
.setInterpolator(OvershootInterpolator())
.withEndAction(it::onComplete)
}
}
fun View.slideOut(offset: Float): Completable {
return Completable.create {
animate().alpha(0f)
.scaleX(0f)
.scaleY(0f)
.translationY(offset)
.setDuration(200)
.withEndAction {
visibility = View.GONE
it.onComplete()
}
}
}
fun View.fadeOut(duration: Long = 30): Completable {
return Completable.create {
animate().setDuration(duration)
.alpha(0f)
.withEndAction {
visibility = View.GONE
it.onComplete()
}
}
}
fun View.fadeIn(): Completable {
return Completable.create {
visibility = View.VISIBLE
alpha = 0f
animate().alpha(1f)
.setDuration(200)
.withEndAction(it::onComplete)
}
}
fun View.rotate(degree: Float): Completable {
return Completable.create {
animate().rotation(degree)
.setDuration(200)
.withEndAction(it::onComplete)
}
}