-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiplePreviews.kt
114 lines (104 loc) · 2.61 KB
/
MultiplePreviews.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.kotlindojo.learningpreviews.ui.previews
import android.content.res.Configuration
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import com.kotlindojo.learningpreviews.R
import com.kotlindojo.learningpreviews.TextSample
import com.kotlindojo.learningpreviews.ui.theme.LearningPreviewsTheme
/**
* Stack them
* https://developer.android.com/jetpack/compose/tooling?hl=it&skip_cache=false#preview-multipreview
*/
@Preview(name = "0", group = "Stack")
@Preview(name = "1", group = "Stack")
@Preview(name = "2", group = "Stack")
@Composable
fun StackPreviews() {
LearningPreviewsTheme {
TextSample()
}
}
/**
* Multipreview Annotations
* Multiple @Preview annotations with different configurations that can be applied across multiple
* composables.
*
* Note: Available from Android Studio Dolphin and Jetpack Compose 1.2.0-beta01.
*
* https://developer.android.com/jetpack/compose/tooling?hl=it&skip_cache=false#preview-multipreview
*/
// First we create it
@Preview(
name = "Small",
group = "Multipreviews",
fontScale = 0.5f
)
@Preview(
name = "Medium",
group = "Multipreviews",
fontScale = 1f
)
@Preview(
name = "Large",
group = "Multipreviews",
fontScale = 1.5f
)
annotation class FontScalePreviews
// Now we use it
@FontScalePreviews
@Composable
fun MultipreviewsAnnotation() {
LearningPreviewsTheme {
TextSample(text = "Hello Scale")
}
}
@FontScalePreviews
@Composable
fun ScaleFontAgain() {
Text("More scale?", color = Color.Magenta)
}
/**
* Combine Multipreviews for a single Composable
*/
// Create them
@Preview(
name = "Night",
group = "Combo",
uiMode = Configuration.UI_MODE_NIGHT_YES
)
@Preview(
name = "Day",
group = "Combo",
uiMode = Configuration.UI_MODE_NIGHT_NO
)
annotation class UiModePreviews
@Preview(
name = "English",
group = "Combo",
locale = "en"
)
@Preview(
name = "Bahasa Indonesia",
group = "Combo",
locale = "in-rID" // Setup locale https://developer.android.com/training/basics/supporting-devices/languages
)
annotation class LocalePreviews
// Put them together
@UiModePreviews
@LocalePreviews
annotation class ComboPreview
// Use them
@ComboPreview
@Composable
fun Combo() {
LearningPreviewsTheme {
Surface(color = MaterialTheme.colors.primary) {
Text(text = stringResource(R.string.greeting))
}
}
}