1+ /*
2+ * Copyright 2025 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * https://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
117package com.example.compose.snippets.graphics
218
319import androidx.compose.animation.animateColor
@@ -20,6 +36,7 @@ import androidx.compose.foundation.layout.wrapContentSize
2036import androidx.compose.foundation.shape.RoundedCornerShape
2137import androidx.compose.material3.MaterialTheme
2238import androidx.compose.material3.Text
39+ import androidx.compose.runtime.Composable
2340import androidx.compose.runtime.LaunchedEffect
2441import androidx.compose.runtime.getValue
2542import androidx.compose.runtime.mutableStateOf
@@ -30,32 +47,30 @@ import androidx.compose.ui.Modifier
3047import androidx.compose.ui.draw.clip
3148import androidx.compose.ui.draw.dropShadow
3249import androidx.compose.ui.draw.innerShadow
50+ import androidx.compose.ui.draw.shadow
3351import androidx.compose.ui.graphics.Brush
3452import androidx.compose.ui.graphics.Color
53+ import androidx.compose.ui.graphics.RectangleShape
3554import androidx.compose.ui.graphics.shadow.Shadow
3655import androidx.compose.ui.tooling.preview.Preview
3756import androidx.compose.ui.unit.DpOffset
3857import androidx.compose.ui.unit.dp
3958import androidx.compose.ui.unit.sp
40- import kotlinx.coroutines.delay
41- import androidx.compose.runtime.Composable
42- import androidx.compose.ui.draw.shadow
43- import androidx.compose.ui.graphics.RectangleShape
4459import com.example.compose.snippets.ui.theme.SnippetsTheme
45-
46-
60+ import kotlinx.coroutines.delay
4761
4862// [START android_compose_graphics_simple_shadow]
4963@Preview(showBackground = true )
5064@Composable
5165fun SimpleShadow () {
52- Box (Modifier
53- .shadow(12 .dp, RectangleShape )
54- .size(100 .dp, 100 .dp))
66+ Box (
67+ Modifier
68+ .shadow(12 .dp, RectangleShape )
69+ .size(100 .dp, 100 .dp)
70+ )
5571}
5672// [END android_compose_graphics_simple_shadow]
5773
58-
5974// [START android_compose_graphics_simple_drop_shadow]
6075@Composable
6176@Preview(
@@ -78,7 +93,6 @@ fun SimpleDropShadowUsage() {
7893 )
7994 )
8095 .align(Alignment .Center )
81-
8296 .background(
8397 color = Color .White ,
8498 shape = RoundedCornerShape (20 .dp)
@@ -107,13 +121,11 @@ fun SimpleInnerShadowUsage() {
107121 .width(300 .dp)
108122 .height(200 .dp)
109123 .align(Alignment .Center )
110-
111- // note that the background needs to be defined before defining the inner shadow
124+ // note that the background needs to be defined before defining the inner shadow
112125 .background(
113126 color = Color .White ,
114127 shape = RoundedCornerShape (20 .dp)
115128 )
116-
117129 .innerShadow(
118130 shape = RoundedCornerShape (20 .dp),
119131 shadow = Shadow (
@@ -155,7 +167,6 @@ fun RealisticShadows() {
155167 .width(300 .dp)
156168 .height(200 .dp)
157169 .align(Alignment .Center )
158-
159170 .dropShadow(
160171 shape = RoundedCornerShape (100 .dp),
161172 shadow = Shadow (
@@ -165,7 +176,6 @@ fun RealisticShadows() {
165176 offset = DpOffset (x = 2 .dp, 8 .dp)
166177 )
167178 )
168-
169179 .dropShadow(
170180 shape = RoundedCornerShape (100 .dp),
171181 shadow = Shadow (
@@ -175,14 +185,12 @@ fun RealisticShadows() {
175185 offset = DpOffset (x = 0 .dp, 4 .dp)
176186 )
177187 )
178-
179-
180- // note that the background needs to be defined before defining the inner shadow
188+ // note that the background needs to be defined before defining the inner shadow
181189 .background(
182190 color = Color .Black ,
183191 shape = RoundedCornerShape (100 .dp)
184192 )
185- // //
193+ // //
186194 .innerShadow(
187195 shape = RoundedCornerShape (100 .dp),
188196 shadow = Shadow (
@@ -192,7 +200,6 @@ fun RealisticShadows() {
192200 offset = DpOffset (x = 6 .dp, 6 .dp)
193201 )
194202 )
195-
196203 .innerShadow(
197204 shape = RoundedCornerShape (100 .dp),
198205 shadow = Shadow (
@@ -202,7 +209,6 @@ fun RealisticShadows() {
202209 offset = DpOffset (x = 5 .dp, 5 .dp)
203210 )
204211 )
205-
206212 .innerShadow(
207213 shape = RoundedCornerShape (100 .dp),
208214 shadow = Shadow (
@@ -212,7 +218,6 @@ fun RealisticShadows() {
212218 offset = DpOffset (x = (- 3 ).dp, (- 12 ).dp)
213219 )
214220 )
215-
216221 .innerShadow(
217222 shape = RoundedCornerShape (100 .dp),
218223 shadow = Shadow (
@@ -222,7 +227,6 @@ fun RealisticShadows() {
222227 offset = DpOffset (x = 0 .dp, 0 .dp)
223228 )
224229 )
225-
226230 .innerShadow(
227231 shape = RoundedCornerShape (100 .dp),
228232 shadow = Shadow (
@@ -233,7 +237,6 @@ fun RealisticShadows() {
233237 )
234238 )
235239
236-
237240 ) {
238241 Text (
239242 " Realistic Shadows" ,
@@ -273,7 +276,7 @@ fun GradientBasedShadowAnimation() {
273276 Color (0xFF4cc9f0 )
274277 )
275278
276- // ..
279+ // ..
277280
278281 // State for the breathing animation
279282 var breathingState by remember { mutableStateOf(BreathingState .Inhaling ) }
@@ -316,7 +319,6 @@ fun GradientBasedShadowAnimation() {
316319 }
317320 }
318321
319-
320322 // Get text based on current state
321323 val breathingText = when (breathingState) {
322324 BreathingState .Inhaling -> " Inhale"
@@ -405,7 +407,7 @@ fun NeumorphicRaisedButton(
405407 offset = DpOffset (lowerOffset, lowerOffset)
406408 ),
407409
408- )
410+ )
409411 .background(bgColor, shape)
410412 )
411413}
@@ -490,19 +492,16 @@ fun AnimatedColoredShadows() {
490492 }
491493 // [END_EXCLUDE]
492494
493-
494-
495495 Box (
496496 Modifier
497497 .clickable(
498498 interactionSource, indication = null
499499 ) {
500- // ** ...... **//
500+ // ** ...... **//
501501 }
502502 .width(300 .dp)
503503 .height(200 .dp)
504504 .align(Alignment .Center )
505-
506505 .dropShadow(
507506 shape = RoundedCornerShape (70 .dp),
508507 shadow = Shadow (
@@ -513,7 +512,6 @@ fun AnimatedColoredShadows() {
513512 alpha = shadowAlpha
514513 )
515514 )
516-
517515 .dropShadow(
518516 shape = RoundedCornerShape (70 .dp),
519517 shadow = Shadow (
@@ -524,13 +522,11 @@ fun AnimatedColoredShadows() {
524522 alpha = shadowAlpha
525523 )
526524 )
527-
528- // note that the background needs to be defined before defining the inner shadow
525+ // note that the background needs to be defined before defining the inner shadow
529526 .background(
530527 color = Color (0xFFFFFFFF ),
531528 shape = RoundedCornerShape (70 .dp)
532529 )
533-
534530 .innerShadow(
535531 shape = RoundedCornerShape (70 .dp),
536532 shadow = Shadow (
@@ -540,7 +536,6 @@ fun AnimatedColoredShadows() {
540536 offset = DpOffset (x = 4 .dp, 0 .dp)
541537 )
542538 )
543-
544539 .innerShadow(
545540 shape = RoundedCornerShape (70 .dp),
546541 shadow = Shadow (
@@ -552,7 +547,6 @@ fun AnimatedColoredShadows() {
552547 )
553548 )
554549
555-
556550 ) {
557551 Text (
558552 " Animated Shadows" ,
@@ -570,7 +564,6 @@ fun AnimatedColoredShadows() {
570564}
571565// [END android_compose_graphics_animated_shadow]
572566
573-
574567// [START android_compose_graphics_neobrutal_shadow]
575568@Composable
576569@Preview(
@@ -613,4 +606,4 @@ fun NeoBrutalShadows() {
613606 }
614607 }
615608}
616- // [END android_compose_graphics_neobrutal_shadow]
609+ // [END android_compose_graphics_neobrutal_shadow]
0 commit comments