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

@herberthtk/react-native-viewport

v0.1.11

Published

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

Downloads

486

Readme

react-native-viewport

Build StatusMIT LicenseSupports AndroidSupports iOSnpm versionnpm

This is a fully customizable, TypeScript-based React Native component that lets you effortlessly monitor when any component enters or exits the viewport. Perfect for tracking impressions and creating engaging, data-driven experiences, this tool triggers a callback whenever visibility changes, enabling precise in-view tracking. Whether you’re building analytics features, enhancing user experience, or managing dynamic content, this package offers a streamlined, reliable way to detect visibility in scrollable views.

Demos

1. Track if the view container is 100% visible on the screen

100% view

2. Set a custom minimum value to Track and trigger visible if the view container is visible on the screen (For this case, the minimum value 70% to trigger isVisibility)

70% view

Why choose this package

There many react-native viewport packages on npm but some of them are no longer actively maintained by their authors, doesn't support Typescript, and most importantly none of them support custom threshold for minimum percentage of the view to be considered visible.

Since I failed to get a package that fulfils the video requirements of my client's application, I decided to write it myself and we are happy with the results

Installation

    npm i @herberthtk/react-native-viewport

Or

    yarn add @herberthtk/react-native-viewport

Usage

import InViewport from '@herberthtk/react-native-viewport';

 const Section = () => {
  const [focused, setFocused] = useState(false);

  const handleChange = useCallback((isVisible: boolean) => {
    setFocused(isVisible);
  }, []);

  const backgroundColor = focused ? 'red' : '#ccc';

  return (
    <InViewport
      threshold={0.7} // This component will be considered visible if it is 70% visible (Default is 1 that means 100%)  
      delay={100} // This component will check if it is visible every 200ms (default is 1000ms or 1 second) )
      onChange={handleChange}
      style={[styles.section, { backgroundColor }]}
    >
      <Text style={focused ? { color: '#fff' } : { color: '#000' }}>
        {focused ? 'Focused' : 'Not focused'}
      </Text>
    </InViewport>
  );
};

const App = (): React.JSX.Element => {
  return (
    <SafeAreaView style={styles.container}>
      <ScrollView>
        {[...new Array(5)].map((_, k) => (
          <Section key={k} />
        ))}
      </ScrollView>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  section: {
    width: Dimensions.get('screen').width,
    height: Dimensions.get('screen').height,
    justifyContent: 'center',
    alignItems: 'center',
    borderBottomColor: 'blue',
    borderBottomWidth: 4,
  },
});

export default App;

Component props

| Property | type | Required | Description | Default value | | ---------| ------- | ------- | -------- | -------- | | disabled | boolean | false | If enabled the component will not track visibility status | false | | delay | number | false | How frequent to check visibility status. Not setting lower less than a second will increase frequency of updates leading performance issues especially in old architecture bridge mode | 1000ms | | threshold | number | false | A fraction (0 to 1) that is greater than 0 but less or equal to 1, 1 means 100% 0.7 means 70% and so on, The value indicate the minimum percentage of the container to be considered visible | 1 | | onChange | Function | true | This is the core and exposed method that listens and updates visibility status | undefined |

This component also accepts all properties of the View component like style Check full list of properties here

Contributing

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

License

MIT


Made with Herbert kavuma