Code Monkey home page Code Monkey logo

react-native-image-carousel's Introduction

react-native-image-carousel

Image carousel with support for heading, captions, fullscreen mode, image swiping and pinch-to-zoom in fullscreen mode.

Supports both Android and iOS. Zoom feature works on iOS only.

Demo

Demo

Installation

npm install --save react-native-image-carousel

Usage

import ImageCarousel from 'react-native-image-carousel';

export default class App extends Component<any, any, any> {
  _imageCarousel: ImageCarousel;

  componentWillMount() {
    (this: any)._renderHeader = this._renderHeader.bind(this);
  }

  _renderHeader(): ReactElement<any> {
    return (
      <TouchableWithoutFeedback onPress={this._imageCarousel.close}>
        <View>
          <Text style={styles.closeText}>Exit</Text>
        </View>
      </TouchableWithoutFeedback>
    );
  }

  _renderFooter(): ReactElement<any> {
    return (
      <Text style={styles.footerText}>Footer!</Text>
    );
  }

  _renderContent(idx: number): ReactElement<any> {
    return (
      <Image
        style={styles.container}
        source={{ uri: urls[idx] }}
        resizeMode={'contain'}
      />
    );
  }

  render(): ReactElement<any> {
    return (
      <View style={styles.container}>
        <ImageCarousel
          ref={(imageCarousel: ImageCarousel) => {
            this._imageCarousel = imageCarousel;
          }}
          renderContent={this._renderContent}
          renderHeader={this._renderHeader}
          renderFooter={this._renderFooter}
        >
          {urls.map((url: string): ReactElement<any> => (
            <Image
              key={url}
              style={styles.image}
              source={{ uri: url, height: 100 }}
              resizeMode={'contain'}
            />
          ))}
        </ImageCarousel>
      </View>
    );
  }
}

Check full example in Example folder.

Props and methods

Every prop is optional.

Name Type Description
activeProps? Object Props of each child when in fullscreen mode. (For a component to fill the screen activeProp's style must be flex: 1). This prop is ignored in case renderContent prop is provided.
activeComponents? [ReactElement<any>] Active components' bounds will be used for opening/closing fullscreen mode animations. If not provided, the immediate children are used.
zoomEnabled? boolean true by default, if false, children are not zoomable.
hideStatusBarOnOpen? boolean true by default, if false, status bar does not fade out on open.
renderContent? (idx: number) => ReactElement<any> Component to render in fullscreen mode for the given index.
renderHeader? () => ReactElement<any> Component to render at the top when in fullscreen mode.
renderFooter? () => ReactElement<any> Component to render at the bottom when in fullscreen mode.
onIdxChange? (idx: number) Fired on index change in fullscreen mode.
onOpen? () => void Fired on fullscreen mode open.
onClose? () => void Fired on fullscreen mode close.

react-native-image-carousel also provides two methods for opening and closing the fullscreen mode respectively:

open(startIdx: number), close.

License

MIT License © Anvilabs LLC

react-native-image-carousel's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-image-carousel's Issues

Does it have landscape support?

Looks awesome. Looking for a image carousel that animates rotation like real native examples.
But I don't see any mention of landscape or orientation, so just wondering before I try implementing it :)

activeComponents usage ?

Hello,
I can't seem to find any documentation for using activeComponents property.

For example I have code like this:

<ImageCarousel>
  <View>
    <Image />
    <Text>Some text</Text>
    <Button>Some button</Button>
  </View>

  <View>
    <Image />
    <Text>Some text</Text>
    <Button>Some button</Button>
  </View>
</ImageCarousel>

When I trigger .open for that carousel, picture gets animated from <View> bounds instead of using <Image> bounds. I assume that I must somehow tell ImageCarousel to use <Image> instead of immediate children ? How would I do that ?

Other than that - this is literally the best gallery/carousel library for React Native !
Keep up the good work !

[IOS]RN 0.33 Support for defaultImageSource

Hi @anvilabs . Great work, This component looks awesome. I have successfully integrated into my react project. But got one small Issue.

When passing the props to the component (renderContent) I am also passing the defaultSource which is a static file on the project folder . This works fine with the thumbnails but when loading the fullscreen view it shows a black view not the defaultSource. below is the code I have used.

Render Method

return ( <View> <Text style={styles.sectionHeaderText}>ADDITIONAL IMAGES</Text> <View style={styles.additionalImageContainer}> <ImageCarousel ref={(imageCarousel: ImageCarousel) => { this._imageCarousel = imageCarousel; }} renderContent={this.renderImage} > {this.state.imageList.map((url: string): ReactElement<any> => ( <Image style={styles.thumbnailImage} key={Math.random()} source={{uri:url}} defaultSource={{uri: './images/placeholder.jpg'}} /> ))} </ImageCarousel> </View> </View> )

renderImage method

return ( <Image style={styles.imageViewerImage} resizeMode={'contain'} onLoadStart={this.onImageLoadStart(i)} source={{uri:this.state.imageList[i]}} defaultSource={{uri: './images/placeholder.jpg'}} /> );

Is there anything I need to do to fix it....

React native how to render items without using any loder?

I have implemented a delete feature for the image editor app.
Case: If the user added a number of images in edit mode and wants to delete the unnecessary layer of the image from the editor then allows to delete the selected layer from the array.
Issue: when deleted the selected layer from the array the remaining image swaps its position and size to deleted image position and size. Even if I double-check the scale value and position remain the same as I fixed. This issue occurs if am not using the loder and if am using the loder then the image did not swap their position and scale.
how to handle the states: I am handling the states in the component and I also checked if I handled the states in redux same error occurred. App speed to slow if handled with redux. Here is my code.
`const onDeleteLayerSequence = data => {
let indexing = data.length;
data.forEach(item => {
indexing--;
item.key = indexing;
});
setInputData(data);
setIsDelete(!isDelete);
};

           const deleteLayer = index => {
             const filterItem = [
               ...inputData.slice(0, index),
               ...inputData.slice(index + 1, inputData.length),
               ];
              onDeleteLayerSequence(filterItem);
             };

              useEffect(() => {
               setImageArray(inputData.filter(item => item.type == 'image'));
               // setLoader(true);
              }, [isDelete]);    
           return (
              <>
               <AutoDragSortableView
                dataSource={inputData}
                parentWidth={util.WP(100)}
                childrenWidth={util.WP(100)}
                childrenHeight={util.WP(12)}
                keyExtractor={(item, index) => item.id}
                renderItem={(item, index) => render_item(item, index)}
                onDataChange={data => onSelectLayer(data)}
                onClickItem={(data, i) => replaceImage(data, i)}
              />
            </View>
          </DraggablePanel>
          <View style={styles.editImageWrapper}>
            <ViewShot
              ref={reference}
              options={{format: 'jpg', quality: 1.0, result: 'base64'}}>
              <ImageBackground
                style={[
                  styles.templateContainer,
                  {backgroundColor: background},
                ]}
                resizeMode="stretch"
                source={selectTemplate}>

                {isFocused &&
                  imageArray &&
                  imageArray.map((item, i) => {
                    return (
                      <component.PinchZoomView
                        minScale={0.1}
                        maxScale={5}
                        scale={item.scale}
                        translateX={item.translateX}
                        translateY={item.translateY}
                        data={value =>
                          modifyValues(value, item.layer, item.key)
                        }
                        key={i}
                        style={[
                          styles.pinchImagePosition,
                          {
                            zIndex: item.key,
                          },
                        ]}>
                        <ImageCarousel>
                          <Image
                            source={{
                              uri: item.editImage,
                              height: util.WP(100),
                              width: util.WP(100),
                            }}
                            key={item}
                            resizeMode="contain"
                          />
                        </ImageCarousel>
                      </component.PinchZoomView>
                    );
                  })}
              </ImageBackground>
            </ViewShot>
          </View>
         </>
        )`

Zoom not working in FullScreen Mode (iOS and Android)

If using something like:

<ImageCarousel
  renderHeader={renderHeader}
  renderContent={renderImage}
  onIdxChange={onChange}
  zoomEnabled={true}>
  { children }
</ImageCarousel>

zoom feature is not working.

If not using custom renderContent, zoom is working but the images are small and pull to exit is not working.

RN version: 0.61.5

Hooks component

How can I use
onPress={this._imageCarousel.close}
in my Hooks component? Can't close image preview in renderHeader

Is it alive? Zoom doesn't work on iOS

So I have a problem with zoom on iOS. It seems like image is updating on zooming but the result is the same.

UPD: Also I want to help with contribution if this project is still alive because it's the best image carousel at this moment for RN builded with just pure JS (hello Expo).

How to add snap to the scrollview out of the lightbox?

I want to add snap movement to the images but they only snap when inside lightbox.
<ImageCarousel ... snapToInterval={deviceWidth} //your element width snapToAlignment={"center"}> {imagesMap} <- MAKE THESE SNAP </ImageCarousel>
How can I achieve that? And also is there a easy way to implement pagination? Thanks

this.props.children causes error

Hi, I'm trying to implement your package in our app. I have the latest I believe 0.4.6. I'm developing on an Android Emulator using sdk 28 from AndroidStudio. I'm basically getting an "Error: Out of memory" message. So I've putt all manner of conlogs in to see if I can figure it out.
Inside the "render" method I have

console.tron.log(`==========here==========`);
				console.tron.log("here");
				console.tron.log(`==========END here==========`);
				console.tron.log(`==========_this.props.children==========`);
				console.tron.log(this.props.children);
				console.tron.log(`==========END _this.props.children==========`);

I get the "here" , sometimes it hangs for a long time, then it seems to rerender, I get the "here" again, then the first line ==========_this.props.children========== then the out of memory error.
I will paste the full stack trace at the bottom but it's huge.and not really formatted. sorry.
please let me know if there's more info I can give you.
My code looks just like your example pretty much

export interface CarouselProps {
	urls: Array<{ imageUrl: string; thumbnailImageUrl: string }>;
}

export class Carousel extends PureComponent<CarouselProps> {
	_imageCarousel: ImageCarousel;

	_renderHeader = (): any => {
		return (
			<TouchableWithoutFeedback onPress={this._imageCarousel.close}>
				<RX.View>
					<RX.Text style={styles.closeText}>Exit</RX.Text>
				</RX.View>
			</TouchableWithoutFeedback>
		);
	};

	_renderContent(idx: number): any {
		return (
			<RX.Image
				style={styles.container}
				source={this.props.urls[idx].imageUrl}
				resizeMode={"contain"}
			/>
		);
	}

	render(): any {
		if (!this.props.urls || this.props.urls.length <= 0) {
			return null;
		}
		return (
			<RX.View style={styles.container}>
				<RX.Text>IMAGES</RX.Text>
				<RX.View>
					<ImageCarousel
						ref={(imageCarousel: ImageCarousel) => {
							this._imageCarousel = imageCarousel;
						}}
						renderContent={this._renderContent}
						renderHeader={this._renderHeader}
					>
						{this.props.urls.map(
							(url: { imageUrl: string; thumbnailImageUrl: string }): any => {
								return (
									<Image
										key={url.thumbnailImageUrl}
										style={styles.image}
										source={{ uri: url.thumbnailImageUrl, height: 100 }}
										resizeMode={"contain"}
									/>
								);
							},
						)}
					</ImageCarousel>
				</RX.View>
			</RX.View>
		);
	}
}

Carousel.displayName = "Carousel";

const styles = StyleSheet.create({
	container: {
		flex: 1,
		justifyContent: "center",
	},
	closeText: {
		color: "white",
		textAlign: "right",
		padding: 10,
	},
	footerText: {
		color: "white",
		textAlign: "center",
	},
	image: {
		marginRight: 2,
		height: 100,
	},
});
 "message": "Error: Out of memory\n\nThis error is located at:\n    in ImageCarousel (created by Carousel)\n    in Carousel (created by StylingLoader)\n    in RCTView (at View.js:45)\n    in View (created by View)\n    in View (created by StylingLoader)\n    in StylingLoader (created by StylingLoader[tasker.preview.images])\n    in StylingLoader[tasker.preview.images] (created by TaskerPreviewCategoryImages)\n    in TaskerPreviewCategoryImages\n    in Unknown (created by StylingLoader)\n    in RCTView (at View.js:45)\n    in View (at ScrollView.js:976)\n    in RCTScrollView (at ScrollView.js:1115)\n    in ScrollView (created by ScrollView)\n    in ScrollView (created by StylingLoader)\n    in RCTView (at View.js:45)\n    in View (created by View)\n    in View (created by StylingLoader)\n    in StylingLoader (created by StylingLoader[tasker.preview])\n    in StylingLoader[tasker.preview] (created by TaskerPreview)\n    in TaskerPreview (created by TaskerPreviewContainer)\n    in _b (at withNavigationFocus.js:33)\n    in withNavigationFocus(_b) (at withNavigation.js:25)\n    in withNavigation(withNavigationFocus(_b)) (created by TaskerPreviewContainer)\n    in ErrorBoundary (created by TaskerPreviewContainer)\n    in AnalyticsContextProvider (created by TaskerPreviewContainer)\n    in TaskerPreviewContainer (at SceneView.js:9)\n    in SceneView (at StackViewLayout.tsx:899)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at StackViewCard.tsx:93)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at screens.native.js:59)\n    in Screen (at StackViewCard.tsx:80)\n    in Card (at createPointerEventsContainer.tsx:95)\n    in Container (at StackViewLayout.tsx:971)\n    in RCTView (at View.js:45)\n    in View (at screens.native.js:83)\n    in ScreenContainer (at StackViewLayout.tsx:383)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at StackViewLayout.tsx:379)\n    in PanGestureHandler (at StackViewLayout.tsx:372)\n    in StackViewLayout (at withOrientation.js:30)\n    in withOrientation (at StackView.tsx:103)\n    in RCTView (at View.js:45)\n    in View (at Transitioner.tsx:267)\n    in Transitioner (at StackView.tsx:40)\n    in StackView (at createNavigator.js:61)\n    in Navigator (at createKeyboardAwareNavigator.js:12)\n    in KeyboardAwareNavigator (at SceneView.js:9)\n    in SceneView (at StackViewLayout.tsx:888)\n    in RCTView (at View.js:45)\n    in View (at StackViewLayout.tsx:887)\n    in RCTView (at View.js:45)\n    in View (at StackViewLayout.tsx:886)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at StackViewCard.tsx:93)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at screens.native.js:59)\n    in Screen (at StackViewCard.tsx:80)\n    in Card (at createPointerEventsContainer.tsx:95)\n    in Container (at StackViewLayout.tsx:971)\n    in RCTView (at View.js:45)\n    in View (at screens.native.js:83)\n    in ScreenContainer (at StackViewLayout.tsx:383)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (at StackViewLayout.tsx:379)\n    in PanGestureHandler (at StackViewLayout.tsx:372)\n    in StackViewLayout (at withOrientation.js:30)\n    in withOrientation (at StackView.tsx:103)\n    in RCTView (at View.js:45)\n    in View (at Transitioner.tsx:267)\n    in Transitioner (at StackView.tsx:40)\n    in StackView (at createNavigator.js:61)\n    in Navigator (at createKeyboardAwareNavigator.js:12)\n    in KeyboardAwareNavigator (at createAppContainer.js:429)\n    in NavigationContainer (created by Navigator_)\n    in Navigator_ (created by Context.Consumer)\n    in QueryErrorProcessor (created by QueryRootNavigationState_)\n    in QueryRootNavigationState_ (created by QueryRootNavigationState)\n    in QueryRootNavigationState (created by Context.Consumer)\n    in NavigatorSelector (created by App)\n    in AnalyticsRootProvider (created by Context.Consumer)\n    in AnalyticsRoot (created by CoreBootstrap)\n    in ApolloProvider (created by ApolloProvider_)\n    in ApolloProvider (created by ApolloProvider_)\n    in ApolloProvider_ (created by Context.Consumer)\n    in ApolloProvider! (created by CoreBootstrap)\n    in ServerProvider_ (created by Context.Consumer)\n    in ServerProvider (created by CoreBootstrap)\n    in RCTView (at View.js:45)\n    in View (created by View)\n    in View (created by ViewportProvider_)\n    in ViewportProvider_ (created by Context.Consumer)\n    in ViewportProvider! (created by CoreBootstrap)\n    in SelectTextStyles (created by Context.Consumer)\n    in SelectColorPalette (created by Context.Consumer)\n    in SelectTextAndColors (created by CoreBootstrap)\n    in LegacyContextSignalComponent (created by CoreBootstrap)\n    in LegacyIntlConsumer (created by IntlProvider)\n    in IntlProvider (created by IntlProvider)\n    in IntlProvider (created by CoreBootstrap)\n    in EnvironmentProvider (created by CoreBootstrap)\n    in CoreBootstrap (created by App)\n    in App\n    in RCTView (at View.js:45)\n    in View (created by RootViewUsingStore)\n    in RCTView (at View.js:45)\n    in View (at createAnimatedComponent.js:151)\n    in AnimatedComponent (created by RootViewUsingStore)\n    in RootViewUsingStore (at renderApplication.js:35)\n    in RCTView (at View.js:45)\n    in View (at AppContainer.js:98)\n    in RCTView (at View.js:45)\n    in View (at AppContainer.js:115)\n    in AppContainer (at renderApplication.js:34)",

Columns?

Whenever I try to put it into a FlatList I fail at it. The carousel is rendered but always the first image.

Anyone knows a tangible way to make a table with columns and rows of images?

Does it support 100+ images?

Hi,
I have about 100+ images to show in carousel (remote images). Does this library will be performant if use 100+ images. Most of the libraries have OutOfMemory issue if using large number of images.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.