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

rn-style-props

v0.1.3

Published

to get react-native style prop types

Downloads

5

Readme

rn-style-props

This package is intended for React Native apps. It contains the constants and the functions to check the type of style props: layout, transform, shadow, view, text or image.

Constans

  • layoutStyleProps is an array of all style props of layout type
  • transformStyleProps is an array of all style props of transform type
  • shadowStyleProps is an array of all style props of shadow type
  • textStyleProps is an array of all style props of text type
  • imageStyleProps is an array of all style props of image type

Functions

  • isLayoutStyleProp
    It returns true if a style prop is a layout type. The function parameter is the prop name string to check.

  • isTransformStyleProp
    It returns true if a style prop is a transform type. The function parameter is the prop name string to check.

  • isShadowStyleProp
    It returns true if a style prop is a shadow type. The function parameter is the prop name string to check.

  • isViewStyleProp
    It returns true if a style prop is a view type. The function parameter is the prop name string to check.

  • isTextStyleProp
    It returns true if a style prop is a text type. The function parameter is the prop name string to check.

  • isImageStyleProp
    It returns true if a style prop is a image type. The function parameter is the prop name string to check.

  • isViewStyleValidProp
    It returns true if a style prop is valid for View component, that is if its type is layout, transform, shadow or view. The function parameter is the prop name string to check.

  • isTextStyleValidProp
    It returns true if a style prop is valid for Text component, that is if it is valid for View component or its type is text. The function parameter is the prop name string to check.

  • isImageStyleValidProp
    It returns true if a style prop is valid for Image component, that is if it is valid for View component or its type is image. The function parameter is the prop name string to check.

  • extractTextStyle
    If you have an object containing a set of style props for a Text component, this function will separate all style props whose text type. This function returns an object which has three properties:

    • view is an object containing all style props which are valid for View component.
    • text is an object containing all style props whose text type.
    • unknown is an object containing all props excluded from the other properties. For each props included here, a warning message is raised.

    Usage:
    Suppose you create a custom component:

    import React from 'react';
    import {Text, View} from 'react-native';
    import shallowCompare from 'react-addons-shallow-compare';
    import Decorator from './Decorator';
    
    class TextCustom extends React.Component {
      #style = null;
    
      constructor(props) {
          super(props);
          this.#style = extractTextStyle(props.style);
      }
    
      shouldComponentUpdate(nextProps, nextState) {
          if (!Object.is(this.props.style, nextProps.style)) {
              this.#style = extractTextStyle(nextProps.style);
          }
          return shallowCompare(this, nextProps, nextState);
      }
    
      render() {
          return (
              <View style={this.#style.view}>
                  <Decorator />
                  <Text style={this.#style.text}>{this.props.children}</Text>
              </View>
          );
      }
    }

    In the above example, you just need define one prop for style. You don't need two props: the first one is for container View and another one is for contained Text.

    Parameters:

    • style is an object containing the style props to be extracted.
    • paddingForText: if it's true then all padding props will assigned to text property in the returned object. It may be useful if the contained component is TextInput. This parameter has default value, that is false.
  • extractImageStyle
    It's like extractTextStyle but for Image component. The properties of the returned object are view, image and unknown.