All Projects β†’ mrousavy β†’ React Native Blurhash

mrousavy / React Native Blurhash

Licence: mit
πŸ–ΌοΈ A library to show colorful blurry placeholders while your content loads.

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects
swift
15916 projects
kotlin
9241 projects

Projects that are alternatives of or similar to React Native Blurhash

Vue Content Loading
Vue component to easily build (or use presets) SVG loading cards Facebook like.
Stars: ✭ 729 (+69.53%)
Mutual labels:  ux, loading, placeholder
React Cool Img
😎 🏞 A React <Img /> component let you handle image UX and performance as a Pro!
Stars: ✭ 356 (-17.21%)
Mutual labels:  ux, component, placeholder
Imageviewer.swift
An easy to use Image Viewer that is inspired by Facebook
Stars: ✭ 1,071 (+149.07%)
Mutual labels:  library, image, ux
Vue Content Loader
SVG component to create placeholder loading, like Facebook cards loading.
Stars: ✭ 2,790 (+548.84%)
Mutual labels:  component, loading, placeholder
Geotic
Entity Component System library for javascript
Stars: ✭ 97 (-77.44%)
Mutual labels:  library, npm, component
Croppr.js
A vanilla JavaScript image cropper that's lightweight, awesome, and has absolutely zero dependencies.
Stars: ✭ 294 (-31.63%)
Mutual labels:  image, component
Paper Onboarding
PaperOnboarding is a material design UI slider. Swift UI library by @Ramotion
Stars: ✭ 3,147 (+631.86%)
Mutual labels:  library, component
Klib
A standalone and lightweight C library
Stars: ✭ 3,442 (+700.47%)
Mutual labels:  algorithm, library
Kiimagepager
The KIImagePager is inspired by foursquare's ImageSlideshow, the user may scroll through images loaded from the Web
Stars: ✭ 324 (-24.65%)
Mutual labels:  library, image
Tooltip Sequence
A simple step by step tooltip helper for any site
Stars: ✭ 287 (-33.26%)
Mutual labels:  npm, ux
Circle Menu
⭕️ CircleMenu is a simple, elegant UI menu with a circular layout and material design animations. Swift UI library made by @Ramotion
Stars: ✭ 3,306 (+668.84%)
Mutual labels:  library, component
Npm Gif
Replace NPM install's progress bar with a GIF!
Stars: ✭ 332 (-22.79%)
Mutual labels:  image, npm
Length.js
πŸ“ JavaScript library for length units conversion.
Stars: ✭ 292 (-32.09%)
Mutual labels:  library, npm
Sqip
"SQIP" (pronounced \skwΙͺb\ like the non-magical folk of magical descent) is a SVG-based LQIP technique.
Stars: ✭ 3,074 (+614.88%)
Mutual labels:  image, placeholder
React Magic Hat
🎩✨Library to implement the Magic Hat technique, blazingly fast πŸš€
Stars: ✭ 297 (-30.93%)
Mutual labels:  library, ux
React Spectrum
Generate colorful text placeholders 🎨
Stars: ✭ 289 (-32.79%)
Mutual labels:  library, placeholder
React Component Library
A project skeleton to get your very own React Component Library up and running using Rollup, Typescript, SASS + Storybook
Stars: ✭ 313 (-27.21%)
Mutual labels:  library, component
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (-21.16%)
Mutual labels:  algorithm, library
Picassopalette
Android Lollipop Palette is now easy to use with Picasso !
Stars: ✭ 366 (-14.88%)
Mutual labels:  image, loading
Materialimageloading
Material image loading implementation
Stars: ✭ 396 (-7.91%)
Mutual labels:  image, loading

Blurhash

πŸ–ΌοΈ Give your users the loading experience they want.

Install via npm:

npm i react-native-blurhash
npx pod-install

Buy Me a Coffee at ko-fi.com

npm npm

GitHub followers Twitter Follow

BlurHash is a compact representation of a placeholder for an image. Instead of displaying boring grey little boxes while your image loads, show a blurred preview until the full image has been loaded.

The algorithm was created by woltapp/blurhash, which also includes an algorithm explanation.

Turn grey image boxes into colorful blurred images

Example Workflow

    In order to use the Blurhash component, you have to already have a Blurhash string. See the blurha.sh page to create example strings.

    This is how I use it in my project:

  1. A user creates a post by calling a function on my server which expects a payload of an image and some post data (title, description, ...)
  2. The function on my server then
    1. generates a blurhash from the image in the payload using the C encoder
    2. stores the post data (including the generated blurhash string) in my database
    3. uploads the image to a content delivery network (e.g. AWS)
  3. Now everytime a user loads a feed of posts from my database, I can immediately show a <Blurhash> component (with the post's .blurhash property) over my <Image> component, and fade it out once the <Image> component's onLoadEnd function has been called.

  4. Note: You can also use the react-native-blurhash encoder to encode straight from your React Native App!

Usage

The <Blurhash> component has the following properties:

Name Type Explanation Required Default Value
blurhash string The blurhash string to use. Example: LGFFaXYk^6#[email protected],[email protected][or[Q6. βœ… undefined
decodeWidth number The width (resolution) to decode to. Higher values decrease performance, use 16 for large lists, otherwise you can increase it to 32.
See: performance
❌ 32
decodeHeight number The height (resolution) to decode to. Higher values decrease performance, use 16 for large lists, otherwise you can increase it to 32.
See: performance
❌ 32
decodePunch number Adjusts the contrast of the output image. Tweak it if you want a different look for your placeholders. ❌ 1.0
decodeAsync boolean Asynchronously decode the Blurhash on a background Thread instead of the UI-Thread.
See: Asynchronous Decoding
❌ false
resizeMode 'cover' | 'contain' | 'stretch' | 'center' Sets the resize mode of the image. (no, 'repeat' is not supported.)
See: Image::resizeMode
❌ 'cover'
onLoadStart () => void A callback to call when the Blurhash started to decode the given blurhash string. ❌ undefined
onLoadEnd () => void A callback to call when the Blurhash successfully decoded the given blurhash string and rendered the image to the <Blurhash> view. ❌ undefined
onLoadError (message?: string) => void A callback to call when the Blurhash failed to load. Use the message parameter to get the error message. ❌ undefined
All View props ViewProps All properties from the React Native View. Use style.width and style.height for display-sizes. Also, style.borderRadius is natively supported on iOS. ❌ {}

Example Usage:

import { Blurhash } from 'react-native-blurhash';

export default function App() {
  return (
    <Blurhash
      blurhash="LGFFaXYk^6#[email protected],[email protected][or[Q6."
      style={{flex: 1}}
    />
  );
}

See the example App for a full code example.

iOS Screenshot Android Screenshot
iOS Demo Screenshot Android Demo Screenshot

Average Color

If your app is really colorful you might want to match some containers' colors to the content's context. To achieve this, use the getAverageColor function to get an RGB value which represents the average color of the given Blurhash:

const averageColor = Blurhash.getAverageColor('LGFFaXYk^6#[email protected],[email protected][or[Q6.')

Encoding

This library also includes a native Image encoder, so you can encode Images to blurhashes straight out of your React Native App!

const blurhash = await Blurhash.encode('https://blurha.sh/assets/images/img2.jpg', 4, 3)

Because encoding an Image is a pretty heavy task, this function is non-blocking and runs on a separate background Thread.

Validation

If you need to validate a blurhash string, you can use isValidBlurhash.

const result = Blurhash.isValidBlurhash('LGFFaXYk^6#[email protected],[email protected][or[Q6.')
if (result.isValid) {
  console.log(`Blurhash is valid!`)
} else {
  console.log(`Blurhash is invalid! ${result.reason}`)
}

Performance

The performance of the decoders is really fast, which means you should be able to use them in collections quite easily. By increasing the decodeWidth and decodeHeight props, the time to decode also increases. I'd recommend values of 16 for large lists, and 32 otherwise. Play around with the values but keep in mind that you probably won't see a difference when increasing it to anything above 32.

Asynchronous Decoding

Use decodeAsync={true} to decode the Blurhash on a separate background Thread instead of the main UI-Thread. This is useful when you are experiencing stutters because of the Blurhash's decoder - e.g.: in large Lists.

Threads are re-used (iOS: DispatchQueue, Android: kotlinx Coroutines).

Caching

Image

A <Blurhash> component caches the rendered Blurhash (Image) as long as the blurhash, decodeWidth, decodeHeight and decodePunch properties stay the same. Because unmounting the <Blurhash> component clears the cache, re-mounting it will cause it to decode again.

Cosine Operations

Cosine operations get cached in memory to avoid expensive re-calculation (~24.576 cos(...) calls per 32x32 blurhash). Since this can affect memory usage, you can manually clear the cosine array cache by calling:

Blurhash.clearCosineCache()

Note: At the moment, cosine operations are only cached on Android. Calling clearCosineCache() is a no-op on other platforms.

Resources

Buy Me a Coffee at ko-fi.com

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].