react-native-component-inview
v1.0.2
Published
Detect if component is in device viewport
Downloads
27,775
Maintainers
Readme
react-native-component-inview
A React Native wrapper to check whether a component is in the view port to track impressions and clicks
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>