react-native-reusable-code:
imagePicker
actionSheet
audio
documentPicker module
method
arguments
description
launchImageLibrary
{ height?: number, width?: number}
- optional
calls default phone gallery; height
and width
params (if provided) will be set for cropping area; returns Promise
;
launchCamera
{ height?: number, width?: number}
- optional
calls default phone camera; height
and width
params (if provided) will be set for cropping area; returns Promise
;
open
{ cameraLabel: string, galleryLabel: string, cancelLabel: string, onSelect: (base64: string) => {}, options?: { height?: number, width?: number}}
Opens actionSheet
with 3 buttons (Camera, Gallery, Cancel);
Install react-native-permissions , react-native-image-crop-picker and @yfuks/react-native-action-sheet
Copy imagePicker.js
to your project;
Copy actionSheet.js
to your project;
Import ImagePicker from 'src/imagePicker.js'
;
Call one of supported methods;
launchImageLibrary
method:
ImagePicker
.launchImageLibrary({width: 200, height: 200})
.then((base64: string) => {})
launchCamera
method:
ImagePicker
.launchCamera({width: 200, height: 200})
.then((base64: string) => {})
open
method:
ImagePicker.open({
cameraLabel: "Open Camera",
galleryLabel: "Open Gallery",
cancelLabel: "Cancel",
onSelect: (base64string) => {}
});
method
arguments
description
show
Array<{ label: string, onPress: Function, isCancel?: boolean }>
calls default phone gallery; height
and width
params (if provided) will be set for cropping area;
Install @yfuks/react-native-action-sheet
Copy actionSheet.js
to your project;
Import ActionSheet from 'src/actionSheet.js'
;
Call show
method with supported arguments;
show
method:
const options = [
{
label: props.cameraLabel,
onPress: () => {}
},
{
label: props.galleryLabel,
onPress: () => {}
},
{
label: props.cancelLabel,
onPress: () => {},
isCancel: true,
},
];
ActionSheet.show(options);
method
arguments
description
onStartRecord
{ callback: (err: string, path: string) => void }
starts recording audio to a file, by default record.mp4;
onStopRecord
{ callback: (err: string) => void }
stop recording audio;
onStartPlay
{ path: string }
starts play audio from url or local file; return Promise
onPausePlay
{ }
Pause the player;
onStopPlay
{ }
Stops the player and removes the listener;
Install react-native-audio-recorder-player
Install react-native-audio-toolkit
Copy audio.js
to your project;
Import import AudioRecorder from 'src/audio';
Call onStartRecord
method with supported arguments;
Call onStopRecord
method with supported arguments;
Call onStartPlay
method with supported arguments;
Call onPausePlay
method with supported arguments;
Call onStopPlay
method with supported arguments;
initial for use AudioRecorder:
audioRecorder = new AudioRecorder();
onStartRecord
method:
this.audioRecorder.onStartRecord((err, filename) => {
if (err) {
console.log(err);
}
this.setState(() => ({ filename }));
});
onStopRecord
method:
this.audioRecorder.onStopRecord((err) => {
if (err) {
console.log("error stop recording", err);
}
});
onStartPlay
method:
this.audioRecorder.onStartPlay("https://somelink/record.mp4");
this.audioRecorder.onStartPlay("file:///sdcard/record.mp4");
onPausePlay
method:
this.audioRecorder.onPausePlay();
onStopPlay
method:
this.audioRecorder.onStopPlay();
documentPicker.js methods:
method
arguments
description
checkType
type: string
checks if provided type
is in list of possible extensions (listed in attachment.config.js ); returns boolean
;
getType
name: string
return mime type for provided name
; returns string
; uses react-native-mime-types v "2.2.1" ;
getFileName
url: string
return filename for provided url
; returns string
;
How to use documentPicker.js
:
Install react-native-document-picker , react-native-doc-viewer and react-native-mime-types
Copy documentPicker
folder to your project;
Import DocumentPicker from 'src/documentPicker/documentPicker'
;
Call one of supported methods;
init
method:
DocumentPicker
.init()
.then((res: {
type: string,
fileName: string,
uri: string,
data?: {},
fileSize: number
}) => {})
openFile
method:
DocumentPicker
.openFile({
uri,
fileName,
type
})
How to use file.helper.js
:
Install react-native-mime-types
Copy documentPicker
folder to your project;
Import * as FileHelper from 'src/documentPicker/file.helper'
;
Call one of supported methods;
checkType
method:
FileHelper
.checkType("image/jpeg"); // boolean here
getType
method:
FileHelper
.getType("image.jpeg"); // `image/jpeg` here
getFileName
method:
FileHelper
.getFileName("file:///folder1/folder2/image.jpeg"); // `image.jpeg` here