npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-viewability-tracking-view

v1.0.0

Published

A React Native View that provides similar viewability tracking as the FlatList, but better™

Downloads

23

Readme

react-native-viewability-tracking-view

Note: This tracking uses setInterval and the native measure method, which can affect your application's performance if used excessively

If you need to track how many times a View is visible on the screen, you can use this. It provides options for setting offsets (offset*), in case part of your screen is covered by fixed elements, e.g. a tab bar.

Also, you can configure what is considered enough to be "seen". By default, onViewabilityChange will be called when at least 50% (itemVisiblePercentThreshold) of the ViewabilityTrackingView has been rendered within the device's screen dimensions for at least 1000 ms (minimumViewTime).

Lastly, you can define how often the measurement is taken, which affects the accuracy of the tracking and the performance impact it has (viewabilityMeasurementInterval).

Example

import ViewabilityTrackingView, {
  OnViewabilityParameters,
} from 'react-native-viewability-tracking-view'

export const MyComponent = ({
  isCurrentRoute,
  title,
}: {
  isCurrentRoute: boolean
  title: string
}) => {
  const onViewabilityChange = (data: OnViewabilityParameters) => {
    /* do something */
  }

  return (
    <ViewabilityTrackingView
      enabled={isCurrentRoute} // to only track when relevant
      accessibilityLabel={`Advertising banner ${title}`}
      onViewabilityChange={onViewabilityChange}
      testID="ViewabilityTrackingView"
      // check docs below for all props
    >
      <Text>{title}</Text>
    </ViewabilityTrackingView>
  )
}

Props

export interface OnViewabilityCallbackParameters<
  Item extends Record<string, unknown> = Record<string, never>
> {
  isInView: boolean
  item?: Item
  itemVisiblePercent: number
  testID?: string
  timeInView?: number
  timeOutOfView?: number
}

export interface ViewabilityTrackingViewProps<
  Item extends Record<string, unknown> = Record<string, never>
> extends ViewProps {
  /**
   * DEV ONLY: Set to true to get console.logs of the viewability, each time it's measured.
   *
   * @type {boolean}
   * @memberof ViewabilityTrackingViewProps
   */
  __DEV__debug?: boolean

  children?: React.ReactNode

  /**
   * Requiring explicit opt-in to the tracking. This is to remind consumers that viewability tracking
   * might affect performance, so ideally it should only be enabled when there is a chance that the
   * content will come into view.
   *
   * @type {boolean}
   * @memberof ViewabilityTrackingViewProps
   */
  enabled: boolean

  /**
   * Minimum percent of pixels that need to be viewable for item to be considered in view. Defaults to 50.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  itemVisiblePercentThreshold?: number

  /**
   * Item is optional, but passed into the onViewability* callbacks.
   *
   * @type {OnMeasureParameters['item']}
   * @memberof ViewabilityTrackingViewProps
   */
  item?: Item

  /**
   * Minimum view time, in milliseconds, required to trigger onViewabilityChange. Defaults to 1000.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  minimumViewTime?: number

  /**
   * Use offsetBottom to set that amount of pixels as not viewable, e.g. if there is a fixed bottom
   * bar that content can be scrolled behind, while still within the window of the device.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  offsetBottom?: number

  /**
   * Use offsetLeft to set that amount of pixels as not viewable, e.g. if there is a fixed sidebar
   * that content can be scrolled behind, while still within the window of the device.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  offsetLeft?: number

  /**
   * Use offsetRight to set that amount of pixels as not viewable, e.g. if there is a fixed sidebar
   * that content can be scrolled behind, while still within the window of the device.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  offsetRight?: number

  /**
   * Use offsetTop to set that amount of pixels as not viewable, e.g. if there is a fixed header
   * that content can be scrolled behind, while still within the window of the device.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  offsetTop?: number

  /**
   * Called when the itemVisiblePercentThreshold and the minimumViewTime is met for the first time
   * since coming into view and when going out of view after having been in view. In the latter case
   * it does not matter for how long it had been in view before going out of view.
   *
   * @memberof ViewabilityTrackingViewProps
   */
  onViewabilityChange?: (params: OnViewabilityCallbackParameters) => void

  /**
   * Called on every viewability measurement, which is done at the viewabilityMeasurementInterval.
   *
   * @memberof ViewabilityTrackingViewProps
   */
  onViewabilityCheck?: (params: OnViewabilityCallbackParameters) => void

  testID?: string

  /**
   * Time between viewability measurements, in milliseconds. Defaults to 200.
   *
   * @type {number}
   * @memberof ViewabilityTrackingViewProps
   */
  viewabilityMeasurementInterval?: number
}