0.3.0 • Published 5 years ago

react-native-reportable v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-native-reportable

Easy to use declarative report for React Native

Installation

$ npm install --save react-native-reportable

Usage

To report things you must use the createReportableComponent or Reportable.create composer. The common components View (includes Container & Visible), ScrollView, FlatList, SectionList, Text and Touchables are precomposed and exposed under the Reportable namespace. If you have your own component that you wish to report, simply wrap it with a Reportable.View or compose it with:

import Reportable from 'react-native-reportable';
MyCustomComponent = Reportable.create(MyCustomComponent);

Declarative Usage

Report Visible

<Reportable.View.Visible style={{height: 100}} report-foo="bar" />

Report Press

<Reportable.Button title="press me" report-foo="bar" />

Properties

Note: Other properties will be passed down to underlying component.

PropDescriptionDefault
onReportVisibleA function that is called when Component is visible. The function is called with a mergedData argument.console.log
onReportPressA function that is called when Component has been pressed. The function is called with a mergedData argument.console.log
onMergeDataA function that get the mergedData, the first argument is parent's mergedData, and the second argument is Component's data obtained by props with a report- prefix .Object.assign
reportWOffsetThe width offset of reportable node.0
reportHOffsetThe width offset of reportable node.0
reportItemKeyThe key of reportable list's reportable item.
report-*The report data prop.

Imperative Usage

Refreshable FlatList

import Reportable from 'react-native-animatable';

const RefreshableFlatList = Reportable.create(FlatList, {
  isListable: true,
  useHooks(node, props) {
    const onRefresh = props.onRefresh
    props.onRefresh = React.useCallback(() => {
      node.refresh()
      return onRefresh && onRefresh()
    }, [onRefresh])
    return props
  },
}),