khevamann / rn-responsive-styles

Responsive styles for react-native and react-native-web
MIT License
39 stars 3 forks source link

Bug in responsive styles #7

Closed EthanHermsey closed 2 years ago

EthanHermsey commented 2 years ago

Hey Kheva,

I've found a bug. Sorry for the amount of discussion that I'm throwing at you, I hope it's not too much.

In the example below there's a Text component that is supposed to change ONLY it's fontSize according to the device size. Eventhough I explicitly state the fontWeight should be 300, it still changed it to 700 ( from the textbold style ) in screen sizes medium and smaller. I'm fairly certain this is the intended use ( but not the intended result ). I'm suspecting the regex has something to do with this, not sure.

import { CreateResponsiveStyle, DEVICE_SIZES, maxSize } from 'rn-responsive-styles'
import { Text, View } from 'react-native';

export default function App() {
    const { styles } = useStyles();

    return (
        <View style={styles('center')}>
            <Text style={styles('text')}>Open up App.tsx to start working on your app!</Text>
        </View>
    );
}

const useStyles = CreateResponsiveStyle(
    {
        center: {
            flex: 1,
            justifyContent: "center",
            alignItems: "center",
            textAlign: "center",
        },
        text: {
            fontSize: 40,
            fontWeight: '300'
        },
        textlight: {
            fontWeight: '300'
        },
        textbold: {
            fontWeight: '700'
        },

    },
    {
        [maxSize(DEVICE_SIZES.MEDIUM_DEVICE)]: {
            text: {
                fontSize: 30,
                fontWeight: '300'
            },
            textlight: {
                fontWeight: '300'
            },
            textbold: {
                fontWeight: '700'
            },
        },
        [maxSize(DEVICE_SIZES.SMALL_DEVICE)]: {
            text: {
                fontSize: 20,
                fontWeight: '300'
            },
            textlight: {
                fontWeight: '300'
            },
            textbold: {
                fontWeight: '700'
            },
        }
    }
)
khevamann commented 2 years ago

Wow! Good catch, yes this is an important issue. Thank you for finding this!

Also sorry for the late reply, I love that you are opening issues and contributing, it is nice to have someone else pushing development and improvements.