Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,590 --> 00:00:07,820
Now before we move on in the next video to customizing and styling this app bar using material you eyes
2
00:00:07,880 --> 00:00:09,200
styling system.
3
00:00:09,290 --> 00:00:16,750
I wanted to go ahead and add a kind of cool feature to this that it actually shows on their documentation.
4
00:00:16,820 --> 00:00:26,880
So if you go down through their examples you'll find here where it says scrolling and they have two
5
00:00:26,880 --> 00:00:28,130
examples here.
6
00:00:28,200 --> 00:00:32,540
The scroll to hide app bar which you can see right there.
7
00:00:32,540 --> 00:00:40,070
So as I start scrolling down that disappears and underneath it the Elevate app bar.
8
00:00:40,110 --> 00:00:42,500
So you see how this is flat.
9
00:00:42,510 --> 00:00:47,080
And it looks as if it's integrated with the same page as the text.
10
00:00:47,160 --> 00:00:56,130
But once you start scrolling you can see that very suddenly here where it comes up and goes back down
11
00:00:56,940 --> 00:00:58,800
I actually really like this effect.
12
00:00:58,860 --> 00:01:06,600
So let's go over and look at the source code and see if we can't get it to work for ourselves.
13
00:01:06,650 --> 00:01:10,290
The first thing we need to do here is copy this function.
14
00:01:10,310 --> 00:01:12,170
This elevation scroll.
15
00:01:12,410 --> 00:01:18,440
We're going to copy that and we're going to flip back over to the code editor and place this in front
16
00:01:18,500 --> 00:01:20,650
of our header function.
17
00:01:20,660 --> 00:01:28,150
We're going to paste that in and then we can go ahead and get rid of the prop types part and now you
18
00:01:28,150 --> 00:01:31,430
can see that we're missing the use scroll trigger.
19
00:01:31,570 --> 00:01:38,450
So let's go back over here and you can see that they just import that from material UI.
20
00:01:38,830 --> 00:01:47,000
So we're going to copy that and import that as well and now all we have to do is come down here and
21
00:01:47,000 --> 00:01:48,130
actually use it.
22
00:01:48,130 --> 00:01:56,420
So the elevation scroll cause that and then come underneath here and put our closing tag and if we go
23
00:01:56,420 --> 00:02:00,250
ahead and hit save we can come back over here.
24
00:02:00,260 --> 00:02:04,460
And if you go over into the app you won't see any changes yet.
25
00:02:04,490 --> 00:02:13,770
So let's go back to the material UI example and keep scrolling down to here where it has this array
26
00:02:14,010 --> 00:02:15,080
that it creates.
27
00:02:15,120 --> 00:02:21,750
And we're going to go ahead and copy this and then go back to the code and use this just so that we
28
00:02:21,750 --> 00:02:27,630
have some extra text on the screen and you can see the scrolling effect take place.
29
00:02:27,630 --> 00:02:35,220
And so if we come to the app dot J.S. file and underneath here instead of our hello let's go ahead and
30
00:02:35,220 --> 00:02:42,900
paste in what we had copied from the documentation and changed this 12 up here to one hundred and twenty.
31
00:02:42,900 --> 00:02:48,420
So this is going to create one hundred and twenty copies of this on our screen which should be plenty
32
00:02:48,420 --> 00:02:55,040
to show these scrolling effect so let's save that and flip it back over to the browser.
33
00:02:55,230 --> 00:03:01,920
And now you can see obviously the screen is full of text and if you look up here our app bar you see
34
00:03:01,920 --> 00:03:02,560
it's flat.
35
00:03:02,580 --> 00:03:05,840
But when we start to scroll you can see it start floating.
36
00:03:05,840 --> 00:03:11,940
And this actually is just enough to make it a Scroll on my screen but you can still see where it goes
37
00:03:12,000 --> 00:03:18,450
from flat to floating flat to floating.
38
00:03:18,450 --> 00:03:23,730
It is really subtle so if you just look up here at this top line you can see the top of like that see
39
00:03:23,730 --> 00:03:32,030
right there floating flat floating flat pretty cool.
40
00:03:32,050 --> 00:03:36,690
And it was honestly not very hard to set up so let's look for a second.
41
00:03:36,700 --> 00:03:38,950
Some of the options that made this work
42
00:03:41,770 --> 00:03:51,790
here in the header file if you take a look at the function that we imported from the material UI documentation
43
00:03:52,270 --> 00:03:57,180
the first variable that you see is the trigger or constant actually.
44
00:03:57,370 --> 00:04:06,940
And this uses the use scroll trigger hook from material UI which essentially is an event listener for
45
00:04:06,940 --> 00:04:08,370
when the user is scrolling.
46
00:04:09,380 --> 00:04:17,150
The first option that set here is the disable hysteresis and I don't know if I'm pronouncing that correctly
47
00:04:17,420 --> 00:04:24,730
but what that means is whether or not there's a little delay when the user is scrolling.
48
00:04:24,770 --> 00:04:31,010
So sometimes when you want the app bar to go away the hide on scroll.
49
00:04:31,010 --> 00:04:36,530
You actually sometimes will have a little bit of a delay in there but for this we don't want that.
50
00:04:36,560 --> 00:04:44,470
So we disable that and then right below there you see the threshold and we have that is set to zero
51
00:04:44,890 --> 00:04:54,590
although it defaults to 100 that number controls how far the user has to start scrolling before it triggers
52
00:04:54,650 --> 00:04:57,610
this event listener and so with a zero.
53
00:04:57,620 --> 00:05:04,060
As soon as the user starts scrolling it will trigger it whereas if you put in say the default on 100
54
00:05:04,280 --> 00:05:10,060
you would take the user scrolling farther down before the event listener actually triggers.
55
00:05:10,210 --> 00:05:15,800
Now we actually don't need under here where it says and sets the target.
56
00:05:15,820 --> 00:05:21,610
This is actually up here what it's talking about is it's only being said here because the demo for the
57
00:05:21,640 --> 00:05:28,330
documentation was in an AI frame so it will default to window so we can go ahead and just get rid of
58
00:05:28,330 --> 00:05:29,260
that.
59
00:05:29,320 --> 00:05:33,490
That means you can go up here and delete the window from there as well.
60
00:05:33,490 --> 00:05:40,000
And if you want to you can go ahead and get rid of that comment put a little space back in there and
61
00:05:40,000 --> 00:05:43,630
then the last part that you'll see is where it returns at the end.
62
00:05:43,630 --> 00:05:53,020
Here a new version of whatever component you are wrapping with elevation scroll it clones the children
63
00:05:53,380 --> 00:06:00,940
and returns a new copy of that element with a new elevation depending on whether or not the trigger
64
00:06:00,970 --> 00:06:02,710
has been set.
65
00:06:02,710 --> 00:06:09,780
So if our event listener has set this trigger then it will have an elevation of 4.
66
00:06:09,790 --> 00:06:12,310
So that is our floating state.
67
00:06:12,310 --> 00:06:14,740
Otherwise it will remain flat.
68
00:06:14,770 --> 00:06:17,630
And that is with an elevation of zero.
69
00:06:17,740 --> 00:06:24,100
So then all we had to do was take that function and wrap our components with it and we got that really
70
00:06:24,100 --> 00:06:26,410
nice easy functionality.
71
00:06:26,440 --> 00:06:31,090
So I really am glad that the documentation had that and made it so easy for us.
72
00:06:32,160 --> 00:06:40,470
Let's go ahead and get rid of all of that extra text and replace it with our hello again so we can give
73
00:06:40,470 --> 00:06:46,340
that a save go and check and you see the halo is covered up by that app bar again.
74
00:06:46,340 --> 00:06:52,920
So let's go ahead and start taking a look at how we can solve that and all the rest of the features
75
00:06:52,920 --> 00:06:58,760
that we have available to us with the material UI theming system in the next video.
8328
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.