1.8.4 • Published 5 years ago

react-native-neon-android v1.8.4

Weekly downloads
100
License
MIT
Repository
github
Last release
5 years ago

react-native-neon-android

A React Native package to take photos using custom camera or custom gallery in android.

  • (Supports on react-native >= 0.47.0)

Installation

npm install react-native-neon-android

Linking

react-native link

Manual linking

  1. Add the following lines to android/settings.gradle:
include ':react-native-neon-android'
project(':react-native-neon-android').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-neon-android/android/app')
  1. Add the compile line to the dependencies in android/app/build.gradle:
dependencies {
    ---------------------
    compile project(':react-native-neon-android')
}
  1. Add the following line to android/app/src/main/java/MainApplication.java:
@Override
protected List<ReactPackage> getPackages() {
   return Arrays.<ReactPackage>asList(
       new MainReactPackage(),
         new NeonReactPackage()
   );
}

Add the following lines to android/app/src/AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          --------------------------------------------->
  <application
     ---------------------
     tools:replace="android:theme,android:allowBackup">
  </application>
   
</manifest>   

Add the following lines to android/app/build.gradle:

android {
    ----------------------
    dataBinding {
        enabled = true
    }
}

Usage

Import NeonAndroid

import NeonAndroid from 'react-native-neon-android';

React methods

  1. NeonAndroid.openNeutral(neonParamsJson, callback)
  2. NeonAndroid.openCamera(neonParamsJson, callback)
  3. NeonAndroid.openGallery(neonParamsJson, callback)
  4. NeonAndroid.openLivePhotos(neonParamsJson, callback)
  • neonParamsJson - Json of neonParams object(can be pass as null)
  • callback - will return neonResponse Json

Example:

NeonAndroid.openNeutral(JSON.stringify(neonParams), (response) => console.log(response));

where response is the neonResponse json which you will get in callback, you can convert it into object using JSON.parse(response).

neonParams

{
    libraryMode: 0,
    numberOfPhotos: 0,
    cameraFacing: 0,
    cameraOrientation: 0,
    cameraViewType: 0,
    galleryViewType: 0,
    tagEnabled: false,
    flashEnabled: true,
    cameraSwitchingEnabled: false,
    cameraToGallerySwitchEnabled: false,
    enableFolderStructure: true,
    galleryToCameraSwitchEnabled: false,
    isRestrictedExtensionJpgPngEnabled: true,
    enableImageEditing: false,
    locationRestrictive: false,
    hideCameraButtonInNeutral: false,
    hideGalleryButtonInNeutral: false,
    hasOnlyProfileTag: false,
    profileTagName: null,
    imageTagListJson: null,
    alreadyAddedImagesJson: null,
};
  • Detail:
KeyTypeDefault ValueRequiredDescription
libraryModeint0no0-Relax, 1-Restrict(a pop-up will be shown on before exit from library)
numberOfPhotosint0noPass 0 for no restriction, if any number other than 0 is passed then only that particular number of images are allowed
cameraFacingint0no0-Rear, 1-Front
cameraOrientationint0no0-Landscape, 1-Portrait
cameraViewTypeint0no0-Normal camera, 1-Gallery preview camera
galleryViewTypeint0no0-Grid Structure, 1-Horizontal Structure
tagEnabledbooleanfalseno*if passes true then imageTagListJson must not be null or empty
flashEnabledbooleantruenoIf passes true then flash is enabled
cameraSwitchingEnabledbooleanfalsenoIf passes true then camera swithing is allowed
cameraToGallerySwitchEnabledbooleanfalsenoIf passes true then access to gallery from camera screen is allowed
enableFolderStructurebooleantruenoIf passes true then folder structure for gallery is enabled
galleryToCameraSwitchEnabledbooleanfalsenoIf passes true then access to camera from galeery screen is allowed
isRestrictedExtensionJpgPngEnabledbooleantruenoIf passes true then only jpg and png format are allowed
enableImageEditingbooleanfalseno
locationRestrictivebooleanfalsenoIf passes true then GPS location is required
hideCameraButtonInNeutralbooleanfalsenoIf passes true then camera button will hide on neutral screen
hideGalleryButtonInNeutralbooleanfalsenoIf passes true then gallery button will hide on neutral screen
hasOnlyProfileTagbooleanfalseno*if passes true then profileTagName must not be null or empty
profileTagNameStringnullno
imageTagListJsonJsonnullnoJson of array of imageTag
alreadyAddedImagesJsonJsonnullnoJson of array of already added images(fileInfo)
compressByint100noimage quality(size) compare to original image(in between 0-100)
folderRestrictivebooleanfalsenoIf passes true then image selection from gallery is restricted(only images taken from app are allowed)
folderNameStringnullnoIf passes then images will be saved in a separate folder(folderName)
titleNameStringnullnoIf passes then title of neutral screen will be changed accordingly
showTagImagebooleanfalsenoIf true then tag preview will show on camera screen
showPreviewForEachImagebooleanfalsenoIf true then preview will show on each photo click
  • fileInfo
{
    dateTimeTaken: "1522229825513",
    fileCount: 0,
    filePath: "https://images.unsplash.com/photo-1441742917377-57f78ee0e582?h=1024",
    selected: false,
    source: "PHONE_GALLERY",
    type: "IMAGE",
    latitude: "",
    longitude: "",
    fileName: "",
    displayName: "",
    fileTag: {
        mandatory: false,
        numberOfPhotos: 1,
        tagId: "3",
        tagName: "Tag3",
        location: null,
        tagPreviewUrl: "https://----"
    }
};

Details of fileInfo:

KeyTypeDescription
dateTimeTakenStringdateTime in milliseconds
fileCountint
filePathStringlocal path or url
selectedboolean
sourceboolean
typeString
latitudeString
longitudeString
fileNameString
displayNameString
fileTagobjectimageTag
  • imageTag
{
    mandatory: false,
    numberOfPhotos: 1,
    tagId: "1",
    tagName: "Tag1",
    location: null,
    tagPreviewUrl: "https://----"
};

Details of imageTag:

KeyTypeDescription
mandatoryboolean
numberOfPhotosintnumber of images required for particular tag
tagIdString
tagNameString
locationobjectLocation used in android

Usage Example

import React, {Component} from 'react';
import {
    StyleSheet,
    Text,
    View,
    TouchableNativeFeedback, FlatList, Image, ScrollView
} from 'react-native';
import NeonAndroid from 'react-native-neon-android';
import * as Constants from './Constants';

let imageTagList = [
    {
        mandatory: false,
        numberOfPhotos: 1,
        tagId: "1",
        tagName: "Tag1",
        location: null,
        tagPreviewUrl: "https://----"
    },

    {
        mandatory: false,
        numberOfPhotos: 1,
        tagId: "2",
        tagName: "Tag2",
        location: null,
        tagPreviewUrl: "https://----"
    }

];

let neonParams = {
    libraryMode: 0,
    numberOfPhotos: 0,
    cameraFacing: 0,
    cameraOrientation: 0,
    cameraViewType: 0,
    galleryViewType: 0,
    tagEnabled: false,
    flashEnabled: true,
    cameraSwitchingEnabled: false,
    cameraToGallerySwitchEnabled: false,
    enableFolderStructure: true,
    galleryToCameraSwitchEnabled: false,
    isRestrictedExtensionJpgPngEnabled: true,
    enableImageEditing: false,
    locationRestrictive: false,
    hideCameraButtonInNeutral: false,
    hideGalleryButtonInNeutral: false,
    hasOnlyProfileTag: false,
    profileTagName: null,
    imageTagListJson: null,
    alreadyAddedImagesJson: null,
};


export default class App extends Component<Props> {
    constructor() {
        super();
        this.openNeon = this.openNeon.bind(this);
        this.prepareList = this.prepareList.bind(this);
        this.state = {
            images: [],
            alreadyAddedImages: []
        }

    }
    
    onEachLivePhotoClick = (response) => {
            console.log('Live Photo ==>',response);
    };
    
    componentDidMount(){
         //use it, if event for each live photo click is required
         NeonAndroid.addEventListener('livePhoto', this.onEachLivePhotoClick);
    }
    
    componentWillUnmount(){
         //required, if event for each live photo is added
         NeonAndroid.removeEventListener('livePhoto', this.onEachLivePhotoClick);
    }

    openNeon(position) {
        let params = {};
        switch (position) {
            case Constants.OPEN_NEUTRAL:
                params.profileTagName = 'Cover';
                params.hasOnlyProfileTag = true;
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openNeutral(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_CAMERA:
                params.cameraOrientation = 1;
                params.flashEnabled = true;
                params.cameraSwitchingEnabled = true;
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openCamera(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_CAMERA_PRIORITY:
                params.cameraOrientation = 1;
                params.flashEnabled = true;
                params.cameraSwitchingEnabled = true;
                params.tagEnabled = true;
                params.libraryMode = 1;
                params.numberOfPhotos = 2;
                params.cameraToGallerySwitchEnabled = true;
                params.imageTagListJson = JSON.stringify(imageTagList);
                NeonAndroid.openCamera(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_GALLERY_FOLDERS:
                params.galleryToCameraSwitchEnabled = false;
                params.numberOfPhotos = 0;
                params.enableFolderStructure = true;
                params.imageTagListJson = JSON.stringify(imageTagList);
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_GALLERY_FOLDERS_PRIORITY:
                params.galleryToCameraSwitchEnabled = true;
                params.numberOfPhotos = 0;
                params.enableFolderStructure = true;
                params.imageTagListJson = JSON.stringify(imageTagList);
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_GALLERY_FILES:
                params.galleryToCameraSwitchEnabled = false;
                params.numberOfPhotos = 2;
                params.enableFolderStructure = false;
                params.libraryMode = 1;
                params.galleryViewType = 0;
                params.tagEnabled = true;
                params.imageTagListJson = JSON.stringify(imageTagList);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_GALLERY_FILES_PRIORITY:
                params.galleryToCameraSwitchEnabled = true;
                params.numberOfPhotos = 0;
                params.galleryViewType = 0;
                params.enableFolderStructure = false;
                params.imageTagListJson = JSON.stringify(imageTagList);
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;

            case Constants.OPEN_GALLERY_HORIZONTAL:
                params.galleryToCameraSwitchEnabled = false;
                params.numberOfPhotos = 0;
                params.galleryViewType = 1;
                params.enableFolderStructure = false;
                params.imageTagListJson = JSON.stringify(imageTagList);
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_GALLERY_HORIZONTAL_PRIORITY:
                params.galleryToCameraSwitchEnabled = true;
                params.numberOfPhotos = 0;
                params.galleryViewType = 1;
                params.enableFolderStructure = false;
                params.imageTagListJson = JSON.stringify(imageTagList);
                params.alreadyAddedImagesJson = JSON.stringify(this.state.alreadyAddedImages);
                NeonAndroid.openGallery(JSON.stringify(params), (response) => this.prepareList(response));
                break;
            case Constants.OPEN_LIVE_PHOTOS:
                params.locationRestrictive = true;
                params.tagEnabled = true;
                params.imageTagListJson = JSON.stringify(imageTagList);
                NeonAndroid.openLivePhotos(JSON.stringify(params), (response) => this.prepareList(response));
                break;

        }
    }

    prepareList(response) {
        if (JSON.parse(response).imageCollection.length === 0) {
            this.setState({alreadyAddedImages: []});
            return;
        }
        let data = JSON.parse(response).imageCollection;
        this.setState({
            alreadyAddedImages: data,
            images: data
        });
    }

    renderItem({item, index}) {
        let imageUrl = '';
        if (item.filePath.toString().contains("//")) {
            imageUrl = item.filePath;
        } else {
            imageUrl = "file://" + item.filePath;
        }
        return (
            <View>
                <Image
                    style={{
                        alignSelf: 'center',
                        margin: 5,
                        width: 110,
                        height: 100,
                    }}
                    source={{uri: imageUrl}}
                />
            </View>

        )
    }


    render() {
        return (
            <ScrollView>
                <View style={styles.container}>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_NEUTRAL)}>
                        <Text style={styles.instructions}>
                            Neutral
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_CAMERA)}>
                        <Text style={styles.instructions}>
                            Camera
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_CAMERA_PRIORITY)}>
                        <Text style={styles.instructions}>
                            Camera Priority
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_FOLDERS)}>
                        <Text style={styles.instructions}>
                            Gallery(Folders)
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_FOLDERS_PRIORITY)}>
                        <Text style={styles.instructions}>
                            Gallery Priority(Folders)
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_FILES)}>
                        <Text style={styles.instructions}>
                            Gallery(Files)
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_FILES_PRIORITY)}>
                        <Text style={styles.instructions}>
                            Gallery Priority(Files)
                        </Text>
                    </TouchableNativeFeedback>

                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_HORIZONTAL)}>
                        <Text style={styles.instructions}>
                            Gallery(Horizontal)
                        </Text>
                    </TouchableNativeFeedback>
                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_GALLERY_HORIZONTAL_PRIORITY)}>
                        <Text style={styles.instructions}>
                            Gallery Priority(Horizontal)
                        </Text>
                    </TouchableNativeFeedback>

                    <TouchableNativeFeedback onPress={() => this.openNeon(Constants.OPEN_LIVE_PHOTOS)}>
                        <Text style={styles.instructions}>
                            Live Photos
                        </Text>
                    </TouchableNativeFeedback>

                    <FlatList
                        contentContainerStyle={styles.list}
                        data={this.state.images}
                        renderItem={this.renderItem}/>
                </View>
            </ScrollView>
        );
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#F5FCFF',
    },
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        alignSelf: 'stretch',
        backgroundColor: 'green',
        padding: 12,
        color: 'white',
        fontWeight: 'bold',
        fontSize: 16,
        marginTop: 10,
    },
    list: {
        justifyContent: 'center',
        flexDirection: 'row',
        flexWrap: 'wrap'
    }
});

let fileInfo = {
    dateTimeTaken: "1522229825513",
    fileCount: 0,
    filePath: "https://images.unsplash.com/photo-1441742917377-57f78ee0e582?h=1024",
    selected: false,
    source: "PHONE_GALLERY",
    type: "IMAGE",
    latitude: "",
    longitude: "",
    fileName: "",
    displayName: "",
    fileTag: {
        mandatory: false,
        numberOfPhotos: 1,
        tagId: "3",
        tagName: "Tag3",
        location: null,
        tagPreviewUrl: "https://----"
    }
};

Author:

  • Rajeev Kumar(rajeev15june@gmail.com)
1.8.4

5 years ago

1.8.3

5 years ago

1.8.2

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.9

5 years ago

1.7.8

5 years ago

1.7.7

5 years ago

1.7.6

5 years ago

1.7.5

5 years ago

1.7.4

5 years ago

1.7.3

5 years ago

1.7.2

5 years ago

1.7.1

5 years ago

1.7.0

5 years ago

1.6.9

5 years ago

1.6.8

5 years ago

1.6.7

5 years ago

1.6.6

5 years ago

1.6.5

5 years ago

1.6.4

5 years ago

1.6.3

5 years ago

1.6.2

5 years ago

1.6.1

5 years ago

1.6.0

6 years ago

1.5.5

6 years ago

1.5.4

6 years ago

1.5.3

6 years ago

1.5.2

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.7

6 years ago

1.4.6

6 years ago

1.4.5

6 years ago

1.4.4

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.4.1

6 years ago

1.4.0

6 years ago

1.3.9

6 years ago

1.3.8

6 years ago

1.3.7

6 years ago

1.3.6

6 years ago

1.3.5

6 years ago

1.3.3

6 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago