JSPM

react-native-component-inview

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3131
  • Score
    100M100P100Q124008F
  • License MIT

Detect if component is in device viewport

Package Exports

  • react-native-component-inview

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-component-inview) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-native-component-inview

A React Native wrapper to check whether a component is in the view port to track impressions and clicks

demo

Installation

npm i --save react-native-component-inview # npm syntax
yarn add react-native-component-inview --save # yarn syntax

Example

import InView from 'react-native-component-inview'

const [isInView, setIsInView] = useState(false)

const checkVisible = (isVisible:boolean) => {
    if (isVisible){
      setIsInView(isVisible)
    } else {
      setIsInView(isVisible)
    }
  }

<ScrollView>
  <InView onChange={(isVisible) => this.checkVisible(isVisible)}>
    <View style={[styles.item, {backgroundColor: isInView ? 'yellow' : '#f9c2ff'}]}>
      <Text>yay</Text>
    </View>
  </InView>
</ScrollView>