Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
expo-asset
Advanced tools
The expo-asset package is a library for managing assets in Expo projects. It provides utilities for loading and caching assets such as images, fonts, and other media files, making it easier to handle these resources in a performant way.
Loading Assets
This feature allows you to load assets such as images. The code sample demonstrates how to load an image asset asynchronously and log its local URI once it is loaded.
import { Asset } from 'expo-asset';
async function loadAssets() {
const imageAsset = Asset.fromModule(require('./path/to/image.png'));
await imageAsset.downloadAsync();
console.log('Image loaded:', imageAsset.localUri);
}
Caching Assets
This feature allows you to cache multiple assets. The code sample demonstrates how to cache an array of image assets asynchronously and log a message once all assets are cached.
import { Asset } from 'expo-asset';
async function cacheAssets() {
const assets = [
require('./path/to/image1.png'),
require('./path/to/image2.png')
];
const cachePromises = assets.map(asset => Asset.fromModule(asset).downloadAsync());
await Promise.all(cachePromises);
console.log('All assets cached');
}
Using with Expo's Asset System
This feature demonstrates how to use expo-asset with Expo's AppLoading component to load and cache assets before rendering the main application. The code sample shows how to load an image asset and display a loading screen until the asset is ready.
import { Asset } from 'expo-asset';
import { AppLoading } from 'expo';
export default function App() {
const [isReady, setIsReady] = useState(false);
async function loadResources() {
const imageAsset = Asset.fromModule(require('./path/to/image.png'));
await imageAsset.downloadAsync();
}
if (!isReady) {
return (
<AppLoading
startAsync={loadResources}
onFinish={() => setIsReady(true)}
onError={console.warn}
/>
);
}
return (
<View>
<Text>App is ready!</Text>
</View>
);
}
react-native-fast-image is a performant React Native image component that supports caching and progressive loading. It is similar to expo-asset in terms of caching capabilities but is specifically focused on image handling and provides more advanced features like priority loading and GIF support.
react-native-cached-image is another package for handling image caching in React Native applications. It provides a simple API for caching images and is similar to expo-asset in terms of caching functionality. However, it is more limited in scope as it focuses solely on images.
expo-file-system is a package that provides access to the file system on the device. It can be used to read, write, and manage files, including caching assets. While it offers broader file management capabilities compared to expo-asset, it requires more manual handling of assets.
An Expo universal module to download assets and pass them into other APIs
For managed Expo projects, please follow the installation instructions in the API documentation for the latest stable release. If you follow the link and there is no documentation available then this library is not yet usable within managed projects — it is likely to be included in an upcoming Expo SDK release.
For bare React Native projects, you must ensure that you have installed and configured the expo
package before continuing.
expo install expo-asset
Contributions are very welcome! Please refer to guidelines described in the contributing guide.
FAQs
An Expo universal module to download assets and pass them into other APIs
The npm package expo-asset receives a total of 425,404 weekly downloads. As such, expo-asset popularity was classified as popular.
We found that expo-asset demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.