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
yarn add react-native-component-inview --save
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>