22
22
23
23
![ @georstat : react-native-image-gallery default_demo] ( https://user-images.githubusercontent.com/717975/142775046-475bfc3b-6326-4b3d-afa3-58189e003043.gif )
24
24
25
-
26
25
## Installation
27
26
28
27
#### yarn:
@@ -68,12 +67,14 @@ const MyGallery = () => {
68
67
```
69
68
70
69
#### Custom Gallery without thumbs:
70
+
71
71
For more info check [ example] ( https://github.com/georstat/react-native-image-gallery/tree/main/example/src )
72
72
73
73
This example uses [ georstat/react-native-image-cache] ( https://github.com/georstat/react-native-image-cache ) for image caching
74
+
74
75
``` tsx
75
- import {CacheManager , CachedImage } from ' @georstat/react-native-image-cache' ;
76
- import {Dirs } from ' react-native-file-access' ;
76
+ import { CacheManager , CachedImage } from ' @georstat/react-native-image-cache' ;
77
+ import { Dirs } from ' react-native-file-access' ;
77
78
78
79
CacheManager .config = {
79
80
baseDir: ` ${Dirs .CacheDir }/images_cache/ ` ,
@@ -83,53 +84,53 @@ CacheManager.config = {
83
84
};
84
85
85
86
const MyGallery = () => {
86
- const [isOpen, setIsOpen] = useState (false );
87
- const openGallery = () => setIsOpen (true );
88
- const closeGallery = () => setIsOpen (false );
87
+ const [isOpen, setIsOpen] = useState (false );
88
+ const openGallery = () => setIsOpen (true );
89
+ const closeGallery = () => setIsOpen (false );
89
90
90
- const renderHeaderComponent = (image : any , currentIndex : number ) => {
91
- return <Header currentIndex = { currentIndex } />;
92
- };
93
-
94
- const renderFooterComponent = (image : any , currentIndex : number ) => {
95
- return <Footer total = { images .length } currentIndex = { currentIndex } />;
96
- };
97
-
98
- const renderCustomImage = (image : Image ) => {
99
- return (
100
- <View style = { styles .customImageContainer } >
101
- <CachedImage
102
- resizeMode = " cover"
103
- source = { image .url }
104
- style = { styles .customImage }
105
- thumbnailSource = " https://via.placeholder.com/350x150"
106
- />
107
- </View >
108
- );
109
- };
91
+ const renderHeaderComponent = (image : any , currentIndex : number ) => {
92
+ return <Header currentIndex = { currentIndex } />;
93
+ };
94
+
95
+ const renderFooterComponent = (image : any , currentIndex : number ) => {
96
+ return <Footer total = { images .length } currentIndex = { currentIndex } />;
97
+ };
98
+
99
+ const renderCustomImage = (image : Image ) => {
110
100
return (
111
- <View >
112
- <Button onPress = { openGallery } title = " Open Gallery" />
113
- <ImageGallery
114
- close = { closeCustomGallery }
115
- hideThumbs
116
- images = { images }
117
- isOpen = { isCustomGalleryOpen }
118
- renderCustomImage = { renderCustomImage }
119
- renderFooterComponent = { renderFooterComponent }
120
- renderHeaderComponent = { renderHeaderComponent }
121
- />
122
- </View >
123
- )
124
- }
101
+ <View style = { styles .customImageContainer } >
102
+ <CachedImage
103
+ resizeMode = " cover"
104
+ source = { image .url }
105
+ style = { styles .customImage }
106
+ thumbnailSource = " https://via.placeholder.com/350x150"
107
+ />
108
+ </View >
109
+ );
110
+ };
111
+ return (
112
+ <View >
113
+ <Button onPress = { openGallery } title = " Open Gallery" />
114
+ <ImageGallery
115
+ close = { closeCustomGallery }
116
+ hideThumbs
117
+ images = { images }
118
+ isOpen = { isCustomGalleryOpen }
119
+ renderCustomImage = { renderCustomImage }
120
+ renderFooterComponent = { renderFooterComponent }
121
+ renderHeaderComponent = { renderHeaderComponent }
122
+ />
123
+ </View >
124
+ );
125
+ };
125
126
```
126
127
127
128
## Props
128
129
129
130
#### ` CachedImage ` accepts the following props:
130
131
131
132
| Properties | PropType | Description |
132
- | ------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
133
+ | ----------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
133
134
| ` isOpen ` | ` Boolean ` | (** Required** ) when to show the gallery. |
134
135
| ` images ` | ` Array ` | (** Required** ) array of objects. Every image must have a ` url ` (required), a thumbUrl (optional) and id (optional) and any other info you need |
135
136
| ` resizeMode ` | ` string ` | React Native Image component [ resizeMode] ( https://reactnative.dev/docs/image#resizemode ) defaults to ` contain ` , used on images |
@@ -144,6 +145,11 @@ const MyGallery = () => {
144
145
| ` renderHeaderComponent ` | ` Func ` | Function to render a custom header at the top of the screen. Accepts image and current index, eg. ` (image:Image, currentIndex:number) => ... ` |
145
146
| ` renderFooterComponent ` | ` Func ` | Function to render a custom header at the top of the screen. Accepts image and current index eg. ` (image:Image, currentIndex:number) => ... ` |
146
147
148
+ ## Todo:
149
+
150
+ - Add zoom factor
151
+ - Add prop to keep zoom and double tap to zoom out
152
+
147
153
## Authors:
148
154
149
155
- [ Efstathios Ntonas] ( https://github.com/efstathiosntonas )
0 commit comments