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-resource-saving-container

v1.0.2

Published

View container that saves resources (bitmaps, camera) by detaching native views when they are not visible

Downloads

8

Readme

react-native-resource-saving-container

This is a very tiny React Native component that allows for saving memory by releasing resources attached to views that may are not visible on screen.

How it works?

When native views are rendered in your React Native app, the framework creates corresponding native views and mounts them in view hierarchy. Native views provides the platform with a way how they should be rendered on screen, but a part of that they can also consume memory. For example Image component keeps a reference to a bitmap that it needs to rende, Camera component keeps the camera session active which results in increased power consumption used by camera hardware and processor unit as well as memoty consumption used for buffering. When such a views are rendered but not visible on a screen (perhaps they are few levels down navigation hierarchy) they can still take up resources they need for rendering.

ResourceSavingContainer allows for such a components to release their resources using technique that has been in React Native forever -- removeClippedSubviews property. This property allows for components rendered in javascript to be instantiated in native but detached from the native view hierarchy when outside of their parent's visible bounds.

How to use it

Use <ResourceSavingContainer/> as a container in which you want to put resource intensive components (e.g. images, or even whole screens from navigation stack). When your components are not expected to be visible (e.g. they have been covered by other navigation card) set visible={false} to detach all children from native view hierarchy.

First import <ResourceSavingContainer/> component like this:

import ResourceSavingContainer from 'react-native-resource-saving-container';

Then use it in your render method:

    <ResourceSavingContainer
        style={{ backgroundColor: '#fcfcfc' }}
        visible={this.state.visible}>
        <Image source={require('./largeImageBackground.jpg')} />
    </ResourceSavingContainer>

Caveats

<ResourceSavingContainer/> uses relative positioning to move its childrent outside of the visible bounds therefore children rendered directly under ResourceSavingContainer should not use absolute positioning. If you need absolute positioning you can render relatively positioned <View/> inside <ResourceSavingContainer/> and then use absolute positioning inside of that <View/>.

Troubleshooting

Try searching over the issues on GitHub here. If you don't find anything that would help feel free to open a new issue!

You could also just read the source code - it only has a few lines.