Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Update documentation for new repo #22

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 94 additions & 94 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### ⚠️ This is a fork of https://github.com/DylanVann/react-native-fast-image. All credit goes to the original author.
### ⚠️ This is a fork of [react-native-fast-image](https://github.com/DylanVann/react-native-fast-image). All credit goes to the original author.

<h1 align="center">
🚩 FastImage
Expand Down Expand Up @@ -38,67 +38,65 @@ Performant React Native image component.
<em>FastImage example app.</em>
</p>

React Native's `Image` component handles image caching like browsers
for the most part.
If the server is returning proper cache control
headers for images you'll generally get the sort of built in
caching behavior you'd have in a browser.
Even so many people have noticed:
React Native’s `Image` component handles image caching like browsers for the most part.

- Flickering.
- Cache misses.
- Low performance loading from cache.
- Low performance in general.
If the server is returning proper cache control headers for images you’ll generally get the sort of built in caching behavior you’d have in a browser.

Even so, many people have noticed:

- flickering,
- cache misses,
- low performance loading from cache, and
- low performance in general.

`FastImage` is an `Image` replacement that solves these issues.
`FastImage` is a wrapper around
[SDWebImage (iOS)](https://github.com/rs/SDWebImage)
and
[Glide (Android)](https://github.com/bumptech/glide).

`FastImage` is a wrapper around [SDWebImage (iOS)](https://github.com/rs/SDWebImage) and [Glide (Android)](https://github.com/bumptech/glide).

## Features

- [x] Aggressively cache images.
- [x] Add authorization headers.
- [x] Prioritize images.
- [x] Preload images.
- [x] GIF support.
- [x] Border radius.
- [x] Aggressively cache images.
- [x] Add authorization headers.
- [x] Prioritize images.
- [x] Preload images.
- [x] GIF support.
- [x] Border radius.

## Usage

**Note: You must be using React Native 0.60.0 or higher to use the most recent version of `react-native-fast-image`.**
**Note: You must be using React Native 0.60.0 or higher to use the most recent version of `@d11/react-native-fast-image`.**

```bash
yarn add react-native-fast-image
yarn add @d11/react-native-fast-image
cd ios && pod install
```

```jsx
import FastImage from 'react-native-fast-image'

const YourImage = () => (
<FastImage
style={{ width: 200, height: 200 }}
source={{
uri: 'https://unsplash.it/400/400?image=1',
headers: { Authorization: 'someAuthToken' },
priority: FastImage.priority.normal,
}}
resizeMode={FastImage.resizeMode.contain}
/>
)
import FastImage from "@d11/react-native-fast-image";
import * as React from "react";

const YourImage = (): React.ReactNode => (
<FastImage
resizeMode={FastImage.resizeMode.contain}
style={{ height: 200, width: 200 }}
source={{
headers: { Authorization: "someAuthToken" },
priority: FastImage.priority.normal,
uri: "https://unsplash.it/400/400?image=1",
}}
/>
);
```

## Are you using Glide already using an AppGlideModule?
## Are you using Glide already using an `AppGlideModule`?

- [Are you using Glide already using an AppGlideModule?](docs/app-glide-module.md) (you might have problems if you don't read this)
- [Are you using Glide already using an `AppGlideModule`?](docs/app-glide-module.md) (you might have problems if you don't read this)

## Are you using Proguard?
## Are you using ProGuard?

If you use Proguard you will need to add these lines to `android/app/proguard-rules.pro`:
If you use [ProGuard](https://www.guardsquare.com/proguard) you’ll need to add these lines to `android/app/proguard-rules.pro`:

```
```pro
-keep public class com.dylanvann.fastimage.* {*;}
-keep public class com.dylanvann.fastimage.** {*;}
-keep public class * implements com.bumptech.glide.module.GlideModule
Expand All @@ -119,45 +117,45 @@ Source for the remote image to load.

### `source.uri?: string`

Remote url to load the image from. e.g. `'https://facebook.github.io/react/img/logo_og.png'`.
Remote url to load the image from, e.g. `"https://unsplash.it/400/400?image=1"`.

---

### `source.headers?: object`
### `source.headers?: Object`

Headers to load the image with. e.g. `{ Authorization: 'someAuthToken' }`.
Headers to load the image with, e.g. `{ Authorization: "someAuthToken" }`.

---

### `source.priority?: enum`
### `source.priority?: Priorities`

- `FastImage.priority.low` - Low Priority.
- `FastImage.priority.normal` **(Default)** - Normal Priority.
- `FastImage.priority.high` - High Priority.
- `FastImage.priority.low` – Low Priority.
- `FastImage.priority.normal` **(Default)** – Normal Priority.
- `FastImage.priority.high` – High Priority.

---

### `source.cache?: enum`
### `source.cache?: CacheControls`

- `FastImage.cacheControl.immutable` - **(Default)** - Only updates if url changes.
- `FastImage.cacheControl.web` - Use headers and follow normal caching procedures.
- `FastImage.cacheControl.cacheOnly` - Only show images from cache, do not make any network requests.
- `FastImage.cacheControl.immutable` – **(Default)** - Only updates if url changes.
- `FastImage.cacheControl.web` – Use headers and follow normal caching procedures.
- `FastImage.cacheControl.cacheOnly` – Only show images from cache, do not make any network requests.

---

### `defaultSource?: number`

- An asset loaded with `require(...)`.
- Note that like the built-in `Image` implementation, on Android `defaultSource` does not work in debug mode. This is due to the fact that assets are sent from the dev server, but RN's functions only know how to load it from `res`.
- An asset loaded with `require()` or `import`.
- Note that like the built-in `Image` implementation, on Android `defaultSource` does not work in debug mode. This is due to the fact that assets are sent from the dev server, but RNs functions only know how to load it from `res`.

---

### `resizeMode?: enum`
### `resizeMode?: ResizeModes`

- `FastImage.resizeMode.contain` - Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
- `FastImage.resizeMode.cover` **(Default)** - Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
- `FastImage.resizeMode.stretch` - Scale width and height independently, This may change the aspect ratio of the src.
- `FastImage.resizeMode.center` - Do not scale the image, keep centered.
- `FastImage.resizeMode.contain` – Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding).
- `FastImage.resizeMode.cover` **(Default)** – Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding).
- `FastImage.resizeMode.stretch` – Scale width and height independently, This may change the aspect ratio of the src.
- `FastImage.resizeMode.center` – Do not scale the image, keep centered.

---

Expand All @@ -167,25 +165,29 @@ Called when the image starts to load.

---

### `onProgress?: (event) => void`
### `onProgress?: (event: OnProgressEvent) => void`

Called when the image is loading.

e.g. `onProgress={e => console.log(e.nativeEvent.loaded / e.nativeEvent.total)}`
```tsx
onProgress={event => console.log(event.nativeEvent.loaded, event.nativeEvent.total)}
```

---

### `onLoad?: (event) => void`
### `onLoad?: (event: OnLoadEvent) => void`

Called on a successful image fetch. Called with the width and height of the loaded image.

e.g. `onLoad={e => console.log(e.nativeEvent.width, e.nativeEvent.height)}`
```jsx
onLoad={event => console.log(event.nativeEvent.width, event.nativeEvent.height)}
```

---

### `onError?: () => void`

Called on an image fetching error or when source is malformed (i.e: empty or null).
Called on an image fetching error or when source is malformed, i.e., empty or `null`.

---

Expand All @@ -195,39 +197,40 @@ Called when the image finishes loading, whether it was successful or an error.

---

### `style`
### `style?: ViewStyle`

A React Native style. Supports using `borderRadius`.

---

### `fallback: boolean`
### `fallback?: boolean`

If true will fallback to using `Image`.
In this case the image will still be styled and laid out the same way as `FastImage`.
If `true` it will fallback to using `Image`. The image will still be styled and laid out the same way as `FastImage`.

---

### `tintColor?: number | string`

If supplied, changes the color of all the non-transparent pixels to the given color.

---

### `testID?: string`

Optional ID for testing, e.g., via [`react-test-renderer`](https://www.npmjs.com/package/react-test-renderer).

## Static Methods

### `FastImage.preload: (source[]) => void`

Preload images to display later. e.g.
Preload images to display later.

```js
```tsx
FastImage.preload([
{
uri: 'https://facebook.github.io/react/img/logo_og.png',
headers: { Authorization: 'someAuthToken' },
},
{
uri: 'https://facebook.github.io/react/img/logo_og.png',
headers: { Authorization: 'someAuthToken' },
},
{
uri: "https://unsplash.it/400/400?image=1",
headers: { Authorization: "someAuthToken" },
},
])
```

Expand All @@ -249,26 +252,23 @@ If you have any problems using this library try the steps in [troubleshooting](d

## Supported React Native Versions

This project only aims to support the latest version of React Native.\
This simplifies the development and the testing of the project.
This project only aims to support the latest version of React Native. This simplifies the development and the testing of the project.

If you require new features or bug fixes for older versions you can fork this project.

## Credits

The idea for this modules came from
[vovkasm's](https://github.com/vovkasm)
[react-native-web-image](https://github.com/vovkasm/react-native-web-image)
package.
It also uses Glide and SDWebImage, but didn't have some features I needed (priority, headers).
The idea for this modules came from [vovkasm’s](https://github.com/vovkasm) [react-native-web-image](https://github.com/vovkasm/react-native-web-image) package.

It also uses Glide and SDWebImage, but didn’t have some features I needed (priority, headers).

Thanks to [@mobinni](https://github.com/mobinni) for helping with the conceptualization
Thanks to [@mobinni](https://github.com/mobinni) for helping with the conceptualization.

## Licenses

- FastImage - MIT © [DreamSportsLabs](https://github.com/dream-sports-labs/)
- SDWebImage - `MIT`
- Glide - BSD, part MIT and Apache 2.0. See the [LICENSE](https://github.com/bumptech/glide/blob/master/LICENSE) file for details.
- FastImage – MIT © [DreamSportsLabs](https://github.com/dream-sports-labs/)
- SDWebImage – MIT
- Glide – BSD, part MIT and Apache 2.0. See the [LICENSE](https://github.com/bumptech/glide/blob/master/LICENSE) file for details.

[build-badge]: https://github.com/dream-sports-labs/react-native-fast-image/workflows/CI/badge.svg
[build]: https://github.com/dream-sports-labs/react-native-fast-image/actions?query=workflow%3ACI
Expand All @@ -277,10 +277,10 @@ Thanks to [@mobinni](https://github.com/mobinni) for helping with the conceptual
[downloads-badge]: https://img.shields.io/npm/dm/react-native-fast-image.svg
[npmtrends]: http://www.npmtrends.com/@d11/react-native-fast-image
[package]: https://www.npmjs.com/package/@d11/react-native-fast-image
[version-badge]: https://img.shields.io/npm/v/react-native-fast-image.svg
[twitter]: https://twitter.com/home?status=Check%20out%20react-native-fast-image%20by%20%40atomarranger%20https%3A//github.com/DylanVann/react-native-fast-image
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/dylanvann/react-native-fast-image.svg?style=social
[github-watch-badge]: https://img.shields.io/github/watchers/dylanvann/react-native-fast-image.svg?style=social
[version-badge]: https://img.shields.io/npm/v/@d11/react-native-fast-image.svg
[twitter]: https://twitter.com/home?status=Check%20out%20react-native-fast-image%20by%20%40atomarranger%20https%3A//github.com/dream-sports-labs/react-native-fast-image
[twitter-badge]: https://img.shields.io/twitter/url/https/github.com/dream-sports-labs/react-native-fast-image.svg?style=social
[github-watch-badge]: https://img.shields.io/github/watchers/dream-sports-labs/react-native-fast-image.svg?style=social
[github-watch]: https://github.com/dream-sports-labs/react-native-fast-image/watchers
[github-star-badge]: https://img.shields.io/github/stars/dylanvann/react-native-fast-image.svg?style=social
[github-star-badge]: https://img.shields.io/github/stars/dream-sports-labs/react-native-fast-image.svg?style=social
[github-star]: https://github.com/dream-sports-labs/react-native-fast-image/stargazers
7 changes: 3 additions & 4 deletions docs/app-glide-module.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# Removing MyAppGlideModule from react-native-fast-image
# Removing `MyAppGlideModule` from `@d11/react-native-fast-image`

If you are using Glide within your application using an `AppGlideModule` then you will
need to prevent the inclusion of the `AppGlideModule` in this package.
If you’re using Glide within your application using an `AppGlideModule` then you’ll need to prevent the inclusion of the `AppGlideModule` in this package.

To accomplish this you can add to `android/build.gradle`:
To accomplish this you can add this to your `android/build.gradle`:

```gradle
project.ext {
Expand Down
13 changes: 6 additions & 7 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
This is how to start the example app so you can test code with it.

```bash
Make sure you are running on node 18+ and java 21
# This package Using Yarn3.6.4
Make sure you’re running on node 18+ and Java 21
# This package Using Yarn 3.6.4
corepack enable

# check (Should return 3.6.4)
yarn -v
# Check (Should return 3.6.4)
yarn -v

# If version listed is not 3.6.4
corepack prepare yarn@3.6.4 --activate
Expand All @@ -20,14 +20,13 @@ yarn
# Android
yarn example android

# IOS
# iOS
# Install pod dependency
cd ReactNativeFastImageExample/ios
bundle install
pod install


# Got to root folder
# Go to root folder
cd ../..
yarn example ios
```
Loading
Loading