Skip to content

Commit 984ab85

Browse files
Merge pull request SmartToolFactory#34 from shahzadansari/fix/tutorial2.11-preview-not-interactive
Tutorial 2.11 - Fix non-interactive Previews
2 parents 27eaa88 + b4e8a0d commit 984ab85

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Tutorial1-1Basics/src/main/java/com/smarttoolfactory/tutorial1_1basics/chapter2_material_widgets/Tutorial2_11SnackProgressSelection.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import androidx.compose.ui.text.font.FontWeight
5353
import androidx.compose.ui.tooling.preview.Preview
5454
import androidx.compose.ui.unit.dp
5555
import androidx.compose.ui.unit.sp
56+
import com.smarttoolfactory.tutorial1_1basics.isInPreview
5657
import com.smarttoolfactory.tutorial1_1basics.ui.components.StyleableTutorialText
5758
import com.smarttoolfactory.tutorial1_1basics.ui.components.TutorialHeader
5859
import com.smarttoolfactory.tutorial1_1basics.ui.components.TutorialText2
@@ -100,12 +101,15 @@ private fun SnackBarExample() {
100101

101102
TutorialText2(text = "Action SnackBar")
102103
val context = LocalContext.current
104+
val isInPreview = isInPreview
103105
Snackbar(modifier = Modifier.padding(4.dp),
104106
action = {
105107
Text(
106108
text = "Action",
107109
modifier = Modifier.clickable {
108-
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
110+
if (!isInPreview) {
111+
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
112+
}
109113
})
110114
}) {
111115
Text("Action Snackbar")
@@ -118,7 +122,9 @@ private fun SnackBarExample() {
118122
Text(text = "Action",
119123
color = Color(0xffCE93D8),
120124
modifier = Modifier.clickable {
121-
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
125+
if (!isInPreview) {
126+
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
127+
}
122128
}
123129
)
124130
}) {
@@ -137,7 +143,9 @@ private fun SnackBarExample() {
137143
Text(
138144
text = "Action",
139145
modifier = Modifier.clickable {
140-
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
146+
if (!isInPreview) {
147+
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
148+
}
141149
})
142150
}) {
143151
Text("Snackbar with custom shape and colors")
@@ -154,7 +162,9 @@ private fun SnackBarExample() {
154162
color = Color(0xffD32F2F),
155163
fontWeight = FontWeight.Bold,
156164
modifier = Modifier.clickable {
157-
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
165+
if (!isInPreview) {
166+
Toast.makeText(context, "Action is clicked", Toast.LENGTH_SHORT).show()
167+
}
158168
})
159169
}) {
160170
Text("Snackbar with custom shape and colors")

0 commit comments

Comments
 (0)