@hocs/with-view-layout-props

0.2.0 • Public • Published

↔️ 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

Package Sidebar

Install

npm i @hocs/with-view-layout-props

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

7.81 kB

Total Files

4

Last publish

Collaborators

  • hocs