github jpudysz/react-native-unistyles v2.1.0
Release 2.1.0

latest releases: v3.0.0-alpha.35, v3.0.0-alpha.34, v3.0.0-alpha.33...
9 months ago

2.1.0 (2024-01-23)

Features

Example

You can now use boolean values to select the variants:

import { useStyles } from 'react-native-unistyles'

const Component = ({ isPrimary, isDisabled }) => {
    const { styles } = useStyles(stylesheet, {
        color: !isDisabled,
        borderColor: isPrimary
        // you can also use strings
        // color: "true" | "false"
    })

    return (
        <View style={styles.container} />
    )
}

const stylesheet = createStyleSheet(theme => ({
    container: {
        // otter styles
        variants: {
            color: {
                true: {
                    backgroundColor: theme.colors.primary
                },
                false: {
                    backgroundColor: theme.colors.disabled
                },
                // you can still specify a default variant
                default: {
                    backgroundColor: theme.colors.barbie
                }
                // or other variants
                special: {
                    backgroundColor: theme.colors.special
                }
            },
            borderColor: {
                true: {
                    borderColor: theme.colors.primary
                }
                // you can also skip "false" here
            }
        }
    }
})

If you specify a boolean variants like “true”, there is no requirement to specify a “false” variant (and vice versa). You can mix boolean variants with other variants as well.

Don't miss a new react-native-unistyles release

NewReleases is sending notifications on new releases.