@alliance-software-development/asd-media-react-native
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

asd-media-react-native

React Native Module for ASD Media built on top of UploadCare API

Prequisites

Installation

npm install @alliance-software-development/asd-media-react-native

OR

yarn add @alliance-software-development/asd-media-react-native

Usage

import React from 'react';
import { View, Image, Button, StyleSheet } from 'react-native';
import { ASDMedia } from '@alliance-software-development/asd-media-react-native';

// ...

const App = () => {
  const asdMediaRef = React.useRef()
  const [selectedImage, setSelectedImage] = React.useState()

  const handleOnImageUpload = (data) => {
    alert(JSON.stringify(data));
  };

  const handleOnImageChange = (data) => {
    setSelectedImage(data.uri)
  };

  return (
    <View style={styles.container}>

      <View style={{ margin: 10 }}>
    <ASDMedia
      ref={asdMediaRef}
      publicKey="UPLOADCARE_PUBLIC_KEY"
      onImageUpload={handleOnImageUpload}
      onImageChange={handleOnImageChange}
    />
    </View>
    <Image source={{uri: selectedImage }} style={{width: 100, height: 100}}>
    <Button title="Upload" onPress={asdMediaRef.current?.handleUpload} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
        flex: 1,
        flexDirection: "row",
        justifyContent: "center",
        alignItems: "center"
        }
})

Props

ASDMedia component accepts following props.

Name Type Default Is Required
publicKey string - Yes
onImageUpload Func - Yes
onImageChange Func - No
buttonText string Choose a photo No
buttonContainerStyle {} - No
buttonStyle {} - No
buttonTextStyle {} - No

Props Explanation

  • publicKey (String) - UploadCare public key of your project Doc here.
  • onImageUpload (?=Function) - Called upon success or failure of the upload session with { ...props }
  • onImageChange (?=Function) - Called when the image selection changes with { uri: imagepath }
  • buttonText (?String) - Button text, default is Choose a photo.
  • buttonContainerStyle (?Object) - Styling to be spread to the view wrapping the button Component.
  • buttonStyle (?Object) - Styling to be spread to the default button component style.
  • buttonTextStyle (?Object) - Button text styling

Package Sidebar

Install

npm i @alliance-software-development/asd-media-react-native

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

44.6 kB

Total Files

9

Last publish

Collaborators

  • cvjude
  • blvckleumas
  • kelvin_img
  • abdulsamadola
  • asddev