Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@futurejj/react-native-visibility-sensor

JairajJangle29.5kMIT1.3.19TypeScript support: included

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

react-native, ios, android, visibility-sensor, visibility, sensor, visibilitysensor, in-view, inview

readme

@futurejj/react-native-visibility-sensor

🔍 Component visibility sensor wrapper to sense whether or not a component is in viewport with configurable inset thresholds.

npm version License Workflow Status Android iOS Web GitHub issues TS Expo Snack NPM Downloads npm bundle size

Visibility Sensor demo

Installation

Using yarn

yarn add @futurejj/react-native-visibility-sensor

using npm:

npm install @futurejj/react-native-visibility-sensor

Usage

import React from 'react';
import { ScrollView, Text } from 'react-native';
import { VisibilitySensor } from '@futurejj/react-native-visibility-sensor';

export default function VisibilitySensorExample() {
  const [isInView, setIsInView] = React.useState(false);

  function checkVisible(isVisible: boolean) {
    if (isVisible) {
      setIsInView(isVisible);
    } else {
      setIsInView(isVisible);
    }
  }

  return (
    <ScrollView>
      <VisibilitySensor
        onChange={(isVisible) => checkVisible(isVisible)}
        threshold={{
          left: 100,
          right: 100,
        }}
        style={[styles.item, { backgroundColor: isInView ? 'green' : 'red' }]}>
        <Text>This View is currently visible? {isInView ? 'yes' : 'no'}</Text>
      </VisibilitySensor>
    </ScrollView>
  );
}

Properties

VisibilitySensorProps extends ViewProps from React Native, which includes common properties for all views, such as style, onLayout, etc.

Property Type Required Description
onChange (visible: boolean) => void Yes Callback function that fires when visibility changes.
disabled boolean No If true, disables the sensor.
triggerOnce boolean No If true, the sensor will only trigger once.
delay number | undefined No The delay in milliseconds before the sensor triggers.
threshold VisibilitySensorThreshold No Defines the part of the view that must be visible for the sensor to trigger.

Additionally, all properties from ViewProps are also applicable.


VisibilitySensorThreshold

Property Type Required Description
top number No The top threshold value for visibility.
bottom number No The bottom threshold value for visibility.
left number No The left threshold value for visibility.
right number No The right threshold value for visibility.

Notes

  1. ⚠️ Facing problem on Android? Refer this discussion: https://github.com/JairajJangle/react-native-visibility-sensor/pull/1#issuecomment-2251569005

Contributing

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

License

MIT

Support the project

LiberPay_Donation_Button           Paypal_Donation_Button           Paypal_Donation_Button

❤️ Thanks to


changelog

1.3.19 (2025-06-10)

Bug Fixes

1.3.18 (2025-05-13)

Bug Fixes

  • upgrade react-dom from 19.0.0 to 19.1.0 (55cebfe)

1.3.17 (2025-05-13)

Bug Fixes

  • upgrade react from 19.0.0 to 19.1.0 (4a57e4f)

1.3.16 (2025-05-11)

Bug Fixes

  • upgraded example app to expo sdk 53 (6310358)

1.3.15 (2025-04-26)

Bug Fixes

  • incorrect visibility state on initial render - fixes #30 (d60a411), closes #33

1.3.14 (2025-04-14)

Bug Fixes

1.3.13 (2025-04-06)

Bug Fixes

1.3.12 (2025-03-11)

Bug Fixes

  • upgrade expo from 52.0.32 to 52.0.35 (3b93316)

1.3.11 (2025-02-11)

Bug Fixes

  • upgrade expo from 52.0.25 to 52.0.27 (fef8acd)

1.3.10 (2025-02-04)

Bug Fixes

  • upgrade react-native from 0.76.0 to 0.76.6 (e239ae3)

1.3.9 (2025-01-18)

Bug Fixes

  • upgrade expo from 52.0.18 to 52.0.21 (e47a69f)

1.3.8 (2024-12-16)

Bug Fixes

  • upgrade expo from 52.0.7 to 52.0.11 (8336047)

1.3.7 (2024-11-17)

Bug Fixes

  • example/package.json & example/yarn.lock to reduce vulnerabilities (e596d6d)

1.3.6 (2024-11-17)

Bug Fixes

  • example/package.json & example/yarn.lock to reduce vulnerabilities (23d75f6)

1.3.5 (2024-10-22)

Bug Fixes

  • upgrade expo from 51.0.34 to 51.0.35 (5b23e0b)

1.3.4 (2024-09-26)

Bug Fixes

  • upgrade expo from 51.0.31 to 51.0.32 (751ba97)
  • upgrade react-native from 0.75.1 to 0.75.2 (c15f073)

1.3.3 (2024-09-09)

Bug Fixes

  • upgrade react-dom from 18.2.0 to 18.3.1 (8f8f34e)
  • upgrade react-native from 0.74.5 to 0.75.1 (1413631)

1.3.2 (2024-09-08)

Bug Fixes

1.3.1 (2024-09-05)

Bug Fixes

  • upgrade react-dom from 18.2.0 to 18.3.1 (293b129)

1.3.0 (2024-08-27)

Features

1.2.9 (2024-05-11)

Bug Fixes

  • semantic_release: updated gh actions to v4 (33142d2)
  • semantic_release: updated lock files (ca77dfc)

1.2.8 (2024-05-11)

Bug Fixes

  • semantic_release: removed duplicate release config from package json (397f18c)

1.2.7 (2024-05-11)

Bug Fixes

  • semantic_release: release config fix for assets (78fa8ae)

1.2.6 (2024-05-11)

Bug Fixes

  • semantic_release: release config fix for assets (79eb25e)

1.2.5 (2024-05-10)

Bug Fixes

  • semantic_release: added github release config (08b018d)
  • semantic_release: updated lock files (fad6633)

1.2.4 (2024-05-10)

Bug Fixes

  • semantic_release: updated lock files (f55586f)
  • semantic_release: updated lock files (f4ce442)

1.2.3 (2024-05-10)

Bug Fixes

  • semantic_release: updated lock files (e50fcc0)

1.2.2 (2024-05-10)

Bug Fixes

  • semantic_release: added missing semantic release dependencies (0d0e64d)
  • semantic_release: updated node version to satisfy semantic release dep (9805f7b)