-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathexample-image-icons.ts
More file actions
473 lines (450 loc) · 12.8 KB
/
Copy pathexample-image-icons.ts
File metadata and controls
473 lines (450 loc) · 12.8 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
/**
* Example usage of TabsBar with comprehensive imageIcon support
* This file demonstrates the new imageIcon functionality with various formats and configurations
*/
import { TabsBar } from './src/index';
// Example 1: Base64 encoded images with different shapes and sizes
async function configureWithBase64Images() {
// Sample base64 images (1x1 pixel PNGs for demonstration)
const redPixel = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==';
const bluePixel = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChAFfeTFYuAAAAABJRU5ErkJggg==';
const greenPixel = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==';
await TabsBar.configure({
items: [
{
id: 'home',
title: 'Home',
systemIcon: 'house',
imageIcon: {
shape: 'circle',
size: 'fit',
image: redPixel,
ring: {
enabled: true,
width: 2.0
}
}
},
{
id: 'search',
title: 'Search',
systemIcon: 'magnifyingglass',
imageIcon: {
shape: 'square',
size: 'fit',
image: bluePixel,
ring: {
enabled: true,
width: 3.0
}
}
},
{
id: 'profile',
title: 'Profile',
systemIcon: 'person',
// imageIcon is optional, so we can omit it entirely if no custom image is needed
// ring is optional, so we can omit it entirely if no ring is desired
}
],
initialId: 'home',
visible: true,
selectedIconColor: '#FF5733',
unselectedIconColor: '#8E8E93'
});
}
// Example 2: Remote URL images with error handling
async function configureWithRemoteImages() {
await TabsBar.configure({
items: [
{
id: 'dashboard',
title: 'Dashboard',
systemIcon: 'chart.bar',
imageIcon: {
shape: 'square',
size: 'cover',
image: 'https://via.placeholder.com/30x30/FF5733/FFFFFF?text=D'
}
},
{
id: 'notifications',
title: 'Alerts',
systemIcon: 'bell',
imageIcon: {
shape: 'circle',
size: 'fit',
image: 'https://via.placeholder.com/30x30/007AFF/FFFFFF?text=N'
},
badge: 3
},
{
id: 'settings',
title: 'Settings',
systemIcon: 'gear',
// imageIcon is optional
}
],
initialId: 'dashboard',
visible: true,
selectedIconColor: 'rgba(0, 122, 255, 1.0)',
unselectedIconColor: 'rgba(142, 142, 147, 0.6)'
});
}
// Example 3: Mixed icon types (imageIcon, systemIcon, and image)
async function configureWithMixedIconTypes() {
await TabsBar.configure({
items: [
{
id: 'tab1',
title: 'Image Icon',
systemIcon: 'star',
imageIcon: {
shape: 'circle',
size: 'cover',
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
}
},
{
id: 'tab2',
title: 'System Icon',
systemIcon: 'heart'
},
{
id: 'tab3',
title: 'Asset Image',
image: 'custom-icon',
systemIcon: 'square'
}
],
initialId: 'tab1',
visible: true
});
}
// Example 4: Different image formats and sizes
async function configureWithVariousFormats() {
await TabsBar.configure({
items: [
{
id: 'png',
title: 'PNG',
systemIcon: 'photo',
imageIcon: {
shape: 'square',
size: 'fit',
image: 'https://via.placeholder.com/50x50.png/FF5733/FFFFFF?text=PNG'
}
},
{
id: 'jpg',
title: 'JPEG',
systemIcon: 'camera',
imageIcon: {
shape: 'circle',
size: 'cover',
image: 'https://via.placeholder.com/40x40.jpg/007AFF/FFFFFF?text=JPG'
}
},
{
id: 'webp',
title: 'WebP',
systemIcon: 'globe',
imageIcon: {
shape: 'square',
size: 'stretch',
image: 'https://via.placeholder.com/60x30.webp/34C759/FFFFFF?text=WEBP'
}
}
],
initialId: 'png',
visible: true,
selectedIconColor: '#FF3B30',
unselectedIconColor: '#C7C7CC'
});
}
// Example 5: Error handling and fallback scenarios
async function configureWithErrorHandling() {
await TabsBar.configure({
items: [
{
id: 'valid',
title: 'Valid',
systemIcon: 'checkmark.circle',
imageIcon: {
shape: 'circle',
size: 'fit',
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg=='
}
},
{
id: 'invalid-url',
title: 'Invalid URL',
systemIcon: 'xmark.circle',
imageIcon: {
shape: 'square',
size: 'cover',
image: 'https://invalid-domain-that-does-not-exist.com/image.png'
}
},
{
id: 'invalid-base64',
title: 'Invalid Base64',
systemIcon: 'exclamationmark.triangle',
imageIcon: {
shape: 'circle',
size: 'fit',
image: 'data:image/png;base64,invalid-base64-data'
}
},
{
id: 'unsupported-format',
title: 'Unsupported',
systemIcon: 'questionmark.circle',
imageIcon: {
shape: 'square',
size: 'cover',
image: 'https://example.com/image.bmp'
}
}
],
initialId: 'valid',
visible: true
});
}
// Example 6: Dynamic image loading with loading states
async function demonstrateLoadingStates() {
// Configure with remote images
await TabsBar.configure({
items: [
{
id: 'slow-load',
title: 'Slow Load',
systemIcon: 'clock',
imageIcon: {
shape: 'circle',
size: 'cover',
image: 'https://httpbin.org/delay/2' // Simulates slow loading
}
},
{
id: 'fast-load',
title: 'Fast Load',
systemIcon: 'bolt',
imageIcon: {
shape: 'square',
size: 'fit',
image: 'https://via.placeholder.com/30x30/FF5733/FFFFFF?text=F'
}
}
],
initialId: 'slow-load',
visible: true
});
// Note: In a real app, you could check loading states like this:
// const webPlugin = TabsBar as any; // Cast to access web-specific methods
// if (webPlugin.getImageLoadingState) {
// console.log('Slow load state:', webPlugin.getImageLoadingState('slow-load'));
// console.log('Fast load state:', webPlugin.getImageLoadingState('fast-load'));
// }
}
// Example 7: High-DPI/Retina display support
async function configureForHighDPI() {
await TabsBar.configure({
items: [
{
id: 'retina',
title: 'Retina',
systemIcon: 'eye',
imageIcon: {
shape: 'circle',
size: 'cover',
// Use 2x size image for retina displays
image: 'https://via.placeholder.com/60x60/FF5733/FFFFFF?text=2X'
}
},
{
id: 'standard',
title: 'Standard',
systemIcon: 'display',
imageIcon: {
shape: 'square',
size: 'fit',
image: 'https://via.placeholder.com/30x30/007AFF/FFFFFF?text=1X'
}
}
],
initialId: 'retina',
visible: true
});
}
// Example 8: Security considerations and CORS handling
async function demonstrateSecurityFeatures() {
await TabsBar.configure({
items: [
{
id: 'cors-enabled',
title: 'CORS OK',
systemIcon: 'shield.checkered',
imageIcon: {
shape: 'circle',
size: 'cover',
// This URL supports CORS
image: 'https://via.placeholder.com/30x30/34C759/FFFFFF?text=OK'
}
},
{
id: 'cors-blocked',
title: 'CORS Blocked',
systemIcon: 'shield.slash',
imageIcon: {
shape: 'square',
size: 'fit',
// This might be blocked by CORS (example)
image: 'https://some-domain-without-cors.com/image.png'
}
},
{
id: 'https-only',
title: 'HTTPS Only',
systemIcon: 'lock',
imageIcon: {
shape: 'circle',
size: 'cover',
// Only HTTPS URLs are allowed for security
image: 'https://via.placeholder.com/30x30/FF9500/FFFFFF?text=SSL'
}
}
],
initialId: 'cors-enabled',
visible: true
});
}
// Example 9: Enhanced ring configuration with selected/unselected states
async function configureWithRings() {
await TabsBar.configure({
items: [
{
id: 'ring-enabled',
title: 'With Ring',
systemIcon: 'circle',
imageIcon: {
shape: 'circle',
size: 'fit',
image: 'https://via.placeholder.com/30x30/FF5733/FFFFFF?text=R',
ring: {
enabled: true,
width: 2.5
}
}
},
{
id: 'thick-ring',
title: 'Thick Ring',
systemIcon: 'square',
imageIcon: {
shape: 'square',
size: 'fit',
image: 'https://via.placeholder.com/30x30/007AFF/FFFFFF?text=T',
ring: {
enabled: true,
width: 4.0
}
}
},
{
id: 'thin-ring',
title: 'Thin Ring',
systemIcon: 'star',
imageIcon: {
shape: 'circle',
size: 'fit',
image: 'https://via.placeholder.com/30x30/34C759/FFFFFF?text=S',
ring: {
enabled: true,
width: 1.0
}
}
},
{
id: 'no-ring',
title: 'No Ring',
systemIcon: 'triangle',
// imageIcon is optional, and ring is optional within imageIcon
// so we can omit the ring property entirely if no ring is desired
imageIcon: {
shape: 'square',
size: 'fit',
image: 'https://via.placeholder.com/30x30/FF9500/FFFFFF?text=N',
}
}
],
initialId: 'ring-enabled',
visible: true,
selectedIconColor: '#FF3B30', // Red ring for selected tabs
unselectedIconColor: '#8E8E93' // Gray ring for unselected tabs
});
}
// Export all examples for testing
export {
configureWithBase64Images,
configureWithRemoteImages,
configureWithMixedIconTypes,
configureWithVariousFormats,
configureWithErrorHandling,
demonstrateLoadingStates,
configureForHighDPI,
demonstrateSecurityFeatures,
configureWithRings
};
// Usage instructions and feature summary
console.log(`
TabsBar ImageIcon Feature Examples:
🎨 SHAPE OPTIONS:
- "circle": Circular icon container
- "square": Square icon container (default)
📏 SIZE OPTIONS:
- "cover": Aspect fill - crops to fill container
- "stretch": Stretches image to fill container exactly
- "fit": Aspect fit - scales to fit within container (recommended for better padding)
🖼️ IMAGE SOURCES:
- Base64 Data URIs: "data:image/png;base64,..."
- Remote URLs: "https://example.com/image.png"
- Supported formats: PNG, JPEG, SVG, WebP
💍 ENHANCED RING OPTIONS:
- enabled: true/false - Show rings around both selected and unselected images
- width: number - Ring thickness in pixels (default: 2.0)
- Selected ring color matches selectedIconColor
- Unselected ring color matches unselectedIconColor
- Transparent spacer ring between image and colored ring (same width as ring)
- Additional 2px padding beneath the ring for better visual spacing
🔒 SECURITY FEATURES:
- HTTPS-only for remote URLs
- CORS handling for cross-origin requests
- Content-type validation
- File size limits (5MB max)
- Format validation
⚡ PERFORMANCE FEATURES:
- Image caching for remote URLs
- Loading state management
- Automatic fallback to systemIcon
- Retina/high-DPI support
- Smaller icon size (24x24) with padding for better appearance
🛡️ ERROR HANDLING:
- Graceful fallback to systemIcon
- Invalid URL handling
- Network error recovery
- Unsupported format detection
EXAMPLES:
1. configureWithBase64Images() - Base64 encoded images with rings
2. configureWithRemoteImages() - Remote URL images
3. configureWithMixedIconTypes() - Mixed icon types
4. configureWithVariousFormats() - Different image formats
5. configureWithErrorHandling() - Error scenarios
6. demonstrateLoadingStates() - Loading state management
7. configureForHighDPI() - Retina display support
8. demonstrateSecurityFeatures() - Security considerations
9. configureWithRings() - Ring configuration examples
All configurations include proper validation, caching, and fallback handling.
Images load asynchronously with smooth transitions between states.
Images now render properly without color tinting and include optional rings for selection.
`);