npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-theme-mk

v0.1.6

Published

Package for managing theme in react-native

Downloads

13

Readme

react-native-theme-mk

Package for managing theme in react-native

A simple solution for theme management in react-native, with its help you can use any schemes, with type definitions, with the ability to dynamically update the theme, with access to device data (width, height)

Installation

npm install react-native-safe-area-context react-native-theme-mk

Usage

Usage

ThemeManager

Constructor options

| Option | Description | |---------------------------|--------------------------------------------------| | dimensionsDesignedDevice| Dimensions of the designed device (optional). | | autoScale | Enables auto-scaling (optional). |

Methods and fields

| Method/Field | Description | |---------------------------|--------------------------------------------------| | name | The name of the current theme. | | theme | The current theme object. | | context | The React context for the current theme. | | set | Sets the current theme by name. | | get | Gets a theme by name. | | onChangeName | Registers a callback for theme name changes. | | removeAllListeners | Removes all registered listeners. | | createStyleSheet | Creates a style sheet using the provided styles creator. | | useTheme | Hook to use the current theme. | | useDevice | Hook to use the device information. | | useScale | Hook to use the scale factor. | | device | The device information. | | dimensionsDesignedDevice| The dimensions of the designed device. |

createStyleSheet

| Parameter | Type | Description | |-----------|------|-------------| | params | object | An object containing the following properties: | | params.theme | C[keyof C] | The current theme object. | | params.device | IDevice | The device information. | | params.scale | number | The scale factor. |

Device

| Property | Description | |---------------------------|--------------------------------------------------| | isAndroid | Indicates if the device is running Android. | | isIOS | Indicates if the device is running iOS. | | isTablet | Indicates if the device is a tablet. | | isIphoneX | Indicates if the device is an iPhone X. | | window | Dimensions of the device's window. | | screen | Dimensions of the device's screen. | | orientation | Current orientation of the device. | | isLandscape | Indicates if the device is in landscape mode. | | isPortrait | Indicates if the device is in portrait mode. | | inset | Insets of the device's screen. | | isSmallScreen | Indicates if the device has a small screen. | | isShortScreen | Indicates if the device has a short screen. | | screenAspectRatio | Aspect ratio of the device's screen. |

Example

import { themePrimary } from './primary-theme';
import { ThemeManager as ThemeManagerCreator } from 'react-native-theme-mk';
import { type IThemeManagerSchema } from './types';

const theme = {
    primary: themePrimary,
};

export const ThemeManager = new ThemeManagerCreator(
    'dark',
    {
        light: lightTheme,
        dark: darkTheme,
    },
    {
        autoScale: true,
        //@default designed device dimensions
        dimensionsDesignedDevice: {
            width: 375,
            height: 812,
        }
    },
);
import { HomeScreen } from './screens/Home';
import { ThemeManager } from './styles';

const { ThemeProvider } = ThemeManager;

export default function App() {
    return (
        <ThemeProvider>
            <HomeScreen />
        </ThemeProvider>
    );
}
import { ThemeManager } from '../../styles';

export const useStyles = ThemeManager.createStyleSheet(({ theme }) => ({
    container: {
        flex: 1,
        backgroundColor: theme.colors.background,
    },
    text: theme.text.h1,
    button: {
        margin: theme.lineHeight.H1,
        height: 50,
        backgroundColor: theme.colors.accent,
    },
}));
import { View, Text, TouchableOpacity } from 'react-native';
import { useStyles } from './screen.styles';
import { ThemeManager } from '../../styles';

const { useTheme } = ThemeManager;

export const HomeScreen = () => {
    const styles = useStyles({ overrideAutoScale: false, overrideThemeName: 'light' });
    const theme = useTheme();

    return (
        <View style={[styles.container]}>
            <Text style={[styles.text]}>Screen Light Theme</Text>
            <Text style={[styles.text, { color: theme.colors.accent }]}>Light/Dark Theme text</Text>
            <TouchableOpacity style={styles.button}>
                <Text style={styles.text}>Button</Text>
            </TouchableOpacity>
        </View>
    );
};

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library