1
- var React = require ( 'react-native' ) ;
2
- var {
3
- PropTypes,
1
+ import React , { Component , PropTypes } from 'react' ;
2
+ import {
4
3
StyleSheet ,
5
4
requireNativeComponent ,
6
5
NativeModules ,
7
6
View ,
8
- merge
9
- } = React ;
10
- merge = merge || require ( 'merge' ) ;
11
-
12
- /******* ENUM **********/
13
-
14
- var constants = {
15
- // Flash enum
16
- SCFlashModeOff : 0 ,
17
- SCFlashModeOn : 1 ,
18
- SCFlashModeAuto : 2 ,
19
- SCFlashModeLight : 3
20
- } ;
21
-
7
+ } from 'react-native' ;
8
+ import merge from 'merge' ;
9
+
10
+ const constants = {
11
+ // Flash enum
12
+ SCFlashModeOff : 0 ,
13
+ SCFlashModeOn : 1 ,
14
+ SCFlashModeAuto : 2 ,
15
+ SCFlashModeLight : 3
16
+ }
22
17
/******* STYLES **********/
23
18
24
- var styles = StyleSheet . create ( {
19
+ const styles = StyleSheet . create ( {
25
20
wrapper : {
26
21
flex : 1 ,
27
22
backgroundColor : "transparent"
@@ -30,69 +25,73 @@ var styles = StyleSheet.create({
30
25
31
26
/******* RECORDER COMPONENT **********/
32
27
33
- var Recorder = React . createClass ( {
28
+ export default class Recorder extends Component {
29
+ constructor ( props ) {
30
+ super ( props )
31
+ this . state = {
32
+ recording : false
33
+ }
34
+ }
35
+
36
+ static constants = constants ;
34
37
35
- propTypes : {
38
+ static propTypes = {
36
39
config : PropTypes . object ,
37
40
device : PropTypes . string ,
38
41
onNewSegment : PropTypes . func
39
- } ,
40
-
41
- getInitialState ( ) {
42
- return {
43
- recording : false
44
- } ;
45
- } ,
42
+ }
46
43
47
44
/*** PUBLIC METHODS ***/
48
45
49
46
// Start recording of the current session
50
47
record ( ) {
51
48
if ( this . state . recording ) return ;
52
- this . state . recording = true ;
49
+ this . setState ( {
50
+ recording : true
51
+ } ) ;
53
52
NativeModules . RNRecorderManager . record ( ) ;
54
- } ,
53
+ }
55
54
56
55
// Capture a picture
57
56
capture ( callback ) {
58
57
NativeModules . RNRecorderManager . capture ( callback ) ;
59
- } ,
58
+ }
60
59
61
60
// Pause recording of the current session
62
61
pause ( ) {
63
62
if ( ! this . state . recording ) return ;
64
63
65
64
var onNewSegment = this . props . onNewSegment || function ( ) { } ;
66
65
NativeModules . RNRecorderManager . pause ( onNewSegment ) ;
67
- this . state . recording = false ;
68
- } ,
66
+ this . setState ( {
67
+ recording : false
68
+ } )
69
+ }
69
70
70
71
// Save the recording
71
72
save ( callback ) {
72
73
NativeModules . RNRecorderManager . save ( callback ) ;
73
- } ,
74
+ }
74
75
75
76
// Remove last segment of the session
76
77
removeLastSegment ( ) {
77
78
NativeModules . RNRecorderManager . removeLastSegment ( ) ;
78
- } ,
79
+ }
79
80
80
81
// Remove all segments of the session
81
82
removeAllSegments ( ) {
82
83
NativeModules . RNRecorderManager . removeAllSegments ( ) ;
83
- } ,
84
+ }
84
85
85
86
// Remove segment at the specified index
86
87
removeSegmentAtIndex ( index ) {
87
88
NativeModules . RNRecorderManager . removeSegmentAtIndex ( index ) ;
88
- } ,
89
+ }
89
90
90
91
/*** RENDER ***/
91
92
92
93
render ( ) {
93
-
94
-
95
- var config = merge ( {
94
+ const config = merge ( {
96
95
autoSetVideoOrientation : false ,
97
96
flashMode : constants . SCFlashModeOff ,
98
97
@@ -126,9 +125,9 @@ var Recorder = React.createClass({
126
125
quality : "HighestQuality" // HighestQuality || MediumQuality || LowQuality
127
126
}
128
127
129
- } , this . props . config ) ;
128
+ } , this . props . config ) ;
130
129
131
- var nativeProps = merge ( { } , this . props , {
130
+ const nativeProps = merge ( { } , this . props , {
132
131
config : config ,
133
132
device : this . props . device || "front"
134
133
} ) ;
@@ -139,11 +138,8 @@ var Recorder = React.createClass({
139
138
</ RNRecorder >
140
139
) ;
141
140
}
141
+ }
142
142
143
- } ) ;
144
-
145
- var RNRecorder = requireNativeComponent ( 'RNRecorder' , Recorder ) ;
143
+ const RNRecorder = requireNativeComponent ( 'RNRecorder' , Recorder ) ;
146
144
147
- Recorder . constants = constants ;
148
145
149
- module . exports = Recorder ;
0 commit comments