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

@dokuhero/react-native-theme

v0.1.2

Published

Theme and stylesheet manager for ReactNative.

Downloads

6

Readme

React Native Theme

Theme and stylesheet manager for ReactNative.

Installation

Using npm:

npm i -S @dokuhero/react-native-theme

or yarn:

yarn add @dokuhero/react-native-theme

Usage

Create your themes

You'll use createTheme function to create new theme. Call this function without any parameter will produce default theme values.

import { createTheme } from '@dokuhero/react-native-theme'

export const dark = createTheme({
  id: 'dark',
  name: 'dark',
  color: {
    primary: '#3878c7',
    secondary: '#44d4fc'
  }
  // just follow intellisense to override default theme values...
  // you may also create new key value here.
})

You may also override your existing theme as if needed

import { createTheme } from '@dokuhero/react-native-theme'

export const dark = createTheme(light, {
  id: 'light',
  name: 'light',
  color: {
    primary: '#ffff'
  }
  // ....
}

Theme Provider

Put ThemeProvider (a React context provider for theme) on your top View of application.

import { Theme, ThemeProvider } from '@dokuhero/react-native-theme'

export class MainScreen extends React.Component<Partial<StateProps>> {
  render() {
    return (
      <ThemeProvider value={light}>
        <View style={{ flex: 1 }}>{/* rest of code.. */}</View>
      </ThemeProvider>
    )
  }
}

Theme Consumer

To consume theme, you can use ThemeConsumer (a React context consumer), or use withTheme HOC function or also withThemeClass class decorator.

ThemeConsumer

const TheComponent: React.SFC = (({children})) => (
  <ThemeConsumer>
    {({ color, space, radius }) => (
      <View style={{
          backgroundColor: color.dark,
          padding: space.medium,
          borderRadius: radius.small
        }}>
        {children}
      </View>
    )}
  </ThemeConsumer>
)

withTheme HOC

interface TheComponentProps {
  children?: React.ReactNode
}

const TheComponent: withTheme<TheComponentProps>(({children, color, space, radius}) => (
  <View style={{
      backgroundColor: color.dark,
      padding: space.medium,
      borderRadius: radius.small
    }}>
    {children}
  </View>
))

withThemeClass class decorator

import { withThemeClass, WithThemeProps } from '@dokuhero/react-native-theme'

interface TheComponentProps extends WithThemeProps {
  children?: React.ReactNode;
}

@withThemeClass()
export class TheComponent extends React.Component<TheComponentProps> {
  render() {
    const {
      theme: { children, color, space, radius }
    } = this.props

    return (
      <View
        style={{
          backgroundColor: color.dark,
          padding: space.medium,
          borderRadius: radius.small
        }}
      >
        {children}
      </View>
    )
  }
}

Themed Stylesheet

We are using react-native-extended-stylesheet to build our Stylesheet module.

createStyleSheet

This is to define your style sheet.

// styles.ts

import {
  ColorKeys,
  createStyleSheet,
  RadiusKeys,
  SpaceKeys
} from '@dokuhero/react-native-theme'

export const styles = createStyleSheet({
  container: {
    flex: 1
  },
  form: {
    backgroundColor: ColorKeys.primary,
    paddingBottom: SpaceKeys.medium,
    borderRadius: RadiusKeys.small,
    alignContent: 'center'
  },
  formContainer: { width: '100%', padding: SpaceKeys.medium }
})

Using it as usually

import { styles } from './styles'

export class MyForm extends React.Component {
  render() {
    const { children } = this.props
    return <View style={styles.form}>{children}</View>
  }
}

buildStyleSheet

To make it work, you need to call this function in the very beginning of your app.

buildStyleSheet(light)

And you may call this function again to change theme.

License

MIT