1.2.9 • Published 1 month ago

@futurejj/react-native-visibility-sensor v1.2.9

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@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 Supported Platform Badge GitHub issues TS

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.

PropertyTypeRequiredDescription
onChange(visible: boolean) => voidYesCallback function that fires when visibility changes.
disabledbooleanNoIf true, disables the sensor.
triggerOncebooleanNoIf true, the sensor will only trigger once.
delaynumber | undefinedNoThe delay in milliseconds before the sensor triggers.
thresholdVisibilitySensorThresholdNoDefines the part of the view that must be visible for the sensor to trigger.

Additionally, all properties from ViewProps are also applicable.


VisibilitySensorThreshold

PropertyTypeRequiredDescription
topnumberNoThe top threshold value for visibility.
bottomnumberNoThe bottom threshold value for visibility.
leftnumberNoThe left threshold value for visibility.
rightnumberNoThe right threshold value for visibility.

Contributing

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

License

MIT

Support the project

❤️ Thanks to


1.2.8

1 month ago

1.2.7

1 month ago

1.2.6

1 month ago

1.2.9

1 month ago

1.2.0

1 month ago

1.2.5

1 month ago

1.2.4

1 month ago

1.2.3

1 month ago

1.2.2

1 month ago

1.2.1

1 month ago

1.1.0

1 month ago

0.2.0

1 month ago