0.0.9 • Published 4 years ago

react-native-layout-components v0.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

React Native Layout Components

React Native Layout Components (RNLC) is a simple component library to help with responsive user interfaces. This component library contains several hooks aswell.

This library is greatly inspired by Material-UI.

API

Breakpoints

Breakpoints are predetermined widths within the window to describe the size of the window. Using breakpoints can make it easier to create a more responsive ui.

SizeStringPixel SizeTypical Device
Extra Small'xs'0-599 pxSmall Handset
Small'sm'600-959 pxTablets in portrait
Medium'md'960-1279 pxTablets in Landscape
Large'lg'1280-1919 pxLaptops
Extra Large'xl'1920+ pxLarge screen monitors

For more information about breakpoints specifications visit Material.io

Breakpoint Ranges

A Breakpoint Range establishes if a range of breakpoints are being used within a specific direction (up or down). The breakpoint is determined by a starting size and then all sizes either larger than that size (up) or smaller (down).

Examples of Breakpoint Range • 'mdDown' would be true if the size of the window's width is ('md') 1279 px or ('sm', 'xs') less. Sizes ('lg', 'xl') 1280px + would be false • 'smUp' would be true if the size of the window's width is ('sm') 600 px or ('md', 'lg', 'xl') more. The size ('xs') 599px - would be false.

Components

Absolute

An Absolute component is a that's position is set to 'absolute'.

PropDefaultTypeDescription
bottomNumberThe value of pixels from the bottom of the absolute component to the bottom of the parent component.
childrennode
leftNumberThe value of pixels from the left of the absolute component to the left of the parent component.
rightNumberThe value of pixels from the right of the absolute component to the right of the parent component.
topNumberThe value of pixels from the top of the absolute component to the top of the parent component.

Center

A Center component will stretch itself from one end of the parent component to the other end, and will place the children within the center of itself.

PropDefaultTypeDescription
childrennode

Column

Column component will place the children in a vertical relative position. From top to bottom.

PropDefaultTypeDescription
align'flex-start''flex-start', 'center', 'flex-end', 'stretch'alignItems
childrennode
justify'flex-start''flex-start', 'flex-end', 'center', 'stretch', 'space-between', 'space-around'justifyContent

Container

Container adjusts to match the size of the parent component. When the container is set to fixed it will match up to the largest possible breakpoint that will fit within the parent component. It's suggested not to place scrollviews or lists within a container, but to place the container within scrollviews.

PropDefaultTypeDescription
childrennode
fixedfalsebool
maxWidth'lg''xs', 'sm', 'md', 'lg', 'xl'The max width of the container to match the breakpoint

Expander

The Expander expands from the row/column to force the next component to trail to the end.

PropDefaultTypeDescription
childrennode

Hidden

The Hidden component will hide based on the size of the app's window width.

PropDefaultTypeDescription
childrennode
xsDownfalseboolHides on window sizes 599 px and less.
xsUpfalseboolHides on window sizes 0 px and more.
smDownfalseboolHides on window sizes 959 px and less.
smUpfalseboolHides on window sizes 600 px and more.
mdDownfalseboolHides on window sizes 1279 px and less.
mdUpfalseboolHides on window sizes 960 px and more.
lgDownfalseboolHides on window sizes 1919 px and less.
lgUpfalseboolHides on window sizes 1280 px and more.
xlDownfalseboolHides on window sizes xl and less.
xlUpfalseboolHides on window sizes 1920 and more.
<Hidden smDown>
    <Text>I am Hidden if the window size is sm or less</Text>
</Hidden>
<Hidden mdUp>
    <Text>I am Hidden if the window size is md or more</Text>
</Hidden>

Row

A Row component will place the children in a horizontal relative position. From left to right.

PropDefaultTypeDescription
align'center''flex-start', 'center', 'flex-end', 'stretch'alignItems
childrennode
justify'flex-start''flex-start', 'flex-end', 'center', 'stretch', 'space-between', 'space-around'justifyContent

Hooks

NameArgumentsReturns
useBreakpointsxs: bool, sm: bool, md: bool, lg: bool, xl: bool, xsDown: bool, xsUp: bool, smDown: bool, smUp: bool, mdDown: bool, mdUp: bool, lgDown: bool, lgUp: bool, xlDown: bool, xlUp: bool, isHidden(breakpointRange: Breakpoint Range): bool

useBreakpoints

import { useBreakpoints } from 'react-native-layout-components'

const breakpoints = useBreakpoints()

console.log('is window small: ' + breakpoints.sm )
console.log('isHidden: ' + breakpoints.isHidden('smDown'))
0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago