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-layout-provider

v1.2.1

Published

Getting layout size by top provider instead of Dimensions

Downloads

31

Readme

React Native Layout Provider Build Status

Getting layout size by top provider instead of Dimensions. This is split from react-native-layout-tester's context & getLayout decorator. Inspired by Provider / connect of react-redux.

Why?

Originally react-native-layout-tester have a problem for Dimensions, you can't get a correct layout with Dimensions for each component if you're using LayouTester wrapper, so we made a getLayout decorator to resolve it.

It's mean you must be use getLayout instead of Dimensions for each component, but you can keep the same code in production.

Installation

$ npm install --save react-native-layout-provider

Usage

Use LayoutProvider to wrap your app container:

import React from 'react';
import LayoutProvider from 'react-native-layout-provider';

export default () => (
  <LayoutProvider
    // Default: "Default"
    label={String}

    // Default: provided by Dimensions
    width={Number},
    height={Number},
    // Default: undefined, you can use react-native-orientation to get portrait
    portrait={Boolean}
  >
    <YourApp />
  </LayoutProvider>
);

And use getLayout for each component, the component props will update when LayoutProvider props changed:

import React, { Component, PropTypes } from 'react';
import { getLayout, defaultLayoutTypes } from 'react-native-layout-provider';

class Comp extends Component {

  // It's same with defaultLayoutTypes
  static propTypes = {
    label: PropTypes.string.isRequired,
    viewport: PropTypes.shape({
      width: PropTypes.number.isRequired,
      height: PropTypes.number.isRequired,
    }).isRequired,
    portrait: PropTypes.bool,
  };

  render() {
    return (...);
  }
}

export default getLayout(layout => ({
  label: layout.label,
  viewport: {
    width: layout.viewport.width,
    height: layout.viewport.height,
  },
  portrait: layout.portrait,
}))(Comp);

Or use babel-plugin-transform-decorators-legacy to get @getLayout() work.

Advanced example

Use react-native-orientation to get / listen orientation, and react-native-extra-dimensions-android to resolved status bar problem for Android.

import React, { Component, PropTypes } from "react";
import { Platform, Dimensions } from "react-native";
import LayoutProvider, { getLayout } from 'react-native-layout-provider';
import Orientation from 'react-native-orientation';
import ExtraDimensions from 'react-native-extra-dimensions-android';

let statusBarHeight = 0;
if (Platform.OS === 'android') {
  try {
    statusBarHeight = ExtraDimensions.get('STATUS_BAR_HEIGHT');
  } catch(e) {}
}

class App extends Component {
  state = {
    orientation: Orientation.getInitialOrientation(),
  };

  _orientationDidChange = orientation => {
    this.setState({ orientation });
  };

  componentDidMount() {
    Orientation.addOrientationListener(this._orientationDidChange);
  }

  componentWillUnmount() {
    Orientation.removeOrientationListener(this._orientationDidChange);
  }

  render() {
    const { height } = Dimensions.get('window');
    return (
      <LayoutProvider
        label="Default"
        height={height - statusBarHeight} // Resolved statusBar problem for Android
        portrait={this.state.orientation === 'PORTRAIT'}
      >
        ...
      </LayoutProvider>
    );
  }
}

License

MIT