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-appear-observer

v2.1.1

Published

Utility to check React Native node visibility on the screen.

Downloads

999

Readme

A React Native library to detect element appearance on the screen

Version 2.1.0 bumps React Native version to 0.72.5. Version 2.0.3 updates minor dependency versions.

Version 2.0 considers the mistakes of first version and expands functionality, briefly it:

  • has updated appear observer hook cycle logic
  • adds support for enabling, disabling and reseting observer (can be used with react navigation)
  • adds full support for usage without provider
  • adds support for render props children to provider
  • adds support of callbacks to provider, adds onScroll as interaction handler
  • adds a utility hook for adding necessary fixes to elements to work on android, incorporates it in observer and provider hooks
  • adds support for usage without parent, relying on window boundaries (provided offsets considered)
  • adds support of settings parent offsets (for cases of floating element above parent)
  • drops reqirement of explicit refs
  • memoizes the configurations properly so that simple non memoized objects can be used
  • changes intersection detection algorithm, incorrect visibility threshold is fixed
  • drops support for useIsAppeared (so far)

Proper documentation will be added later!

Wrap the parent component with provider and supply it with parent view ref.

const App = () => {
  return (
    <AppearObserverProvider>
      <ScrollView>{/* content */}</ScrollView>
    </AppearObserverProvider>
  )
}

Or use useAppearObserver hook if you want to attach callback to visibility change without changing state.

const TestView = ({ onAppear, onDisappear }: any) => {
  const { refProps } = useAppearObserver({
    elementRef,
    onAppear,
    onDisappear
  })

  return <View {...refProps} style={elementStyle} />
}

Usage with react navigation

const TestView = ({ onAppear, onDisappear }: any) => {
  const isFocused = useIsFocused()

  const { refProps } = useAppearObserver({
    enabled: isFocused,
    onAppear,
    onDisappear,
    onDisable: onDisappear // Optional
  })

  return <View {...refProps} style={elementStyle} />
}

useAppearObserver

| Option | Description | Default value | | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------- | | visibilityThreshold | Defines what part of an element should be visible for it to trigger callback, from 0 to 1. | 0 | | intervalDelay | Determines a delay in milliseconds between visibility check repetitions. | 100 | | recalculateParentBoundaries | Tells whether observer should measure parent element boundaries on every on every check or measure once and cache. | false |

useAppearObserverProvider

| Option | Description | Default value | | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | | enableInteractionMode | If true, the touch handlers are attached to child view of context provider and observer runs checks only upon interactions, which could affect element visibility - touch move or scroll, stopping them on after a period of inactivity. If false, checks will run permanently. | true |

  • Observing stops in horizontal lists on Android if provider is attached to parent vertical scroll view and scrolling is performed by holding screen with one finger and moving with another.