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

v1.0.0

Published

<p align="center"> <img src="https://user-images.githubusercontent.com/22475804/151048221-3ca00d76-feeb-478f-883a-8b8a6fbce6b4.png" height="200px" /> <h1 align="center">React Native Layout Render</h1> </p>

Downloads

3

Readme

npm-version

Installation

yarn add react-native-layout-render

Quick Start

- Using YAML

import RenderLayout from 'react-native-layout-render';

const yamlRenderExample = `
version: v1
root:
    type: View
    props:
      style:
        flex: 1
        paddingVertical: 100
        alignItems: center
    children:
      - type: Image
        props:
          style:
            width: 150
            aspectRatio: 0.6
          source:
            uri: "https://user-images.githubusercontent.com/22475804/151039878-d38a4131-4242-4a8b-ac11-d687dfd57abf.png"
      - type: Text
        props:
          style:
            fontSize: 20
            textAlign: center
            paddingVertical: 60
            fontWeight: bold
        children: "React Native Layout Render"
      - type: Text
        props:
          style:
            fontSize: 16
            textAlign: center
            padding: 10
            borderWidth: 1
            borderRadius: 10
        children: "yarn add react-native-layout-render"
`;

export default function App() {
    return <RenderLayout yamlText={yamlRenderExample} />;
}

- Using JSON

import RenderLayout from 'react-native-layout-render';

const jsonRenderExample = {
    version: 'v1',
    root: {
        type: 'View',
        props: {
            style: {
                flex: 1,
                paddingVertical: 100,
                alignItems: 'center',
            },
        },
        children: [
            {
                type: 'Image',
                props: {
                    style: {
                        width: 150,
                        aspectRatio: 0.6,
                    },
                    source: {
                        uri: 'https://user-images.githubusercontent.com/22475804/151039878-d38a4131-4242-4a8b-ac11-d687dfd57abf.png',
                    },
                },
            },
            {
                type: 'Text',
                props: {
                    style: {
                        fontSize: 20,
                        textAlign: 'center',
                        paddingVertical: 60,
                        fontWeight: 'bold',
                    },
                },
                children: 'React Native Layout Render',
            },
            {
                type: 'Text',
                props: {
                    style: {
                        fontSize: 16,
                        textAlign: 'center',
                        padding: 10,
                        borderWidth: 1,
                        borderRadius: 10,
                    },
                },
                children: 'yarn add react-native-layout-render',
            },
        ],
    },
};

export default function App() {
    return <RenderLayout jsonText={JSON.stringify(jsonRenderExample)} />;
}

- Result in the APP


Custom elements

- Create Image with auto height

import React, {useEffect, useState} from 'react';
import {Image} from 'react-native';
import {ICustomElementProps} from 'react-native-layout-render';

export default function ImageAutoHeight({props}: ICustomElementProps) {
    const [aspectRatio, setAspectRatio] = useState<number | undefined>();

    useEffect(() => {
        if (!props?.url) {
            return;
        }
        Image.prefetch(props.url)
            .then(() => {
                Image.getSize(props.url, (width, height) => {
                    const aspect = Math.round((width / height) * 100) / 100;
                    setAspectRatio(aspect);
                });
            })
            .catch(() => {});
    }, [props]);

    return <Image source={{uri: props.url}} {...props} style={[props?.style, {aspectRatio}]} />;
}

- Create Button Link to other apps or websites

import React from 'react';
import { Linking, TouchableOpacity } from 'react-native';
import { ICustomElementProps } from 'react-native-layout-render';

export default function Link({ props, children }: ICustomElementProps) {
    return (
        <TouchableOpacity {...props} onPress={() => goLink(props?.url)}>
            {children}
        </TouchableOpacity>
    );
}

async function goLink(url?: string) {
    if (url && typeof url === 'string') {
        const supported = await Linking.canOpenURL(url);
        if (supported) {
            await Linking.openURL(url);
        }
    }
}

- Using custom elements

import RenderLayout, { setCustomElements } from 'react-native-layout-render';

import Link from './Link';
import ImageAutoHeight from './ImageAutoHeight';

setCustomElements({
    Link: (props, children) => Link({ props, children }),
    ImageAutoHeight: (props) => ImageAutoHeight({ props }),
});

const yamlRenderExample = `
version: v1
root:
    type: View
    props:
      style:
        flex: 1
        paddingVertical: 100
        alignItems: center
    children:
...
      - type: Link
        props:
          style:
            marginTop: 50
            padding: 10
            backgroundColor: "#F5F5F5"
            alignItems: center
            justifyContent: center
            borderRadius: 10
          url: "https://www.youtube.com"
        children:
          - type: Text
            props:
            style:
                fontSize: 20
                textAlign: center
                padding: 10
                borderWidth: 1
                borderRadius: 10
            children: "Open Youtube"
          - type: ImageAutoHeight
            props:
              style:
                marginTop: 15
                width: 180
              url: "https://user-images.githubusercontent.com/22475804/151046905-974b1029-1a4a-4264-a3b8-efa017e61cbb.png"
`;

export default function App() {
    return <RenderLayout yamlText={yamlRenderExample} />;
}

- Result custom elements in the APP