1.0.7 • Published 6 years ago

react-native-swipe-close-image v1.0.7

Weekly downloads
3
License
ISC
Repository
github
Last release
6 years ago

React native swipe close image

A swipe close full screen image for Android and iOS

npm.io

Installation

npm install react-native-swipe-close-image --save

Using

  • Create SwipeCloseImage in render() with imageSource is the source of image (Can be local or remote url link)
import SwipeCloseImage from 'react-native-swipe-close-image';
...
render() {
...
<SwipeCloseImage
  ref={c => (this.swipeToCloseRef = c)}
  imageSource={this.state.imageSource}
/>
...
}
  • Then when want to open the image
...
this.swipeToCloseRef.onOpen(this.imageRef);
...

Code

import SwipeCloseImage from 'react-native-swipe-close-image';

export default class App extends Component {
  onPressImage = () => {
    this.swipeToCloseRef.onOpen(this.imageRef);
    this.setState({
      imageSource:
        'https://facebook.github.io/react-native/docs/assets/favicon.png'
    });
  };

  render() {
    return (
      <View style={styles.container}>
        <TouchableWithoutFeedback onPress={this.onPressImage}>
          <Image
            ref={c => {
              this.imageRef = c;
            }}
            source={{
              uri:
                'https://facebook.github.io/react-native/docs/assets/favicon.png'
            }}
            resizeMode="contain"
            style={styles.imageStyle}
          />
        </TouchableWithoutFeedback>
        <SwipeCloseImage
          ref={c => (this.swipeToCloseRef = c)}
          imageSource={this.state.imageSource}
        />
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },
  imageStyle: {
    width: 250,
    height: 200
  }
});

Example

Props

PropDefaultTypeDescription
imageSourcerequiredstring,numberLink of the source url (Can be local or remote link)
onOpenrequiredfunctionFunction to open the image
resizeModeContainstringResize mode for the image
backdropColorrgba(0,0,0,0.75)stringBackdrop color
durationAnim250numberMilisecond animation
distanceDismissSCREEN_HEIGHT / 5numberDistance to auto dismiss close image

Author

Sieu Thai – sieuhuflit@example.com

https://github.com/sieuhuflit

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago