@se09deluca/react-native-component-inview
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

@se09deluca/react-native-component-inview

A React Native wrapper to check whether a component is in the viewport. Useful to track impressions, clicks or implements custom logic.

It works on Android, iOS & Web .

Installation

using npm

npm install @se09deluca/react-native-component-inview

using Yarn

yarn add @se09deluca/react-native-component-inview

Usage

import InView from '@se09deluca/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>This View is currently visible? {isInView ? 'yes': 'no'}</Text>
    </View>
  </InView>
</ScrollView>

// ...

Demo

demo

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

/@se09deluca/react-native-component-inview/

    Package Sidebar

    Install

    npm i @se09deluca/react-native-component-inview

    Weekly Downloads

    3

    Version

    0.1.4

    License

    MIT

    Unpacked Size

    26.8 kB

    Total Files

    10

    Last publish

    Collaborators

    • se09deluca