-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworkshop-guide.html
More file actions
1138 lines (1013 loc) · 45.2 KB
/
Copy pathworkshop-guide.html
File metadata and controls
1138 lines (1013 loc) · 45.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bucket List App - Workshop Guide</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
line-height: 1.6;
color: #333;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 900px;
margin: 0 auto;
background: white;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
overflow: hidden;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 40px 30px;
text-align: center;
}
.header h1 {
font-size: 2.5em;
margin-bottom: 10px;
}
.header p {
font-size: 1.2em;
opacity: 0.9;
}
.progress-bar-container {
background: rgba(255, 255, 255, 0.2);
height: 8px;
border-radius: 4px;
margin-top: 20px;
overflow: hidden;
}
.progress-bar {
background: #4CAF50;
height: 100%;
width: 0%;
transition: width 0.3s ease;
}
.progress-text {
margin-top: 10px;
font-size: 0.9em;
opacity: 0.9;
}
.content {
padding: 30px;
}
.intro {
background: #f8f9fa;
padding: 20px;
border-radius: 8px;
margin-bottom: 30px;
border-left: 4px solid #667eea;
}
.intro h2 {
color: #667eea;
margin-bottom: 10px;
}
.time-info {
display: flex;
gap: 20px;
margin-top: 15px;
flex-wrap: wrap;
}
.time-badge {
background: white;
padding: 10px 15px;
border-radius: 6px;
font-size: 0.9em;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.time-badge strong {
color: #667eea;
}
.step {
margin-bottom: 20px;
border: 2px solid #e0e0e0;
border-radius: 12px;
overflow: hidden;
transition: all 0.3s ease;
}
.step.completed {
border-color: #4CAF50;
background: #f1f8f4;
}
.step-header {
background: #f8f9fa;
padding: 20px;
cursor: pointer;
display: flex;
align-items: center;
gap: 15px;
transition: background 0.3s ease;
}
.step-header:hover {
background: #e9ecef;
}
.step.completed .step-header {
background: #e8f5e9;
}
.step-checkbox {
width: 24px;
height: 24px;
cursor: pointer;
flex-shrink: 0;
}
.step-title {
flex: 1;
display: flex;
align-items: center;
gap: 10px;
}
.step-number {
background: #667eea;
color: white;
width: 32px;
height: 32px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
flex-shrink: 0;
}
.step.completed .step-number {
background: #4CAF50;
}
.step-name {
font-size: 1.2em;
font-weight: 600;
color: #333;
}
.step-toggle {
width: 24px;
height: 24px;
flex-shrink: 0;
transition: transform 0.3s ease;
}
.step.expanded .step-toggle {
transform: rotate(180deg);
}
.step-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.3s ease;
}
.step.expanded .step-content {
max-height: 5000px;
}
.step-body {
padding: 25px;
border-top: 1px solid #e0e0e0;
}
.step-goal {
background: #fff3cd;
border-left: 4px solid #ffc107;
padding: 15px;
margin-bottom: 20px;
border-radius: 4px;
}
.step-goal strong {
color: #856404;
}
.todo-list {
margin: 20px 0;
}
.todo-item {
padding: 10px;
margin: 8px 0;
background: #f8f9fa;
border-radius: 6px;
display: block;
line-height: 1.6;
padding-left: 30px;
position: relative;
}
.todo-item::before {
content: "→";
color: #667eea;
font-weight: bold;
position: absolute;
left: 10px;
top: 10px;
}
.challenge {
background: #e3f2fd;
border-left: 4px solid #2196F3;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
}
.challenge-title {
color: #1976D2;
font-weight: bold;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.key-learning {
background: #e8f5e9;
border-left: 4px solid #4CAF50;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
}
.key-learning-title {
color: #2e7d32;
font-weight: bold;
margin-bottom: 8px;
display: flex;
align-items: center;
gap: 8px;
}
.checkpoint {
background: #fff3e0;
border: 2px dashed #ff9800;
padding: 15px;
margin: 15px 0;
border-radius: 8px;
text-align: center;
}
.checkpoint strong {
color: #e65100;
}
.complete-step-button {
background: #4CAF50;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 1em;
font-weight: 600;
margin-top: 20px;
display: block;
width: 100%;
transition: background 0.3s ease;
}
.complete-step-button:hover {
background: #45a049;
}
.complete-step-button.completed {
background: #9e9e9e;
cursor: default;
}
.complete-step-button.completed:hover {
background: #9e9e9e;
}
code {
background: #f4f4f4;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
font-size: 0.9em;
color: #d63384;
display: inline;
white-space: nowrap;
}
pre {
background: #2d2d2d;
color: #f8f8f2;
padding: 15px;
border-radius: 6px;
overflow-x: auto;
margin: 15px 0;
position: relative;
}
pre code {
background: none;
color: inherit;
padding: 0;
white-space: pre;
display: block;
}
.reset-button {
background: #dc3545;
color: white;
border: none;
padding: 12px 24px;
border-radius: 6px;
cursor: pointer;
font-size: 1em;
margin-top: 20px;
display: block;
width: 100%;
transition: background 0.3s ease;
}
.reset-button:hover {
background: #c82333;
}
.footer {
background: #f8f9fa;
padding: 20px;
text-align: center;
color: #6c757d;
border-top: 1px solid #e0e0e0;
}
.platform-note {
background: #fff8e1;
border-left: 4px solid #ffa726;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
}
.platform-note strong {
color: #ef6c00;
}
/* Spoiler Styles */
.spoiler {
background: #ffe5e5;
border-left: 4px solid #f44336;
padding: 15px;
margin: 15px 0;
border-radius: 4px;
}
.spoiler-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 10px;
}
.spoiler-title {
color: #c62828;
font-weight: bold;
font-size: 1em;
}
.spoiler-toggle {
background: #f44336;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 0.85em;
transition: background 0.3s ease;
}
.spoiler-toggle:hover {
background: #d32f2f;
}
.spoiler-content {
display: none;
margin-top: 10px;
}
.spoiler-content.visible {
display: block;
}
.code-block {
position: relative;
}
.copy-button {
position: absolute;
top: 10px;
right: 10px;
background: #667eea;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 0.85em;
transition: background 0.3s ease;
}
.copy-button:hover {
background: #5568d3;
}
.copy-button.copied {
background: #4CAF50;
}
.file-label {
background: #667eea;
color: white;
padding: 4px 10px;
border-radius: 4px 4px 0 0;
font-size: 0.85em;
display: inline-block;
margin-bottom: -1px;
}
@media (max-width: 768px) {
.header h1 {
font-size: 2em;
}
.time-info {
flex-direction: column;
gap: 10px;
}
}
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🎯 Bucket List App Workshop</h1>
<p>React Native for React Web Developers</p>
<div class="progress-bar-container">
<div class="progress-bar" id="progressBar"></div>
</div>
<div class="progress-text" id="progressText">0 of 4 steps completed (0%)</div>
</div>
<div class="content">
<div class="intro">
<h2>🌐 For React Web Developers</h2>
<p><strong>Good news!</strong> You already know React. This workshop focuses only on what's <em>different</em> in React Native:</p>
<ul style="margin-left: 20px; margin-top: 10px;">
<li><strong>UI Primitives:</strong> <code><View></code> instead of <code><div></code>, <code><Text></code> instead of text nodes</li>
<li><strong>Styling:</strong> StyleSheet API instead of CSS (but similar concepts!)</li>
<li><strong>Platform APIs:</strong> Alert, AsyncStorage, and platform detection</li>
</ul>
<div class="time-info">
<div class="time-badge"><strong>📱 Platform:</strong> Expo Go or Web</div>
<div class="time-badge"><strong>🎯 Focus:</strong> React Native differences only</div>
</div>
</div>
<!-- Step 1 -->
<div class="step" data-step="1">
<div class="step-header">
<input type="checkbox" class="step-checkbox">
<div class="step-title">
<div class="step-number">1</div>
<div class="step-name">Setup & Pre-populated Data</div>
</div>
<svg class="step-toggle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</div>
<div class="step-content">
<div class="step-body">
<div class="step-goal">
<strong>🎯 Goal:</strong> Verify your setup works and see pre-populated data
</div>
<h3>What to do:</h3>
<div class="todo-list">
<div class="todo-item">Open <code>app/(tabs)/index.tsx</code></div>
<div class="todo-item">Find the <code>useState</code> with the commented pre-populated items (around line 44)</div>
<div class="todo-item">Uncomment the 3 items (Tokyo, Surf, Book) - just remove the <code>//</code></div>
<div class="todo-item">Save the file and check your app - you should see 3 items!</div>
<div class="todo-item">Try adding new items using the + button - it already works!</div>
</div>
<div class="key-learning">
<div class="key-learning-title">💡 Key Learning</div>
<ul style="margin-left: 20px;">
<li><code>useState</code> works EXACTLY the same as React web - no differences!</li>
<li>State management, props, and component logic are all the same</li>
<li>The app is already functional - all CRUD operations are pre-implemented</li>
<li>We'll focus on learning UI primitives, styling, and platform APIs</li>
</ul>
</div>
<div class="checkpoint">
<strong>✅ Check your work:</strong> You should see 3 pre-populated items. Try adding a new item!
</div>
<button class="complete-step-button" onclick="markStepComplete(1)">
✓ Mark Step 1 as Complete
</button>
</div>
</div>
</div>
<!-- Step 2 -->
<div class="step" data-step="2">
<div class="step-header">
<input type="checkbox" class="step-checkbox">
<div class="step-title">
<div class="step-number">2</div>
<div class="step-name">UI Primitives & Styling</div>
</div>
<svg class="step-toggle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</div>
<div class="step-content">
<div class="step-body">
<div class="step-goal">
<strong>🎯 Goal:</strong> Build a custom checkbox using React Native primitives and styling
</div>
<h3>What to do:</h3>
<div class="todo-list">
<div class="todo-item">Open <code>components/bucket-list-item.tsx</code></div>
<div class="todo-item">Find the comment <code>📚 STEP 2: Build your custom checkbox here!</code> (around line 59)</div>
<div class="todo-item"><strong>Try building it yourself first!</strong> Read the requirements below</div>
<div class="todo-item">If you get stuck, scroll down to see the solution with a copy button</div>
<div class="todo-item">Test it! Tap items to mark them complete - toggle should work!</div>
</div>
<div class="challenge">
<div class="challenge-title">🎯 Requirements</div>
<p><strong>Build a custom checkbox with these specs:</strong></p>
<ul style="margin-left: 20px; margin-top: 8px;">
<li><strong>Component:</strong> <code><Pressable></code> - React Native's touchable button</li>
<li><strong>onPress handler:</strong> Call <code>onToggleComplete(item.id)</code></li>
<li><strong>Size:</strong> 24x24 pixels</li>
<li><strong>Border radius:</strong> 12 (makes it a rounded square)</li>
<li><strong>Border:</strong> 2px width, gray color (#ccc)</li>
<li><strong>Centering:</strong> Use <code>alignItems: 'center'</code> and <code>justifyContent: 'center'</code></li>
<li><strong>When completed:</strong> Change background to <code>Colors.tint</code>, border to <code>Colors.tint</code></li>
<li><strong>Checkmark:</strong> Show <code><IconSymbol name="checkmark" size={18} color="white" /></code> when completed</li>
</ul>
<p style="margin-top: 12px;"><strong>Hints:</strong></p>
<ul style="margin-left: 20px;">
<li>Use conditional styling: <code>style={[baseStyle, condition && activeStyle]}</code></li>
<li>Use conditional rendering: <code>{condition && <Component />}</code></li>
<li>Numbers don't need units (16 not "16px")</li>
<li>Properties are camelCase (backgroundColor not background-color)</li>
</ul>
</div>
<div class="key-learning">
<div class="key-learning-title">💡 Key Learning</div>
<ul style="margin-left: 20px;">
<li><code><Pressable></code> = React Native's <code><button></code> or onClick handler</li>
<li>Use <code>onPress</code> instead of <code>onClick</code></li>
<li>StyleSheet uses camelCase properties (backgroundColor not background-color)</li>
<li>No CSS units - numbers are density-independent pixels</li>
<li>Conditional styling works the same as React web: <code>[style1, condition && style2]</code></li>
<li>Flexbox is default (every View has display: flex implicitly)</li>
</ul>
</div>
<!-- Spoiler Solution -->
<div class="spoiler">
<div class="spoiler-header">
<span class="spoiler-title">💡 Solution (Try it yourself first!)</span>
<button class="spoiler-toggle" onclick="toggleSpoiler(this)">Show Solution</button>
</div>
<div class="spoiler-content">
<p style="margin-bottom: 10px;"><strong>Where to add:</strong> In <code>components/bucket-list-item.tsx</code>, replace the comment <code>📚 STEP 2: Build your custom checkbox here!</code> with this code:</p>
<div class="code-block">
<span class="file-label">components/bucket-list-item.tsx</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code><Pressable
onPress={() => onToggleComplete(item.id)}
style={[
{
width: 24,
height: 24,
borderRadius: 12,
borderWidth: 2,
borderColor: '#ccc',
alignItems: 'center',
justifyContent: 'center',
},
item.completed && {
backgroundColor: Colors.tint,
borderColor: Colors.tint
},
]}
>
{item.completed && (
<IconSymbol name="checkmark" size={18} color="white" />
)}
</Pressable></code></pre>
</div>
</div>
</div>
<div class="platform-note">
<strong>🌐 Web vs Native:</strong> This checkbox works identically on both platforms! React Native handles the rendering differences for you.
</div>
<div class="checkpoint">
<strong>✅ Check your work:</strong> Tap the checkbox area on an item - it should toggle between checked/unchecked!
</div>
<button class="complete-step-button" onclick="markStepComplete(2)">
✓ Mark Step 2 as Complete
</button>
</div>
</div>
</div>
<!-- Step 3 -->
<div class="step" data-step="3">
<div class="step-header">
<input type="checkbox" class="step-checkbox">
<div class="step-title">
<div class="step-number">3</div>
<div class="step-name">Platform APIs: Alerts</div>
</div>
<svg class="step-toggle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</div>
<div class="step-content">
<div class="step-body">
<div class="step-goal">
<strong>🎯 Goal:</strong> Learn platform detection with Alert APIs
</div>
<h3>Implementing Platform-Aware Alerts</h3>
<div class="todo-list">
<div class="todo-item">Open <code>utils/platform-alert.ts</code></div>
<div class="todo-item"><strong>Challenge: Implement the showAlert function!</strong> Read the comments for hints</div>
<div class="todo-item">Use <code>Platform.OS</code> to detect 'web' vs native platforms</div>
<div class="todo-item">On web: use <code>window.confirm()</code>, on native: use <code>Alert.alert()</code></div>
<div class="todo-item">If stuck, check the solution below</div>
<div class="todo-item">Open <code>components/bucket-list-item.tsx</code></div>
<div class="todo-item">In the <code>handleDelete</code> function, add a confirmation alert</div>
<div class="todo-item">Import: <code>import { showAlert } from '@/utils/platform-alert';</code></div>
<div class="todo-item">Call showAlert before deleting (see solution below)</div>
</div>
<!-- Spoiler Solution Part 1 -->
<div class="spoiler">
<div class="spoiler-header">
<span class="spoiler-title">💡 Solution Part 1: showAlert Implementation</span>
<button class="spoiler-toggle" onclick="toggleSpoiler(this)">Show Solution</button>
</div>
<div class="spoiler-content">
<p style="margin-bottom: 10px;"><strong>Where to add:</strong> In <code>utils/platform-alert.ts</code>, replace the <code>showAlert</code> function body (lines 33-42) with:</p>
<div class="code-block">
<span class="file-label">utils/platform-alert.ts</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code>export function showAlert(
title: string,
message?: string,
buttons?: AlertButton[]
): void {
if (Platform.OS === 'web') {
// Web fallback using window.confirm
const confirmMessage = message ? `${title}\n\n${message}` : title;
const confirmed = window.confirm(confirmMessage);
if (buttons) {
// Find the appropriate button to call
if (confirmed) {
// Call the first non-cancel button's onPress
const actionButton = buttons.find(btn => btn.style !== 'cancel');
if (actionButton && actionButton.onPress) {
actionButton.onPress();
}
} else {
// Call the cancel button's onPress if it exists
const cancelButton = buttons.find(btn => btn.style === 'cancel');
if (cancelButton && cancelButton.onPress) {
cancelButton.onPress();
}
}
}
} else {
// Native platforms (iOS, Android) - use Alert.alert
Alert.alert(title, message, buttons);
}
}</code></pre>
</div>
</div>
</div>
<!-- Spoiler Solution Part 2 -->
<div class="spoiler">
<div class="spoiler-header">
<span class="spoiler-title">💡 Solution Part 2: Using showAlert in handleDelete</span>
<button class="spoiler-toggle" onclick="toggleSpoiler(this)">Show Solution</button>
</div>
<div class="spoiler-content">
<p style="margin-bottom: 10px;"><strong>Where to add:</strong> In <code>components/bucket-list-item.tsx</code>:</p>
<p style="margin-bottom: 10px;">1. Add import at the top:</p>
<div class="code-block">
<span class="file-label">components/bucket-list-item.tsx (top of file)</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code>import { showAlert } from '@/utils/platform-alert';</code></pre>
</div>
<p style="margin: 15px 0 10px 0;">2. Replace the <code>handleDelete</code> function (around line 41):</p>
<div class="code-block">
<span class="file-label">components/bucket-list-item.tsx (handleDelete)</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code>const handleDelete = () => {
showAlert(
'Delete Item',
'Are you sure you want to delete this item?',
[
{ text: 'Cancel', style: 'cancel' },
{
text: 'Delete',
style: 'destructive',
onPress: () => onDelete(item.id)
}
]
);
};</code></pre>
</div>
</div>
</div>
<div class="key-learning">
<div class="key-learning-title">💡 Key Learning - Platform Detection</div>
<ul style="margin-left: 20px;">
<li><code>Platform.OS</code> returns: 'ios', 'android', or 'web'</li>
<li>Some APIs don't work on all platforms (like Alert.alert)</li>
<li>Solution: Create wrapper utilities that detect platform and use appropriate API</li>
<li>On web: <code>window.confirm()</code></li>
<li>On native: <code>Alert.alert()</code></li>
<li>Your app code doesn't need to know - the utility handles it!</li>
</ul>
</div>
<div class="checkpoint">
<strong>✅ Check your work:</strong>
<ul style="margin-left: 20px; margin-top: 8px; text-align: left;">
<li>Tap trash icon → confirmation dialog appears</li>
<li>Works on both web (window.confirm) and native (Alert.alert)</li>
</ul>
</div>
<button class="complete-step-button" onclick="markStepComplete(3)">
✓ Mark Step 3 as Complete
</button>
</div>
</div>
</div>
<!-- Step 4 -->
<div class="step" data-step="4">
<div class="step-header">
<input type="checkbox" class="step-checkbox">
<div class="step-title">
<div class="step-number">4</div>
<div class="step-name">AsyncStorage for Persistence</div>
</div>
<svg class="step-toggle" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</div>
<div class="step-content">
<div class="step-body">
<div class="step-goal">
<strong>🎯 Goal:</strong> Save and load bucket list items using AsyncStorage
</div>
<div class="info-box">
<strong>📱 Good news!</strong> AsyncStorage works on both web AND native!
<br>On web, it uses localStorage under the hood. No platform detection needed!
</div>
<h3>What You'll Implement</h3>
<p style="margin-bottom: 15px;">
<strong>Good news!</strong> Almost everything is set up for you:
<br>✅ AsyncStorage import is added
<br>✅ Storage key constant is defined
<br>✅ <code>loadItems</code> and <code>saveItems</code> function structures are in place
<br>✅ <code>useEffect</code> is already calling loadItems on mount
<br>✅ All CRUD functions are already calling <code>saveItems()</code>
</p>
<p style="margin-bottom: 15px;">
<strong>Your task:</strong> Just implement the two empty function bodies!
</p>
<div class="todo-list">
<div class="todo-item">Open <code>app/(tabs)/index.tsx</code></div>
<div class="todo-item"><strong>Implement the <code>loadItems</code> function body</strong> (read from AsyncStorage, parse JSON, update state)</div>
<div class="todo-item"><strong>Implement the <code>saveItems</code> function body</strong> (stringify and save to AsyncStorage)</div>
<div class="todo-item">Test! Add items, reload the app - they should persist!</div>
</div>
<!-- Spoiler Solution -->
<div class="spoiler">
<div class="spoiler-header">
<span class="spoiler-title">💡 Solution: Complete AsyncStorage Implementation</span>
<button class="spoiler-toggle" onclick="toggleSpoiler(this)">Show Solution</button>
</div>
<div class="spoiler-content">
<p style="margin-bottom: 10px;"><strong>Complete implementation for <code>app/(tabs)/index.tsx</code>:</strong></p>
<p style="margin-bottom: 10px;">1. Fill in the <code>loadItems</code> function body (around line 54):</p>
<div class="code-block">
<span class="file-label">app/(tabs)/index.tsx - loadItems implementation</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code>try {
const stored = await AsyncStorage.getItem(STORAGE_KEY);
if (stored) {
setItems(JSON.parse(stored));
}
} catch (error) {
console.error('Error loading items:', error);
}</code></pre>
</div>
<p style="margin: 15px 0 10px 0;">2. Fill in the <code>saveItems</code> function body (around line 60):</p>
<div class="code-block">
<span class="file-label">app/(tabs)/index.tsx - saveItems implementation</span>
<button class="copy-button" onclick="copyCode(this)">Copy</button>
<pre><code>try {
await AsyncStorage.setItem(STORAGE_KEY, JSON.stringify(newItems));
} catch (error) {
console.error('Error saving items:', error);
}</code></pre>
</div>
<p style="margin: 15px 0 10px 0;"><strong>That's it!</strong> The CRUD functions are already calling <code>saveItems()</code>, so your data will persist automatically. 🎉</p>
</div>
</div>
<div class="key-learning">
<div class="key-learning-title">💡 Key Learning - AsyncStorage</div>
<ul style="margin-left: 20px;">
<li><strong>Great news:</strong> AsyncStorage works on both web AND native!</li>
<li>On web: Uses <code>localStorage</code> under the hood</li>
<li>On native: Uses native storage APIs</li>
<li>Always asynchronous - must use <code>await</code></li>
<li>Stores strings only - use <code>JSON.stringify()</code> and <code>JSON.parse()</code></li>
<li><code>useEffect</code> for loading works the same as fetching data in React web!</li>
<li>No custom hook needed - just async functions in your component!</li>
</ul>
</div>
<div class="platform-note">
<strong>🌐 Testing on different platforms:</strong>
<ul style="margin-left: 20px; margin-top: 8px;">
<li><strong>Web:</strong> Run <code>npm run web</code> - AsyncStorage uses localStorage</li>
<li><strong>Expo Go:</strong> Scan QR code - AsyncStorage uses native APIs</li>
<li>Same code works everywhere! 🎉</li>
</ul>
</div>
<div class="checkpoint">
<strong>✅ Check your work:</strong>
<ul style="margin-left: 20px; margin-top: 8px; text-align: left;">
<li>Add a few bucket list items</li>
<li>Reload the app (refresh web or close/reopen Expo Go)</li>
<li>Items should still be there!</li>
<li>Delete an item → reload → it stays deleted</li>
<li>Mark item complete → reload → it stays completed</li>
</ul>
</div>
<button class="complete-step-button" onclick="markStepComplete(4)">
✓ Mark Step 4 as Complete
</button>
</div>
</div>
</div>
<button class="reset-button" onclick="resetProgress()">🔄 Reset Progress</button>
</div>
<div class="footer">
<p>🎓 React Native Workshop - Built with ❤️ for React Web Developers</p>
<p style="margin-top: 8px; font-size: 0.9em;">Focuses on React Native differences: UI Primitives, Styling, and Platform APIs</p>
</div>
</div>
<script>
// Toggle spoiler visibility
function toggleSpoiler(button) {
const spoiler = button.closest('.spoiler');
const content = spoiler.querySelector('.spoiler-content');
const isVisible = content.classList.contains('visible');
if (isVisible) {
content.classList.remove('visible');
button.textContent = 'Show Solution';
} else {
content.classList.add('visible');
button.textContent = 'Hide Solution';
}
}
// Copy code to clipboard
function copyCode(button) {
const codeBlock = button.nextElementSibling;
const code = codeBlock.querySelector('code').textContent;
navigator.clipboard.writeText(code).then(() => {
const originalText = button.textContent;
button.textContent = 'Copied!';
button.classList.add('copied');
setTimeout(() => {
button.textContent = originalText;
button.classList.remove('copied');
}, 2000);
}).catch(err => {
console.error('Failed to copy:', err);
alert('Failed to copy code. Please copy manually.');
});
}
// Load saved progress from localStorage
function loadProgress() {
const saved = localStorage.getItem('workshopProgress');
if (saved) {
const progress = JSON.parse(saved);
progress.forEach((completed, index) => {
const step = document.querySelector(`.step[data-step="${index + 1}"]`);
if (step && completed) {
const checkbox = step.querySelector('.step-checkbox');
checkbox.checked = true;
step.classList.add('completed');
}
});
updateProgress();
}
}
// Save progress to localStorage
function saveProgress() {
const checkboxes = document.querySelectorAll('.step-checkbox');
const progress = Array.from(checkboxes).map(cb => cb.checked);
localStorage.setItem('workshopProgress', JSON.stringify(progress));
}
// Update progress bar
function updateProgress() {
const checkboxes = document.querySelectorAll('.step-checkbox');
const total = checkboxes.length;
const completed = Array.from(checkboxes).filter(cb => cb.checked).length;
const percentage = Math.round((completed / total) * 100);
document.getElementById('progressBar').style.width = percentage + '%';
document.getElementById('progressText').textContent =
`${completed} of ${total} steps completed (${percentage}%)`;
}
// Close all steps except the one being opened