Skip to content

Commit fb0b44c

Browse files
committed
Align the Activity video flow with navigation
1 parent 3ca1b85 commit fb0b44c

1 file changed

Lines changed: 39 additions & 17 deletions

File tree

‎src/content/reference/react/Activity.md‎

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,13 @@ b {
339339

340340
</Sandpack>
341341

342-
Activity also preserves other browser-managed state, such as scroll position and media playback position. The following examples use the same video player to compare removing and hiding a `<video>` element. Play the video, hide it, show it again, and then select **Play**.
342+
Activity also preserves other browser-managed state, such as scroll position and media playback position. The following examples use the same video player to compare removing and hiding a `<video>` element. Play the video, switch to the Home tab, return to the Video tab, and then select **Play**.
343343

344344
<Recipes titleText="The difference between removing and hiding a video" titleId="examples-preserving-media-state">
345345

346346
#### Removing the video resets its playback position {/*removing-the-video-resets-its-playback-position*/}
347347

348-
This version conditionally renders the video player. Hiding it removes the `<video>` element from the DOM, so playback starts from the beginning when you show it again.
348+
This version conditionally renders the active tab. Switching to Home removes the `<video>` element from the DOM, so playback starts from the beginning when you return to Video.
349349

350350
<Sandpack>
351351

@@ -354,14 +354,24 @@ import { useState } from 'react';
354354
import VideoPlayer from './VideoPlayer.js';
355355

356356
export default function App() {
357-
const [isShowingVideo, setIsShowingVideo] = useState(true);
357+
const [activeTab, setActiveTab] = useState('video');
358358

359359
return (
360360
<>
361-
<button onClick={() => setIsShowingVideo(showing => !showing)}>
362-
{isShowingVideo ? 'Hide' : 'Show'} video
361+
<button
362+
aria-pressed={activeTab === 'home'}
363+
onClick={() => setActiveTab('home')}
364+
>
365+
Home
366+
</button>
367+
<button
368+
aria-pressed={activeTab === 'video'}
369+
onClick={() => setActiveTab('video')}
370+
>
371+
Video
363372
</button>
364-
{isShowingVideo && <VideoPlayer />}
373+
{activeTab === 'home' && <p>Welcome to my profile!</p>}
374+
{activeTab === 'video' && <VideoPlayer />}
365375
</>
366376
);
367377
}
@@ -394,12 +404,12 @@ export default function VideoPlayer() {
394404
```
395405

396406
```css
407+
button {
408+
margin-right: 10px;
409+
}
397410
.video-player {
398411
margin-top: 10px;
399412
}
400-
.video-player button {
401-
margin-right: 10px;
402-
}
403413
.video-player video {
404414
display: block;
405415
margin-top: 10px;
@@ -412,7 +422,7 @@ export default function VideoPlayer() {
412422

413423
#### Hiding the video preserves its playback position {/*hiding-the-video-preserves-its-playback-position*/}
414424

415-
This version renders the video player inside an Activity boundary. Hiding it preserves the `<video>` element, so playback continues from the same position when you show it and select **Play** again.
425+
This version renders both tabs inside Activity boundaries. Switching to Home hides the `<video>` element without removing it, so playback continues from the same position when you return to Video and select **Play** again.
416426

417427
<Sandpack>
418428

@@ -421,14 +431,26 @@ import { Activity, useState } from 'react';
421431
import VideoPlayer from './VideoPlayer.js';
422432

423433
export default function App() {
424-
const [isShowingVideo, setIsShowingVideo] = useState(true);
434+
const [activeTab, setActiveTab] = useState('video');
425435

426436
return (
427437
<>
428-
<button onClick={() => setIsShowingVideo(showing => !showing)}>
429-
{isShowingVideo ? 'Hide' : 'Show'} video
438+
<button
439+
aria-pressed={activeTab === 'home'}
440+
onClick={() => setActiveTab('home')}
441+
>
442+
Home
430443
</button>
431-
<Activity mode={isShowingVideo ? 'visible' : 'hidden'}>
444+
<button
445+
aria-pressed={activeTab === 'video'}
446+
onClick={() => setActiveTab('video')}
447+
>
448+
Video
449+
</button>
450+
<Activity mode={activeTab === 'home' ? 'visible' : 'hidden'}>
451+
<p>Welcome to my profile!</p>
452+
</Activity>
453+
<Activity mode={activeTab === 'video' ? 'visible' : 'hidden'}>
432454
<VideoPlayer />
433455
</Activity>
434456
</>
@@ -463,12 +485,12 @@ export default function VideoPlayer() {
463485
```
464486

465487
```css
488+
button {
489+
margin-right: 10px;
490+
}
466491
.video-player {
467492
margin-top: 10px;
468493
}
469-
.video-player button {
470-
margin-right: 10px;
471-
}
472494
.video-player video {
473495
display: block;
474496
margin-top: 10px;

0 commit comments

Comments
 (0)