Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Latest commit

 

History

History

with-view-layout-props

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

↔️ with-view-layout-props

npm ci coverage deps

Part of a collection of Higher-Order Components for React, especially useful with Recompose.

Dynamically map View layout dimensions to props using onLayout() handler.

Install

yarn add @hocs/with-view-layout-props

Usage

withResizeObserverProps(
  mapStateToProps: (layoutDimensions: Object) => Object
  handlerName?: string
): HigherOrderComponent

Where:

  • layoutDimensions{ width, height, x, y }
  • handlerName – in some cases you might want to change it. 'onlayout' by default.
import React from 'react';
import { View } from 'react-native';
import withViewLayoutProps from '@hocs/with-view-layout-props';

const Demo = ({ width, height, x, y, onLayout, ...props }) => (
  <View onLayout={onLayout} {...props}>
    { JSON.stringify({ width, height, x, y }) }
  </View>
);

export default withViewLayoutProps(
  ({ width, height, x, y }) => ({ width, height, x, y })
)(Demo);

Related