B1 متوسط English 7:20 858 لغت Science & Tech

Shadows In Compose | Jetpack Compose Tips

English with Lucy · 10,081 بازدید · Added 1 ساعت پیش

Learning Stats

B1

سطح CEFR

858

Total Words

390

Unique Words

5/10

Difficulty

Vocabulary Diversity 45%

زیرنویس‌ها (130 segments)

Download
00:00

ADHITHYA RAMAKUMAR: Users love apps with depth, dimension,

00:03

and realism.

00:04

One of the easiest, yet effective, ways to achieve this

00:08

is shadows.

00:10

For a long time, our mechanisms for rendering shadows

00:14

were constrained to different elevation levels.

00:17

While you can still leverage these presets,

00:20

they historically lacked a straightforward bot

00:23

for fine-grained control that you

00:25

have in popular design tools.

00:28

However, our latest Compose APIs now

00:32

grant us a great level of precision

00:35

with two new powerful modifiers, drop shadows and inner shadows.

00:41

In the next few minutes, we will go beyond rudimentary elevation

00:46

to construct truly delightful user interfaces,

00:49

all through shadows.

00:50

All right, let's dive in.

00:52

[MUSIC PLAYING]

00:57

Typically, design specs for shadows

01:00

revolve around four fundamental parameters.

01:04

These include the x and y offsets,

01:08

the blur radius, the spread, and, of course, the color.

01:14

The drop shadow modifier provides an interface for you

01:18

to control each of these aspects through its shadow parameter.

01:23

Let's look at how to use drop shadow.

01:26

The radius parameter dictates the softness and diffusion

01:30

of your blur.

01:32

Spread controls the expansion or contraction

01:36

of the shadow's geometry.

01:39

Color allows you to define the shadow's tint.

01:43

And offset precisely positions the shadow's geometry

01:47

along the x and y-axes.

01:51

The shape parameter helps define the shadow's overall contour.

01:56

This can be a standard rounded corner shape,

01:59

as seen in this example, or it can

02:02

use any geometry, such as the distinctive cookie

02:05

nine-sided shape, introduced with our recent material

02:08

expressive APIs.

02:09

Now, to create the inverse effect,

02:11

you can use inner shadow.

02:14

This creates the illusion that an element

02:17

is recessed or pressed into the underlying surface.

02:21

It is crucial to remember the rendering order.

02:25

You must first draw your background content

02:27

and then apply the inner shadow modifier

02:30

to achieve the desired concave appearance.

02:34

The true potential of these modifiers

02:37

is unlocked when you realize they can be layered.

02:40

Instead of a single shadow, you can compose multiple shadows

02:44

sequentially, each with distinct colors, blurs, and offsets.

02:49

This technique enables a vast spectrum of effects,

02:52

from subtle highlights to the vibrant, colorful glows seen

02:56

here.

02:58

To begin with, we apply the first layer of our drop shadow.

03:02

Next, we chain a second drop shadow layer on top of it

03:06

with slightly different offsets.

03:10

Then we apply the background color to the component.

03:14

And finally, we apply the inner shadow modifiers.

03:19

This deliberate chaining of drop and inner shadows

03:22

is what produces the depth effect we are aiming for.

03:27

While static shadows are effective,

03:29

dynamic shadows are way more exciting.

03:32

By integrating our shadow properties

03:34

with Compose's animation APIs, we

03:37

can make our UI respond directly to user interaction.

03:42

So when a user presses a button, the shadow

03:44

can change to provide instantaneous feedback.

03:48

To achieve this effect, we first define an outer box

03:51

and attach a clickable modifier to it.

03:54

We then declare the start and end states

03:57

for the various parameters we intend to animate.

04:00

To ensure all animations are perfectly synchronized,

04:04

we leverage updateTransition and provide it

04:07

with a desired target state.

04:10

Here, we define our buttonPressAnimation

04:12

specification, which will control the timing

04:15

and easing of the transition.

04:17

With the different parameters now applied,

04:20

we can see this fluid animation.

04:23

We have successfully evolved a static component

04:26

into an interactive one that uses animated shadows to produce

04:30

a convincing pressed effect.

04:34

Once you are comfortable with these core techniques,

04:37

you can combine them to realize popular design trends, including

04:41

realistic lighting, neomorphism, and neobrutalism.

04:46

Let's explore a few.

04:49

Beginning with emulating realistic lighting.

04:52

To achieve an effect like this, we

04:54

must consider how light behaves in the physical world.

04:58

You typically observe a crisp, direct shadow

05:02

cast by a primary light source, as well as a softer,

05:06

more diffuse ambient shadow.

05:08

We can replicate this by stacking multiple drop shadow

05:12

and inner shadow instances with varied properties.

05:16

First, we apply two chain drop shadow modifiers

05:20

with distinct properties followed by a background

05:24

modifier.

05:25

And to conclude, we apply chained inner shadow modifiers

05:30

to forge the metallic rim effect around the component's edge.

05:35

With these new modifiers, neomorphism

05:38

becomes entirely achievable.

05:40

This trend is characterized by a soft, extruded appearance

05:45

that seems to emerge organically from the background.

05:48

This technique hinges on an element

05:51

that shares the same color as its background and then applying

05:55

two faint opposing shadows--

05:58

a light one from one corner and a dark one from the opposite.

06:02

Conversely, the neobrutalist style

06:05

champions high contrast, blocky layouts,

06:09

standout color palettes, and thick, assertive borders.

06:13

To capture this effect, use a drop shadow

06:17

with zero blur and a hard distinct offset.

06:21

And you might be wondering about gradient shadows.

06:24

Yes, that's possible too.

06:26

Your shadows are not confined to solid colors.

06:30

The shadow API accepts a brush, which allows

06:33

you to create gradient shadows.

06:36

We have covered the basic mechanisms

06:38

of drop shadow and inner shadow, learned how to layer and animate

06:43

them.

06:44

When you combine these elements, you can create stunning effects

06:48

from a breathing, glowing aura to a fully

06:51

interactive and expressive user interface.

06:55

I encourage you to experiment with these modifiers

06:57

in your own projects.

06:59

You can find the complete source code for all of today's examples

07:03

at the link provided in the description.

07:05

Thanks for watching.

07:06

Happy composing!

07:07

[MUSIC PLAYING]

Key Vocabulary (50)

to A1 preposition

toward

"Go to school."

of A1 preposition

belonging

"Cup of tea."

and A1 conjunction

also

"You and me."

in A1 preposition

inside

"In the house."

that A1 determiner

specific

"That book."

it A1 pronoun

A third-person singular pronoun used to refer to an object, animal, or situation that has already been mentioned or is clear from context. It is also frequently used as a dummy subject to talk about time, weather, or distance.

for A1 preposition

Used to show who is intended to have or use something, or to explain the purpose or reason for an action. It is also frequently used to indicate a specific duration of time.

with A1 preposition

A preposition used to indicate that people or things are together, in the same place, or performing an action together. It can also describe the instrument used to perform an action or a characteristic that someone or something has.

as A1 conjunction

A conjunction used to compare two things that are equal in some way. It is most commonly used in the pattern 'as + adjective/adverb + as' to show similarity.

you A1 pronoun

Used to refer to the person or people that the speaker is addressing. It is the second-person pronoun used for both singular and plural subjects and objects.

this A1 pronoun

Used to identify a specific person, thing, or idea that is physically close to the speaker or has just been mentioned. It can also refer to the present time or a situation that is currently happening.

by A1 preposition

A preposition used to show the method or means of doing something, or to identify the person or thing that performs an action. It frequently appears in passive sentences to indicate the agent or before modes of transport.

from A1 preposition

Used to indicate the starting point, source, or origin of something. It can describe a physical location, a point in time, or the person who sent or gave an item.

we A1 pronoun

The word 'we' is a first-person plural pronoun used to refer to the speaker and one or more other people collectively. It is used as the subject of a sentence or clause.

an A1 article

An is an indefinite article used before singular countable nouns that begin with a vowel sound. It functions to indicate a non-specific person or thing, similar to the number one.

Sign up to unlock full features

Track progress, save vocabulary, and practice exercises

Description

Craft dynamic and expressive user interfaces with Shadows in Compose. Adhithya, a Staff Interaction Designer on Android, guides you through techniques to create everything from subtle highlights...

دسته‌بندی‌ها

Technology

English with Lucy