Skip to content

Commit

Permalink
fix: function style not working (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
norman-ags authored Sep 28, 2021
1 parent 2f65863 commit 8ff922d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
19 changes: 17 additions & 2 deletions example/src/Example.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Switch, View, ViewProps } from 'react-native';
import { Switch, View, ViewProps, SafeAreaView, Text } from 'react-native';
import { StatusBar } from 'expo-status-bar';

import { styled, css, useTheme, theme } from './styled';
Expand All @@ -18,7 +18,20 @@ export default function Example({
<>
<Wrapper>
<Switch value={mode === 'dark'} onValueChange={toggleMode} />

<SafeAreaView>
<StyledPressable
style={({ pressed }) => {
console.log({ pressed });
return [
{
backgroundColor: pressed ? 'red' : 'blue',
},
];
}}
>
<Text style={{ color: '#FFFFFF' }}>Styled function Pressable</Text>
</StyledPressable>
</SafeAreaView>
<RowView>
<Button variant="primary">
<ButtonText color="white">Hello</ButtonText>
Expand Down Expand Up @@ -211,3 +224,5 @@ const ButtonText = styled('Text', {
variant: 'body',
},
});

const StyledPressable = styled('Pressable', {});
21 changes: 14 additions & 7 deletions src/internals/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,22 @@ export function createStitches(config = {}) {
})
: {};

const stitchesStyles = [
styleSheet.base,
...variantStyles,
...compoundVariantStyles,
cssStyles,
];

const allStyles =
typeof props.style === 'function'
? (...rest) =>
[props.style(...rest), ...stitchesStyles].filter(Boolean)
: [...stitchesStyles, props.style].filter(Boolean);

const componentProps = {
...props,
style: [
styleSheet.base,
...variantStyles,
...compoundVariantStyles,
cssStyles,
props.style,
].filter(Boolean),
style: allStyles,
ref,
};

Expand Down

0 comments on commit 8ff922d

Please sign in to comment.