Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #411 from gluestack/patch
Browse files Browse the repository at this point in the history
chore: @gluestack-style/[email protected]
  • Loading branch information
ankit-tailor authored Sep 11, 2023
2 parents f31d20b + f2fce65 commit 586c5b0
Show file tree
Hide file tree
Showing 12 changed files with 228 additions and 186 deletions.
37 changes: 25 additions & 12 deletions example/ui-examples-babel/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,27 @@ export function ContextBasedStylesContent() {
);
}

const renderItem = (item: any) => (
<Pressable
key={item}
sx={{
bg: '$amber400',
}}
>
{/* <RNText>{item}</RNText> */}
</Pressable>
);
const RenderItem = (item: any) => {
const [active, setActive] = React.useState(false);
return (
<Pressable
key={item}
onPressIn={() => setActive(true)}
onPressOut={() => setActive(false)}
states={{
active,
}}
sx={{
'bg': '$amber400',
':active': {
bg: '$pink500',
},
}}
>
{/* <RNText>{item}</RNText> */}
</Pressable>
);
};

const renderItem2 = (item: any) => (
<RNPressable key={item} style={styleshet.style}>
Expand All @@ -164,7 +175,7 @@ const MyList = React.memo(() => {
}, []);
const data = useMemo(
() =>
Array(100)
Array(1000)
.fill(0)
.map((_, index) => `Item ${index}`),
[]
Expand All @@ -182,7 +193,9 @@ const MyList = React.memo(() => {
>
{endTime}
</Text>
{data.map(renderItem)}
{data.map((_, k) => (
<RenderItem key={k} />
))}
</>
);
});
Expand Down
37 changes: 33 additions & 4 deletions example/ui-examples-babel/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const myBabel = require('../../packages/babel-plugin-styled-resolver/src/index.js');
const path = require('path');
// process.env.GLUESTACK_STYLE_TARGET = 'native';

module.exports = function (api) {
api.cache(true);
Expand All @@ -11,13 +12,41 @@ module.exports = function (api) {
{
configPath: path.join(__dirname, './gluestack-ui.config.ts'),
configThemePath: ['theme'],
// styled: [
// // '@gluestack-style/react',
// // path.resolve(__dirname, './gluestack-ui-components/core/styled'),
// ],
styled: [
// '@gluestack-style/react',
path.join(__dirname, '../../packages/react/src'),
],
// components: ['@gluesatck-ui/themed'],
},
],
[
'module-resolver',
{
alias: {
// For development, we want to alias the library to the source
['@gluestack-style/react']: path.join(
__dirname,
'../../packages/react/src'
),
// ['@gluestack-style/animation-plugin']: path.join(
// __dirname,
// '../../packages/animation-plugin/src'
// ),
// ['@dank-style/react']: path.join(
// __dirname,
// '../../packages/react/src'
// ),
// ['@gluestack-style/animation-plugin']: path.join(
// __dirname,
// '../../packages/animation-plugin/src'
// ),
// ['@dank-style/animation-plugin']: path.join(
// __dirname,
// '../../packages/animation-plugin/src'
// ),
},
},
],
],
};
};
7 changes: 3 additions & 4 deletions example/ui-examples-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"scripts": {
"start": "expo start --dev-client",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"run:ios": "expo start --ios",
"ios": "GLUESTACK_STYLE_TARGET=native expo start --ios",
"web": "GLUESTACK_STYLE_TARGET=web expo start --web",
"build": "tsc",
"native:prod": "expo start --no-dev --minify"
"native:prod": "GLUESTACK_STYLE_TARGET=native expo start --no-dev --minify"
},
"dependencies": {
"@expo-google-fonts/inter": "^0.2.3",
Expand Down
8 changes: 4 additions & 4 deletions example/ui-examples/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module.exports = function (api) {
{
alias: {
// For development, we want to alias the library to the source
// ['@gluestack-style/react']: path.join(
// __dirname,
// '../../packages/react/lib/commonjs'
// ),
['@gluestack-style/react']: path.join(
__dirname,
'../../packages/react/src'
),
// ['@gluestack-style/animation-plugin']: path.join(
// __dirname,
// '../../packages/animation-plugin/src'
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin-styled-resolver/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gluestack-style/babel-plugin-styled-resolver",
"version": "0.2.3",
"version": "0.2.4",
"description": "A gluestack-style babel plugin that transpiles your styled function calls and resolves the component styling in build time.",
"keywords": [
"css-in-js",
Expand Down
27 changes: 12 additions & 15 deletions packages/babel-plugin-styled-resolver/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ module.exports = function (b) {
const components = ['@gluestack-ui/themed'];
let isStyledPathConfigured = false;
let isComponentsPathConfigured = false;
let targetPlatform = process.env.GLUESTACK_STYLE_TARGET;

return {
name: 'ast-transform', // not required
Expand Down Expand Up @@ -884,6 +885,17 @@ module.exports = function (b) {
let orderResolvedArrayExpression = [];

orderedResolvedTheme.forEach((styledResolved) => {
if (targetPlatform === 'native') {
delete styledResolved.original;
delete styledResolved.value;
delete styledResolved.meta.cssRulesSet;
delete styledResolved.meta.weight;
delete styledResolved.meta.weight;
delete styledResolved.type;
delete styledResolved.componentHash;
delete styledResolved.extendedConfig;
delete styledResolved.value;
}
let orderedResolvedAst = generateObjectAst(styledResolved);
orderResolvedArrayExpression.push(orderedResolvedAst);
});
Expand All @@ -898,12 +910,6 @@ module.exports = function (b) {
t.jsxExpressionContainer(styleIdsAst)
)
);
jsxOpeningElementPath.node.attributes.push(
t.jsxAttribute(
t.jsxIdentifier('toBeInjected'),
t.jsxExpressionContainer(toBeInjectedAst)
)
);
jsxOpeningElementPath.node.attributes.push(
t.jsxAttribute(
t.jsxIdentifier('orderedResolved'),
Expand All @@ -912,15 +918,6 @@ module.exports = function (b) {
)
)
);
jsxOpeningElementPath.node.attributes.push(
t.jsxAttribute(t.jsxIdentifier('sxHash'), t.stringLiteral(sxHash))
);
jsxOpeningElementPath.node.attributes.push(
t.jsxAttribute(
t.jsxIdentifier('styledIds'),
t.jsxExpressionContainer(orderedStyleIdsArrayAst)
)
);
}

if (
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@gluestack-style/react",
"description": "A universal & performant styling library for React Native, Next.js & React",
"version": "0.2.38",
"version": "0.2.40",
"keywords": [
"React Native",
"Next.js",
Expand Down
5 changes: 2 additions & 3 deletions packages/react/src/generateStylePropsFromCSSIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,10 @@ export function generateStylePropsFromCSSIds(
const nativeStyleMap = GluestackStyleSheet.getStyleMap();
styleCSSIds.forEach((cssId: any) => {
const nativeStyle = nativeStyleMap.get(cssId);

if (nativeStyle) {
const queryCondition = nativeStyle?.meta?.queryCondition;
const styleSheetIds = nativeStyle?.value;
const styleSheet = styleSheetIds;

const styleSheet = nativeStyle?.resolved;
if (queryCondition) {
if (isValidBreakpoint(config, queryCondition)) {
styleObj.push(styleSheet);
Expand Down
Loading

0 comments on commit 586c5b0

Please sign in to comment.