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-ui

v2.1.5

Published

Responsive UIs for React Native

Downloads

5,478

Readme

React Native Reponsive UI

CircleCI npm version

Building responsive UIs in React Native.

example

An example is available via expo here.

Installation

npm install react-native-responsive-ui --save

Usage

The MediaQuery component renders its children only if the query evaluates to true (see list of properties below). This component listens to changes in the window dimensions. In the example below, we render the Logo component if the window's height has a minimum size of 450dp and if the device orientation is in portrait mode (height is larger than width).

Media Queries

// @flow
import React, {Component} from "react";
import {View} from "react-native";
import {MediaQuery} from "react-native-responsive-ui";

export default class Login extends Component {
    render(): React$Element<*> {
        return <View>
            <MediaQuery minHeight={450} orientation="portrait">
                <Logo />
            </MediaQuery>
        </View>;
    }
}

Properties

| Name | Type | Description | |----------------|--------|--------------------------------------------------------------------------------------| | minHeight | dp | Minimum height of the window. | | maxHeight | dp | Maximum height of the window. | | minWidth | dp | Minimum width of the window. | | maxWidth | dp | Maximum width of the window. | | minAspectRatio | number | Minimum aspect ration of the window (ratio of horizontal pixels to vertical pixels). | | maxAspectRatio | number | Maximum aspect ration of the window (ratio of horizontal pixels to vertical pixels). | | minPixelRatio | number | Minimum device pixel density. See PixelRatio. | | maxPixelRatio | number | Maximum device pixel density. See PixelRatio. | | orientation | portrait or landspace | Indicates whether the viewport is in landscape (the display is wider than it is tall) or portrait (the display is square or taller than it is wide) mode. | | platform | string | Platform of the device. See Platform. | | condition | boolean | Abritrary boolean value that must be true for the media query to pass. |

useDimensions

import React from "react";
import {useDimensions} from "react-native-responsive-ui";

export default ({ children }) =>  {
  const {width, height} = useDimensions();
  console.log(`New window dimensions: ${width}x${height}`);
  return children;
};

useStylesheet

import React from "react";
import {useStylesheet} from "react-native-responsive-ui";

export default class Buttons extends ResponsiveComponent {
    render() {
        const style = useStylesheet(staticStyle)
        return <View style={style.btns}>
            <Button label="Login" primary style={style.btn} />
            <Button label="Sign Up" style={style.btn} />
        </View>;
    }
}

const staticStyle = [
  {
      query: { orientation: "landscape" },
      style: {
          btns: {
              flexDirection: "row"
          },
          btn: {
              flex: 1
          }
      }
  },
  {
      query: { orientation: "portrait" },
      style: {
          btns: {
              alignSelf: "stretch"
          },
          btn: {
              flex: 0
          }
      }
  }
];

Media Query

mediaQuery() evaluates a media query and return true or false. See example below.

import {mediaQuery, useDimensions} from "react-native-responsive-ui";

const {width, height} = useDimensions();
mediaQuery({ orientation: "portrait", minHeight: 450 }, width, height)

ResponsiveComponent

ResponsiveComponents extends React.Component and add the window dimensions to the state of the component.

import React from "react";
import {ResponsiveComponent} from "react-native-responsive-ui";

export default class Debug extends ResponsiveComponent {
    render() {
        const {width, height} = this.state.window;
        console.log(`New window dimensions: ${width}x${height}`);
        return null;
    }
}

getStylesheet

import React from "react";
import {ResponsiveComponent, getStylesheet} from "react-native-responsive-ui";

export default class Debug extends ResponsiveComponent {
    render() {
        const {width, height} = this.state.window;
        const styles = [
            {
                query: { minHeight: 500 },
                style: { container: { backgroundColor: "red" } }
            }
        ];
        const style = getStylesheet({width, height}, styles)
        return <View style={style.container} />
    }
}