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 #404 from gluestack/release/@gluestack-style/babel…
Browse files Browse the repository at this point in the history
[email protected]

Release/@gluestack style/babel plugin styled [email protected]
  • Loading branch information
ankit-tailor authored Sep 8, 2023
2 parents cfcb8df + 1932d57 commit 60334ad
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 93 deletions.
235 changes: 183 additions & 52 deletions example/ui-examples-babel/App.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,189 @@
import React from 'react';
import { useState } from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';

import Gluestack from './BenchGlueStack';
import ReactNative from './BenchReactNative';
import TimedRender from './TimedRender';

export default function App() {
const [styleType, setStyleType] = useState<any>(undefined);

const onStyleTypePress = (curry) => () => {
setStyleType(curry);
};

const renderStyleLibrary = () => {
switch (styleType) {
case 'Gluestack':
return <Gluestack />;
case 'React Native':
return <ReactNative />;
default:
return null;
}
};
import React, {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
useState,
} from 'react';

import {
Pressable as RNPressable,
Text as RNText,
StyleSheet,
View,
} from 'react-native';
import {
AsForwarder,
styled,
Theme,
StyledProvider,
} from '@gluestack-style/react';
import { config } from './gluestack-ui.config';

const styleshet = StyleSheet.create({
style: {
padding: 12,
backgroundColor: 'red',
margin: 4,
},
});

const Pressable = styled(
RNPressable,
{
bg: '$blue500',
p: '$2',
m: '$1',

// 'bg': '$red600',
// 'w': 100,
// 'h': 100,
// '_light': {
// bg: '$red600',
// },
// '@base': {
// bg: '$blue500',
// },
// ':hover': {
// bg: '$red500',
// },
},
{
componentName: 'Pressable1',
// descendantStyle: ['_text'],
}
);

const Text = styled(
RNText,
{},
{
componentName: 'Text',
}
);
export function ContextBasedStyles() {
return (
<View style={styles.container}>
<Text style={styles.text}>Tap a style library to start rendering</Text>
<Button title="React Native" onPress={onStyleTypePress('React Native')} />
<Button title="Gluestack" onPress={onStyleTypePress('Gluestack')} />
{styleType ? (
<TimedRender key={styleType}>
<Text style={styles.text}>
Rendering with <Text style={styles.bold}>{styleType}</Text>
</Text>
</TimedRender>
) : null}
{renderStyleLibrary()}
</View>
<StyledProvider config={config.theme} colorMode="dark">
<ContextBasedStylesContent />
</StyledProvider>
);
}

const styles = StyleSheet.create({
container: {
// alignItems: "center",
backgroundColor: '#fff',
// flex: 1,
// justifyContent: "center",
},
text: {
marginVertical: 12,
},
bold: {
fontWeight: 'bold',
fontSize: 16,
},
export function ContextBasedStylesContent() {
const [state, setState] = useState(false);

// const color = tabName ? '$red500' : '$green500';
// return (
// <>
// {/* <Theme name={'modern'}>
// <Box states={{ hover: true }}></Box>
// </Theme>
// <Box states={{ hover: true }}></Box> */}
// {/* <Icon as={Circle} size="md" color="$red500" />
// <Pressable
// onPress={() => {
// handleTabChange(!tabName);
// }}
// bg="$amber400"
// h="$50"
// w="$50"
// >
// <Text
// sx={{
// _dark: {
// color: tabName ? '$red500' : '$green500',
// },
// }}
// >
// hello world
// </Text>
// </Pressable> */}
// </>
// );

// return (
// <>
// <MyNewIcon as={AlertCircle} size="sm"></MyNewIcon>
// </>
// );
return (
<>
<RNPressable
onPress={() => {
setState(!state);
}}
style={{
height: 50,
width: 200,
backgroundColor: 'red',
position: 'absolute',
top: 0,
left: 0,
top: 132,
}}
>
<Text style={{ color: 'black' }}>{state ? 'Unmount' : 'Mount'}</Text>
</RNPressable>
{/* <MyPressable>
<RNText>Hello</RNText>
</MyPressable> */}
{/* {state && <MyList />
} */}
{/* <Box pointerEvents="none" style={{ display: state ? 'flex' : 'none' }}> */}
{state && <MyList />}
{/* </Box> */}
</>
);
}

const renderItem = (item: any) => (
<Pressable
key={item}
sx={{
bg: '$amber400',
}}
>
{/* <RNText>{item}</RNText> */}
</Pressable>
);

const renderItem2 = (item: any) => (
<RNPressable key={item} style={styleshet.style}>
{/* <RNText>{item}</RNText>r */}
</RNPressable>
);

const MyList = React.memo(() => {
const time = React.useRef(Date.now());
const [endTime, setEndTime] = React.useState(0);
useEffect(() => {
const end = Date.now() - time.current;
console.log(end, '>>>');
setEndTime(end);
}, []);
const data = useMemo(
() =>
Array(100)
.fill(0)
.map((_, index) => `Item ${index}`),
[]
);

return (
<>
<Text
style={{
position: 'absolute',
top: 100,
zIndex: 999,
color: 'blue',
}}
>
{endTime}
</Text>
{data.map(renderItem)}
</>
);
});
export default ContextBasedStyles;
38 changes: 5 additions & 33 deletions example/ui-examples-babel/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,11 @@ 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'),
],
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'
// ),
},
// styled: [
// // '@gluestack-style/react',
// // path.resolve(__dirname, './gluestack-ui-components/core/styled'),
// ],
// components: ['@gluesatck-ui/themed'],
},
],
],
Expand Down
2 changes: 1 addition & 1 deletion example/ui-examples-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@expo/html-elements": "latest",
"@expo/webpack-config": "18.1.0",
"@gluestack-style/animation-plugin": "latest",
"@gluestack-style/react": "0.1.31",
"@gluestack-style/react": "^0.2.32-alpha.0",
"@gluestack-ui/actionsheet": "latest",
"@gluestack-ui/alert": "latest",
"@gluestack-ui/alert-dialog": "latest",
Expand Down
8 changes: 4 additions & 4 deletions example/ui-examples-babel/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1995,10 +1995,10 @@
"@babel/traverse" "^7.20.5"
lodash.merge "^4.6.2"

"@gluestack-style/react@0.1.31":
version "0.1.31"
resolved "https://registry.yarnpkg.com/@gluestack-style/react/-/react-0.1.31.tgz#07e6740d448a49fa0133b6d94dc6239509f6b2df"
integrity sha512-SXVpHJSoNSVFZbOhQVlHInHMloKmZbW0tTzsxbktJcbt0r54dR1o+hsSXfsOBf5aJYLEKaT2jnjXxXAJRE6nOw==
"@gluestack-style/react@^0.2.32-alpha.0":
version "0.2.32-alpha.0"
resolved "https://registry.yarnpkg.com/@gluestack-style/react/-/react-0.2.32-alpha.0.tgz#44fc228f49e64a9c5e2ddd1207c2abf9d092aae6"
integrity sha512-MvKh5P9M0r26h7ZnBht+hG7j1wsGBmgXUlK2NW6x3K4bE78Ji0BafZvu5ba4vn/+9BBAYQatKOD0Gvt6q2hDfQ==
dependencies:
inline-style-prefixer "^6.0.1"
normalize-css-color "^1.0.2"
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.2",
"version": "0.2.3",
"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
22 changes: 20 additions & 2 deletions packages/babel-plugin-styled-resolver/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,31 @@ module.exports = function (b) {
});
}
},
AssignmentExpression(expressionPath, state) {
if (
expressionPath?.node?.right?.callee?.name ===
styledAliasImportedName ||
expressionPath?.node?.right?.callee?.name === styledImportName
) {
// console.log(expressionPath.node, '>>>>>');
let componentName = expressionPath?.parent?.id?.name;

if (componentName) {
guessingStyledComponents.push(componentName);
}
}
},

CallExpression(callExpressionPath) {
if (
callExpressionPath.node.callee.name === styledAliasImportedName ||
callExpressionPath.node.callee.name === styledImportName
) {
if (callExpressionPath?.parent?.id?.name)
guessingStyledComponents.push(callExpressionPath.parent.id.name);
let componentName = callExpressionPath?.parent?.id?.name;

if (componentName) {
guessingStyledComponents.push(componentName);
}
callExpressionPath.traverse({
ObjectProperty(ObjectPath) {
if (t.isIdentifier(ObjectPath.node.value)) {
Expand Down

0 comments on commit 60334ad

Please sign in to comment.