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-responsive-theme-provider

v0.1.2

Published

`Dimensions` aware styled-components theme provider for responsive theming in react-native

Downloads

3

Readme

react-native-responsive-theme-provider

Dimensions aware styled-components theme provider for responsive theming in react-native

Requirements

  • react
  • react-native
  • styled-components

Features

  • Dimensions aware theme for styled-components
  • Theme will update with new screen and window properties when orientation changes
  • Typescript support

Why?

When building react-native applications there are different orientations and different screen sizes that need to be supported. In order to detect the resolution of the screen, we can use the react native Dimensions API. Using styled-components, it would be easy to do something like this:

import { Dimensions, Text } from 'react-native';
import { ThemeProvider } from 'styled-components/native';

const theme = {
  bigColor: 'blue',
  color: 'red',
  screen: Dimensions.get('screen'),
  window: Dimensions.get('window'),
};

const ThemedText = styled(Text)`
  color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`

const App = () => (
  <ThemeProvider theme={theme}>
    <ThemedText>Some text</ThemedText>
  </ThemeProvider>
);

This is great, but what happens when the user goes from portrait to landscape? Using this code, the screen width will not update to the orientation change.

So the primary goal of this library to provide a theme that will update when the screen orientation changes.

How?

All end-developers need to do is install the library

yarn add @very/react-native-theme-provider
import { Dimensions, Text } from 'react-native';
import ThemeProvider from 'react-native-responsive-theme-provider';

const theme = {
  bigColor: 'blue',
  color: 'red',
};

const ThemedText = styled(Text)`
  color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`

const App = () => (
  <ThemeProvider theme={theme}>
    <ThemedText>Some text</ThemedText>
  </ThemeProvider>
);

Under the hood we are listening for Dimensions changes and updating the theme object with new screen and width properties.

Typescript

import { Text } from 'react-native';
import { ThemedStyledComponentsModule } from 'styled-components';
import styledComponents from 'styled-components/native';
import ThemeProvider, { ThemeDimensionProps } from 'react-native-responsive-theme-provider';

interface ThemeInterface {
  bigColor: string;
  color: string;
}

const { default: styled } = styledComponents as ThemedStyledComponentsModule<
  ThemeInterface & ThemeDimensionProps
>;

const theme: ThemeInterface = {
  bigColor: 'blue',
  color: 'red',
};

// now we have typed support for props.theme
const ThemedText = styled(Text)`
  color: ${(props) => props.theme.screen.width > 800 ? props.theme.bigColor : props.theme.color}
`

const App = () => (
  <ThemeProvider theme={theme}>
    <ThemedText>Some text</ThemedText>
  </ThemeProvider>
);

Selectors

getScreen

alias for props.theme.screen

getScreenWidth

alias for props.theme.screen.width

getWindow

alias from props.theme.window

getWindowWidth

alias from props.theme.window.width

import { Dimensions, Text } from 'react-native';
import ThemeProvider, { getScreenWidth } from 'react-native-responsive-theme-provider';

const theme = {
  bigColor: 'blue',
  color: 'red',
};

const ThemedText = styled(Text)`
  color: ${(props) => getScreenWidth(props) > 800 ? props.theme.bigColor : props.theme.color}
`

const App = () => (
  <ThemeProvider theme={theme}>
    <ThemedText>Some text</ThemedText>
  </ThemeProvider>
);