Skip to content

Commit 24a81f3

Browse files
authored
Infra/assets internal new structure (#3635)
* Add internal assets module with icons and images * Refactor icon imports to use internal assets for consistency * Refactor asset imports to use internal structure and remove assets.icons/images * Add xSmall icon and update ChipsInput to use internal assets * Add transparentSwatch icon and update ColorSwatch component to use it * Add dropdown to icons and update useFieldType to utilize internal assets * Add hintTip icons and update Hint component to use internal assets * Add checkMarkSmall and exclamationSmall icons, update WizardStates to use internal assets * Add gradient overlay images and update Overlay component to use internal assets * Add gradientOverlay image and update ScrollBar component to use it * move hint, swatch assets to internal.images * Rename icons.dropdown to icons.chevronDown * Add icons.demo and update references in components screens * rename checkSmall icon file and update icons - index.js reference * Update ColorSwatch to use internal.images for transparentSwatch * Refactor icon and image exports to include URI and dimensions * Refactor image handling to extract image source and apply dimensions in Icon and Image components * Update snapshots to reflect changes in image in Avatar, TextField, Button, and Hint components * remove unnecessary default export in check icon * Add script to extract image dimensions and update package.json * Revert new structure, split into index.web filesÏ * Icon remove DEFAULT_WEB_ICON_SIZE * Stepper local assets remove, move to Assets * Add new icon variants: minusOutline, minusOutlineSmall, plusOutline, plusOutlineSmall * Update asset imports to use .default for images and icons * Remove esModule option from url-loader configuration in webpack * Remove docuilib configurations from ReactLiveScope * Bump version to 3.14.0 in package.json * Refactor icon asset loading to use the new web assets structure * Rename update-web-assets script to updateWebAssets in package.json * changed extract-dimensions script to use console.error * Update file filtering in createIndexFile to exclude sized assets * rename extract-dimensions script
1 parent 6c7f5b3 commit 24a81f3

File tree

9 files changed

+188
-34
lines changed

9 files changed

+188
-34
lines changed

docuilib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uilib-docs",
3-
"version": "3.13.0",
3+
"version": "3.14.0",
44
"main": "./src/index.ts",
55
"scripts": {
66
"docusaurus": "docusaurus",

docuilib/src/theme/ReactLiveScope/configurations.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

docuilib/src/theme/ReactLiveScope/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import products from '../../assets/data/products';
3-
require('./configurations');
43
import {Colors} from 'react-native-ui-lib/style';
54
import {BorderRadiuses, Button, Image, Spacings, Text, TouchableOpacity, View} from 'react-native-ui-lib/core';
65
import ActionBar from 'react-native-ui-lib/actionBar';
@@ -34,16 +33,18 @@ import * as Playground from './Playground';
3433
Assets.loadAssetsGroup('icons.demo', {
3534
// chevronDown: require('../../assets/icons/chevronDown.png').default,
3635
chevronRight: {
37-
source: require('../../assets/icons/chevronRight.png').default,
38-
style: {width: 24, height: 24}
36+
uri: require('../../assets/icons/chevronRight.png').default,
37+
width: 24,
38+
height: 24
3939
},
4040
// add: require('../../assets/icons/add.png').default,
4141
// camera: require('../../assets/icons/cameraSelected.png').default,
4242
// close: require('../../assets/icons/close.png').default,
4343
// dashboard: require('../../assets/icons/dashboard.png').default,
4444
drag: {
45-
source: require('../../assets/icons/drag.png').default,
46-
style: {width: 10, height: 16}
45+
uri: require('../../assets/icons/drag.png').default,
46+
width: 10,
47+
height: 16
4748
}
4849
// image: require('../../assets/icons/image.png').default,
4950
// plus: require('../../assets/icons/plus.png').default,

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"releaseDemo": "./scripts/release/releaseDemo.sh",
4040
"releaseDocs": "./scripts/release/releaseDocs.sh",
4141
"releaseEslint": "./scripts/release/releaseEslint.sh",
42-
"releaseNative": "./scripts/release/releaseNative.sh"
42+
"releaseNative": "./scripts/release/releaseNative.sh",
43+
"updateWebAssets": "node scripts/assets/extractDimensions.js"
4344
},
4445
"dependencies": {
4546
"babel-plugin-transform-inline-environment-variables": "^0.0.2",

scripts/assets/extractDimensions.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const mime = require('mime-types');
4+
const {imageSize: sizeOf} = require('image-size');
5+
6+
// Base paths
7+
const ICONS_PATH = path.resolve(__dirname, '../../src/assets/internal/icons');
8+
const IMAGES_PATH = path.resolve(__dirname, '../../src/assets/internal/images');
9+
10+
// Function to check if file is an image
11+
function isImageFile(filePath) {
12+
const mimeType = mime.lookup(filePath);
13+
return !!mimeType && mimeType.includes('image');
14+
}
15+
16+
// Function to get dimensions of an image
17+
function getDimensions(imagePath) {
18+
try {
19+
if (!isImageFile(imagePath)) {
20+
console.warn(`File is not an image: ${imagePath}`);
21+
return {width: 0, height: 0};
22+
}
23+
24+
try {
25+
const buffer = fs.readFileSync(imagePath);
26+
const dimensions = sizeOf(buffer);
27+
return {
28+
width: dimensions.width,
29+
height: dimensions.height
30+
};
31+
} catch (sizeError) {
32+
// eslint-disable-next-line no-restricted-syntax
33+
console.error(`Error getting dimensions for ${imagePath}:`, sizeError);
34+
// Default dimensions if sizeOf fails
35+
return {width: 24, height: 24};
36+
}
37+
} catch (error) {
38+
// eslint-disable-next-line no-restricted-syntax
39+
console.error(`Error getting dimensions for ${imagePath}:`, error);
40+
return {width: 0, height: 0};
41+
}
42+
}
43+
44+
// Function to create index files with dimensions
45+
function createIndexFile(sourcePath, targetPath, fileType) {
46+
const files = fs.readdirSync(sourcePath).filter(file => !file.includes('@'));
47+
48+
let content = '';
49+
50+
if (fileType === 'icons') {
51+
content = 'export const icons = {\n';
52+
} else if (fileType === 'images') {
53+
content = 'export const images = {\n';
54+
}
55+
56+
files.forEach((file, index) => {
57+
const filePath = path.join(sourcePath, file);
58+
const mimeType = mime.lookup(filePath);
59+
const isImage = !!mimeType && mimeType.includes('image');
60+
61+
if (!isImage) {
62+
console.warn(`Skipping non-image file: ${filePath}`);
63+
return;
64+
}
65+
66+
const name = path.basename(file, path.extname(file));
67+
const dimensions = getDimensions(filePath);
68+
69+
// Handle hyphenated filenames by converting to camelCase
70+
const propertyName = name.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
71+
72+
content += ` get ${propertyName}() {\n`;
73+
// eslint-disable-next-line max-len
74+
content += ` return {uri: require('./${file}').default, width: ${dimensions.width}, height: ${dimensions.height}};\n`;
75+
content += index === files.length - 1 ? ` }\n` : ` },\n`; // Conditional check for the last file
76+
});
77+
78+
content += '};\n';
79+
80+
fs.writeFileSync(targetPath, content);
81+
console.log(`Created ${targetPath}`);
82+
}
83+
84+
// Create index files
85+
createIndexFile(ICONS_PATH, path.join(ICONS_PATH, 'index.web.js'), 'icons');
86+
createIndexFile(IMAGES_PATH, path.join(IMAGES_PATH, 'index.web.js'), 'images');
87+
88+
console.log('Index files created successfully!');
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
export const icons = {
2+
get check() {
3+
return {uri: require('./check.png').default, width: 21, height: 15};
4+
},
5+
get checkMarkSmall() {
6+
return {uri: require('./checkMarkSmall.png').default, width: 16, height: 16};
7+
},
8+
get checkSmall() {
9+
return {uri: require('./checkSmall.png').default, width: 24, height: 24};
10+
},
11+
get chevronDown() {
12+
return {uri: require('./chevronDown.png').default, width: 16, height: 16};
13+
},
14+
get exclamationSmall() {
15+
return {uri: require('./exclamationSmall.png').default, width: 16, height: 16};
16+
},
17+
get minusOutline() {
18+
return {uri: require('./minusOutline.png').default, width: 32, height: 32};
19+
},
20+
get minusOutlineSmall() {
21+
return {uri: require('./minusOutlineSmall.png').default, width: 24, height: 24};
22+
},
23+
get minusSmall() {
24+
return {uri: require('./minusSmall.png').default, width: 16, height: 16};
25+
},
26+
get plusOutline() {
27+
return {uri: require('./plusOutline.png').default, width: 32, height: 32};
28+
},
29+
get plusOutlineSmall() {
30+
return {uri: require('./plusOutlineSmall.png').default, width: 24, height: 24};
31+
},
32+
get plusSmall() {
33+
return {uri: require('./plusSmall.png').default, width: 16, height: 16};
34+
},
35+
get search() {
36+
return {uri: require('./search.png').default, width: 24, height: 24};
37+
},
38+
get x() {
39+
return {uri: require('./x.png').default, width: 17, height: 16};
40+
},
41+
get xFlat() {
42+
return {uri: require('./xFlat.png').default, width: 16, height: 16};
43+
},
44+
get xMedium() {
45+
return {uri: require('./xMedium.png').default, width: 24, height: 24};
46+
},
47+
get xSmall() {
48+
return {uri: require('./xSmall.png').default, width: 16, height: 16};
49+
}
50+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export const images = {
2+
get gradient() {
3+
return {uri: require('./gradient.png').default, width: 56, height: 2};
4+
},
5+
get gradientOverlay() {
6+
return {uri: require('./gradientOverlay.png').default, width: 76, height: 48};
7+
},
8+
get gradientOverlayHigh() {
9+
return {uri: require('./gradientOverlayHigh.png').default, width: 1, height: 297};
10+
},
11+
get gradientOverlayLow() {
12+
return {uri: require('./gradientOverlayLow.png').default, width: 1, height: 297};
13+
},
14+
get gradientOverlayMedium() {
15+
return {uri: require('./gradientOverlayMedium.png').default, width: 1, height: 297};
16+
},
17+
get hintTipMiddle() {
18+
return {uri: require('./hintTipMiddle.png').default, width: 20, height: 7};
19+
},
20+
get hintTipSide() {
21+
return {uri: require('./hintTipSide.png').default, width: 20, height: 24};
22+
},
23+
get transparentSwatch() {
24+
return {uri: require('./transparentSwatch.png').default, width: 100, height: 100};
25+
}
26+
};

src/components/icon/index.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,9 @@ export type IconProps = Omit<RNImageProps, 'source' | 'tintColor'> &
4747

4848
type Props = IconProps & BaseComponentInjectedProps;
4949

50-
const DEFAULT_WEB_ICON_SIZE = 16;
51-
5250
const Icon = forwardRef((props: Props, ref: any) => {
5351
const {
54-
size = Constants.isWeb ? DEFAULT_WEB_ICON_SIZE : undefined,
52+
size,
5553
tintColor,
5654
style,
5755
supportRTL,
@@ -86,17 +84,19 @@ const Icon = forwardRef((props: Props, ref: any) => {
8684
return source;
8785
}, [source, assetGroup, assetName]);
8886

89-
const renderImage = () => (
90-
<Image
91-
accessible={false}
92-
accessibilityRole={'image'}
93-
fsTagName={recorderTag}
94-
{...others}
95-
ref={ref}
96-
source={iconSource}
97-
style={[margins, iconSize, shouldFlipRTL && styles.rtlFlipped, !!tintColor && {tintColor}, style]}
98-
/>
99-
);
87+
const renderImage = () => {
88+
return (
89+
<Image
90+
accessible={false}
91+
accessibilityRole={'image'}
92+
fsTagName={recorderTag}
93+
{...others}
94+
ref={ref}
95+
source={iconSource}
96+
style={[margins, iconSize, shouldFlipRTL && styles.rtlFlipped, !!tintColor && {tintColor}, style]}
97+
/>
98+
);
99+
};
100100

101101
const renderSvg = () => <SvgImage fsTagName={recorderTag} data={source} {...iconSize} {...props}/>;
102102

webDemo/webpack.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ const imageLoaderConfiguration = {
4343
use: {
4444
loader: 'url-loader',
4545
options: {
46-
name: '[name].[ext]',
47-
esModule: false
46+
name: '[name].[ext]'
4847
}
4948
}
5049
};

0 commit comments

Comments
 (0)