Skip to content

Commit

Permalink
refactor: rename url to src (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
duguyihou authored Apr 25, 2024
1 parent 77540d6 commit 70c60ed
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 752 deletions.
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Performant React Native image component. Powered by [Nuke](https://github.com/ke
- Image downloading and caching
- TypeScript Support
- written in Swift and Kotlin

## Installation

```sh
Expand All @@ -20,34 +21,34 @@ npm install react-native-turbo-image
## Usage

```js
import TurboImage from "react-native-turbo-image";
import TurboImage from 'react-native-turbo-image';

// ...

<TurboImage
url={url}
style={styles.box}
cachePolicy="dataCache"
blurhash="ULKKWp^+s,_300M{t7tR~XNHE2bI00xuWBRP"
/>
src={url}
style={styles.box}
cachePolicy="dataCache"
blurhash="ULKKWp^+s,_300M{t7tR~XNHE2bI00xuWBRP"
/>;
```

## Props

| Prop | Type | Default | Description |
| ------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------- |
| url | string | | The URL of the image |
| resizeMode | string | contain | The resize mode of the image |
| showActivityIndicator (iOS only) | boolean | false | Whether to show the indicator when loading |
| fadeDuration | number | 0.5(iOS) / 0.1(Android) | The transition duration of the image |
| borderRadius | number | | The border radius added to the image |
| rounded | boolean | false | Round the image into a circle |
| blur | number | | The blur radius of the blur filter added to the image |
| monochrome | number/ColorValue || |
| blurhash | string | | The blurhash of the image to show while loading |
| cachePolicy | string | memory | The cache policy of the image |
| onError | function | | The function to call when an error occurs. |
| onSucess | function | | The function to call when the image is successfully loaded |
| Prop | Type | Default | Description |
| -------------------------------- | ------------------- | ----------------------- | ---------------------------------------------------------- |
| src | string | | The URL of the image |
| resizeMode | string | contain | The resize mode of the image |
| showActivityIndicator (iOS only) | boolean | false | Whether to show the indicator when loading |
| fadeDuration | number | 0.3(iOS) / 0.1(Android) | The transition duration of the image |
| borderRadius | number | | The border radius added to the image |
| rounded | boolean | false | Round the image into a circle |
| blur | number | | The blur radius of the blur filter added to the image |
| monochrome | number / ColorValue | | The color applied to the image |
| blurhash | string | | The blurhash of the image to show while loading |
| cachePolicy | string | memory | The cache policy of the image |
| onError | function | | The function to call when an error occurs. |
| onSucess | function | | The function to call when the image is successfully loaded |

## Contributing

Expand Down
2 changes: 1 addition & 1 deletion android/src/main/java/com/turboimage/TurboImageView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.facebook.react.uimanager.ThemedReactContext

@SuppressLint("ViewConstructor")
class TurboImageView(reactContext: ThemedReactContext) : AppCompatImageView(reactContext) {
var url: String? = null
var src: String? = null
var cachePolicy: String? = "memory"
var crossfade: Int = CrossfadeDrawable.DEFAULT_DURATION
var blurhash: String? = null
Expand Down
8 changes: 4 additions & 4 deletions android/src/main/java/com/turboimage/TurboImageViewManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class TurboImageViewManager : SimpleViewManager<TurboImageView>() {
val diskCacheEnabled =
if (view.cachePolicy != "memory") CachePolicy.ENABLED else CachePolicy.DISABLED
val request = ImageRequest.Builder(view.context)
.data(view.url)
.data(view.src)
.target(view)
.listener(
onSuccess = { request, result ->
Expand Down Expand Up @@ -95,9 +95,9 @@ class TurboImageViewManager : SimpleViewManager<TurboImageView>() {
}
}

@ReactProp(name = "url")
fun setUrl(view: TurboImageView, url: String) {
view.url = url
@ReactProp(name = "src")
fun setSrc(view: TurboImageView, src: String) {
view.src = src
}

@ReactProp(name = "resizeMode")
Expand Down
12 changes: 0 additions & 12 deletions example-server/index.js

This file was deleted.

Loading

0 comments on commit 70c60ed

Please sign in to comment.