Skip to content

Infra/assets internal new structure #3635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
627ecbb
Add internal assets module with icons and images
adids1221 Mar 16, 2025
09884c2
Refactor icon imports to use internal assets for consistency
adids1221 Mar 16, 2025
517b077
Refactor asset imports to use internal structure and remove assets.ic…
adids1221 Mar 16, 2025
2219ccb
Add xSmall icon and update ChipsInput to use internal assets
adids1221 Mar 16, 2025
bf5b253
Add transparentSwatch icon and update ColorSwatch component to use it
adids1221 Mar 16, 2025
9c59698
Add dropdown to icons and update useFieldType to utilize internal assets
adids1221 Mar 16, 2025
76d7e03
Add hintTip icons and update Hint component to use internal assets
adids1221 Mar 16, 2025
c25d1e5
Add checkMarkSmall and exclamationSmall icons, update WizardStates to…
adids1221 Mar 16, 2025
1224520
Add gradient overlay images and update Overlay component to use inter…
adids1221 Mar 16, 2025
5bac3cf
Add gradientOverlay image and update ScrollBar component to use it
adids1221 Mar 16, 2025
893c73e
move hint, swatch assets to internal.images
adids1221 Mar 17, 2025
656b0ac
Rename icons.dropdown to icons.chevronDown
adids1221 Mar 17, 2025
d9168a8
Add icons.demo and update references in components screens
adids1221 Mar 17, 2025
f5099c3
rename checkSmall icon file and update icons - index.js reference
adids1221 Mar 17, 2025
64e5930
Merge branch 'master' into infra/Assets_internal
adids1221 Mar 17, 2025
94b12f8
Update ColorSwatch to use internal.images for transparentSwatch
adids1221 Mar 18, 2025
9857ed7
Refactor icon and image exports to include URI and dimensions
adids1221 Mar 18, 2025
e8c0415
Refactor image handling to extract image source and apply dimensions …
adids1221 Mar 18, 2025
730a5c9
Update snapshots to reflect changes in image in Avatar, TextField, Bu…
adids1221 Mar 18, 2025
50761fa
remove unnecessary default export in check icon
adids1221 Mar 18, 2025
121d646
Add script to extract image dimensions and update package.json
adids1221 Mar 18, 2025
33629c6
Merge branch 'master' into infra/Assets_internal_new_strucure
adids1221 Mar 19, 2025
fde6928
Revert new structure, split into index.web filesÏ
adids1221 Mar 19, 2025
c7e17a0
Merge branch 'master' into infra/Assets_internal
adids1221 Mar 19, 2025
52fdada
Merge branch 'infra/Assets_internal' into infra/Assets_internal_new_s…
adids1221 Mar 19, 2025
c21c826
Icon remove DEFAULT_WEB_ICON_SIZE
adids1221 Mar 19, 2025
9aee276
Stepper local assets remove, move to Assets
adids1221 Mar 19, 2025
fd939f3
Merge branch 'infra/Assets_internal' into infra/Assets_internal_new_s…
adids1221 Mar 19, 2025
0c88600
Add new icon variants: minusOutline, minusOutlineSmall, plusOutline, …
adids1221 Mar 19, 2025
0caa8d2
Update asset imports to use .default for images and icons
adids1221 Mar 19, 2025
7dc1ac4
Remove esModule option from url-loader configuration in webpack
adids1221 Mar 19, 2025
267e930
Remove docuilib configurations from ReactLiveScope
adids1221 Mar 19, 2025
06f0d96
Bump version to 3.14.0 in package.json
adids1221 Mar 19, 2025
4d64cbf
Refactor icon asset loading to use the new web assets structure
adids1221 Mar 20, 2025
4adb167
Rename update-web-assets script to updateWebAssets in package.json
adids1221 Mar 20, 2025
34b9e07
changed extract-dimensions script to use console.error
adids1221 Mar 20, 2025
e81cd7e
Update file filtering in createIndexFile to exclude sized assets
adids1221 Mar 20, 2025
ae1eff4
rename extract-dimensions script
adids1221 Mar 20, 2025
58eb45c
Merge branch 'master' into infra/Assets_internal_new_strucure
adids1221 Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes
File renamed without changes
File renamed without changes
5 changes: 4 additions & 1 deletion demo/src/configurations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ export const loadDemoConfigurations = () => {
settings: require('./assets/icons/settings.png'),
share: require('./assets/icons/share.png'),
info: require('./assets/icons/info.png'),
exclamation: require('./assets/icons/exclamationFillSmall.png')
exclamation: require('./assets/icons/exclamationFillSmall.png'),
check: require('./assets/icons/check.png'),
x: require('./assets/icons/x.png'),
minus: require('./assets/icons/minusSmall.png')
});

Assets.loadAssetsGroup('images.demo', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3933,7 +3933,7 @@ exports[`TextField Screen renders screen 1`] = `
accessible={false}
source={
{
"testUri": "../../../src/assets/icons/xFlat.png",
"testUri": "../../../src/assets/internal/icons/xFlat.png",
}
}
style={
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/CheckboxScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class CheckboxScreen extends Component {
borderRadius={2}
size={30}
color={Colors.purple30}
selectedIcon={Assets.icons.x}
selectedIcon={Assets.icons.demo.x}
marginL-s5
/>

Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/IconScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const IconScreen = () => {
<Icon
size={customSize ? size : undefined}
tintColor={customColor ? (color as string) : undefined}
source={Assets.icons.search}
source={Assets.icons.demo.search}
badgeProps={
useBadge
? {
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/ModalScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default class ModalScreen extends Component<ModalScreenProps, State> {
]}
leftButtons={[
{
icon: Assets.icons.x,
icon: Assets.icons.demo.x,
onPress: () => Alert.alert('back'),
buttonProps: {hitSlop: BUTTONS_HIT_SLOP, iconStyle: {tintColor: Colors.yellow10}}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/PickerScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const renderContact = (contactValue: any, props: any) => {
{contact?.name}
</Text>
</View>
{props.isSelected && <Icon source={Assets.icons.check} tintColor={Colors.$iconDefault}/>}
{props.isSelected && <Icon source={Assets.icons.demo.check} tintColor={Colors.$iconDefault}/>}
</View>
);
};
Expand Down
4 changes: 2 additions & 2 deletions demo/src/screens/componentScreens/RadioButtonScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export default class RadioButtonScreen extends Component {
Yes or No?
</Text>
<View row>
{this.renderRadioButtonWithImage('yes', Assets.icons.check, {tintColor: 'green'})}
{this.renderRadioButtonWithImage('no', Assets.icons.x, {tintColor: 'red'})}
{this.renderRadioButtonWithImage('yes', Assets.icons.demo.check, {tintColor: 'green'})}
{this.renderRadioButtonWithImage('no', Assets.icons.demo.x, {tintColor: 'red'})}
</View>
<Text marginT-10>You chose: {this.state.value}</Text>
</RadioGroup>
Expand Down
24 changes: 20 additions & 4 deletions demo/src/screens/componentScreens/SegmentedControlScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import React, {useCallback, useState} from 'react';
import {StyleSheet} from 'react-native';
import {Text, View, Colors, SegmentedControl, Assets, Spacings, BorderRadiuses, Typography, SegmentedControlItemProps} from 'react-native-ui-lib';
import {
Text,
View,
Colors,
SegmentedControl,
Assets,
Spacings,
BorderRadiuses,
Typography,
SegmentedControlItemProps
} from 'react-native-ui-lib';

const segments: Record<string, Array<SegmentedControlItemProps>> = {
first: [{label: 'Default'}, {label: 'Form'}],
second: [{label: '1'}, {label: '2'}, {label: '3'}, {label: Assets.emojis.airplane}, {label: '5'}],
third: [
{
label: 'Very Long Label with icon',
iconSource: Assets.icons.search,
iconSource: Assets.icons.demo.search,
iconStyle: {marginLeft: Spacings.s1, width: 16, height: 16},
iconOnRight: true
},
Expand All @@ -18,7 +28,11 @@ const segments: Record<string, Array<SegmentedControlItemProps>> = {
fifth: [{label: 'Full'}, {label: 'Width'}],
sixth: [{label: 'Full'}, {label: 'Width'}, {label: 'With'}, {label: 'A'}, {label: 'Very Long Segment'}],
seventh: [{label: '$'}, {label: '%'}],
eighth: [{label: 'Plus', iconSource: Assets.icons.plusSmall}, {label: 'Minus', iconSource: Assets.icons.minusSmall}, {label: 'Check', iconSource: Assets.icons.checkSmall}],
eighth: [
{label: 'Plus', iconSource: Assets.icons.demo.plus},
{label: 'Minus', iconSource: Assets.icons.demo.minus},
{label: 'Check', iconSource: Assets.icons.demo.check}
],
ninth: [{label: 'with'}, {label: 'a'}, {label: 'label'}]
};

Expand Down Expand Up @@ -72,7 +86,9 @@ const SegmentedControlScreen = () => {
segmentLabelStyle={styles.customTypography}
preset={screenPreset}
/>
<Text center marginT-s4>With Icons</Text>
<Text center marginT-s4>
With Icons
</Text>
<SegmentedControl segments={segments.eighth} preset={screenPreset}/>
<Text marginT-s4 center>
Custom Styling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Tab1 extends Component {
round
style={{width: 50}}
size={Button.sizes.small}
iconSource={Assets.icons.search}
iconSource={Assets.icons.demo.search}
white
/>
</View>
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/componentScreens/ToastsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default class ToastsScreen extends Component {
onDismiss={this.dismissTopToast}
// autoDismiss={3000}
showDismiss={showDismiss}
// action={{iconSource: Assets.icons.x, onPress: () => console.log('dismiss')}}
// action={{iconSource: Assets.icons.demo.x, onPress: () => console.log('dismiss')}}
showLoader={showLoader}
/>
<Toast
Expand Down
2 changes: 1 addition & 1 deletion demo/src/screens/realExamples/ListActions/ActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default class ActionsList extends Component {
size={'xSmall'}
round
backgroundColor="transparent"
iconSource={Assets.icons.x}
iconSource={Assets.icons.demo.x}
iconStyle={{tintColor: Colors.white}}
onPress={() => {
// console.warn('dismiss press');
Expand Down
2 changes: 1 addition & 1 deletion docuilib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uilib-docs",
"version": "3.13.0",
"version": "3.14.0",
"main": "./src/index.ts",
"scripts": {
"docusaurus": "docusaurus",
Expand Down
11 changes: 0 additions & 11 deletions docuilib/src/theme/ReactLiveScope/configurations.ts

This file was deleted.

1 change: 0 additions & 1 deletion docuilib/src/theme/ReactLiveScope/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import products from '../../assets/data/products';
require('./configurations');
import {Colors} from 'react-native-ui-lib/style';
import {BorderRadiuses, Button, Image, Spacings, Text, TouchableOpacity, View} from 'react-native-ui-lib/core';
import ActionBar from 'react-native-ui-lib/actionBar';
Expand Down
2 changes: 1 addition & 1 deletion expoDemo/MainScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function MainScreen({navigation}) {
preset={null}
text70
fieldStyle={styles.fieldStyle}
leadingAccessory={<Icon source={Assets.icons.search} marginH-s2/>}
leadingAccessory={<Icon source={Assets.internal.icons.search} marginH-s2/>}
/>
}
sections={sections}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"releaseDemo": "./scripts/release/releaseDemo.sh",
"releaseDocs": "./scripts/release/releaseDocs.sh",
"releaseEslint": "./scripts/release/releaseEslint.sh",
"releaseNative": "./scripts/release/releaseNative.sh"
"releaseNative": "./scripts/release/releaseNative.sh",
"update-web-assets": "node scripts/assets/extract-dimensions.js"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateWebAssets - let's follow the other scripts' naming convention

},
"dependencies": {
"babel-plugin-transform-inline-environment-variables": "^0.0.2",
Expand Down
86 changes: 86 additions & 0 deletions scripts/assets/extract-dimensions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
const fs = require('fs');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename the file to extractDimensions.js

const path = require('path');
const mime = require('mime-types');
const {imageSize: sizeOf} = require('image-size');

// Base paths
const ICONS_PATH = path.resolve(__dirname, '../../src/assets/internal/icons');
const IMAGES_PATH = path.resolve(__dirname, '../../src/assets/internal/images');

// Function to check if file is an image
function isImageFile(filePath) {
const mimeType = mime.lookup(filePath);
return !!mimeType && mimeType.includes('image');
}

// Function to get dimensions of an image
function getDimensions(imagePath) {
try {
if (!isImageFile(imagePath)) {
console.warn(`File is not an image: ${imagePath}`);
return {width: 0, height: 0};
}

try {
const buffer = fs.readFileSync(imagePath);
const dimensions = sizeOf(buffer);
return {
width: dimensions.width,
height: dimensions.height
};
} catch (sizeError) {
console.log(`Error getting dimensions for ${imagePath}:`, sizeError);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd put this as error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed, added // eslint-disable-next-line no-restricted-syntax since we have eslint over this.
Also for the other console .

// Default dimensions if sizeOf fails
return {width: 24, height: 24};
}
} catch (error) {
console.log(`Error getting dimensions for ${imagePath}:`, error);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be error

return {width: 0, height: 0};
}
}

// Function to create index files with dimensions
function createIndexFile(sourcePath, targetPath, fileType) {
const files = fs.readdirSync(sourcePath).filter(file => !file.includes('@') && !file.startsWith('.'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what the !file.startsWith('.') is about?

Copy link
Contributor Author

@adids1221 adids1221 Mar 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is Devin script.
Iv'e check it's unnecessary removed.
for now we don't want to include the "sized" files @1.5x...


let content = '';

if (fileType === 'icons') {
content = 'export const icons = {\n';
} else if (fileType === 'images') {
content = 'export const images = {\n';
}

files.forEach((file, index) => {
const filePath = path.join(sourcePath, file);
const mimeType = mime.lookup(filePath);
const isImage = !!mimeType && mimeType.includes('image');

if (!isImage) {
console.warn(`Skipping non-image file: ${filePath}`);
return;
}

const name = path.basename(file, path.extname(file));
const dimensions = getDimensions(filePath);

// Handle hyphenated filenames by converting to camelCase
const propertyName = name.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());

content += ` get ${propertyName}() {\n`;
// eslint-disable-next-line max-len
content += ` return {uri: require('./${file}').default, width: ${dimensions.width}, height: ${dimensions.height}};\n`;
content += index === files.length - 1 ? ` }\n` : ` },\n`; // Conditional check for the last file
});

content += '};\n';

fs.writeFileSync(targetPath, content);
console.log(`Created ${targetPath}`);
}

// Create index files
createIndexFile(ICONS_PATH, path.join(ICONS_PATH, 'index.web.js'), 'icons');
createIndexFile(IMAGES_PATH, path.join(IMAGES_PATH, 'index.web.js'), 'images');

console.log('Index files created successfully!');
26 changes: 0 additions & 26 deletions src/assets/icons/index.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/assets/images/index.js

This file was deleted.

7 changes: 2 additions & 5 deletions src/assets/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {Assets} from './Assets';

export default new Assets().loadAssetsGroup('', {
get icons() {
return require('./icons').icons;
},
get emojis() {
return require('./emojis').emojis;
},
get images() {
return require('./images').images;
get internal() {
return require('./internal').internal;
}
});
Binary file added src/assets/internal/icons/check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/internal/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/internal/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/internal/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/internal/icons/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions src/assets/internal/icons/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export const icons = {
get check() {
return require('./check.png');
},
get checkMarkSmall() {
return require('./checkMarkSmall.png');
},
get checkSmall() {
return require('./checkSmall.png');
},
get chevronDown() {
return require('./chevronDown.png');
},
get exclamationSmall() {
return require('./exclamationSmall.png');
},
get minusOutline() {
return require('./minusOutline.png');
},
get minusOutlineSmall() {
return require('./minusOutlineSmall.png');
},
get minusSmall() {
return require('./minusSmall.png');
},
get plusOutline() {
return require('./plusOutline.png');
},
get plusOutlineSmall() {
return require('./plusOutlineSmall.png');
},
get plusSmall() {
return require('./plusSmall.png');
},
get search() {
return require('./search.png');
},
get x() {
return require('./x.png');
},
get xFlat() {
return require('./xFlat.png');
},
get xMedium() {
return require('./xMedium.png');
},
get xSmall() {
return require('./xSmall.png');
}
};
Loading