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-android-drawables

v1.0.1

Published

React Native support for custom Android Drawables

Downloads

11

Readme

What does this module do?

This module provides a simple "toolkit" for injecting named Drawable into the native Android Resources utilised by React Native applications.

This module isn't particularly useful on its own, but can be used in conjunction with other React Native modules or native Android (Java) code bundled in your app.

Usage

Although this library is designed to be used in React Native apps, this project contains native Android (Java) code only, so you won't interact with this library directly from JavaScript.

Typically other node modules will utilise this library and provide JavaScript bindings specific to those modules.

Consequently, the following documents the Java API.

DrawableProvider

A simple interface for providing resource identifiers for names (named drawables), and drawables for resource identifiers.

DrawableStore

A concrete implementation of DrawableProvider. This class allows you to store drawables by name and automatically generates a corresponding resource identifier using DrawableResources.

Its public methods are generally pretty self explanatory in nature:

  • Drawable getDrawable(int id)
  • int getIdentifier(String name)
  • int setDrawable(String name, Drawable drawable)
  • Drawable removeDrawable(String name)

Setting a Drawable using setDrawable(name, drawable) for an already existing name, will result in drawable replacing whatever Drawable was previously set (the corresponding identifier will also be reused).

The int returned from setDrawable(name, drawable) is the automatically generated identifier i.e. the same value returned from getIdentifier(name).

DrawableResources

Provides just the one public (static) method:

  • static int generateId()

generateId() is called by DrawableStore to obtain suitable identifiers. Any additional DrawableProvider implementations should also use this method for generating Drawable resource identifies.

ResourcesWrapper

A simple Resources subclass which takes another Resources and delegates all method calls to it.

DrawableProviderResourcesWrapper

A subclass of ResourcesWrapper which in addition to taking (wrapping) another Resources instance, also takes a DrawableProvider (e.g. DrawableStore) instance.

Instead of simply delegating to the supplied Resources, when a Drawable is involved, this class will first delegate to the DrawableProvider. If the DrawableProvider does not return a value, then the values from the wrapped Resources will be utilised.

The affected methods which try the DrawableProvider before the wrapped Resources are:

  • Drawable getDrawable(int id) throws NotFoundException
  • Drawable getDrawableForDensity(int id, int density) throws NotFoundException
  • int getIdentifier(String name, String defType, String defPackage)