Skip to content

Commit 8c9f919

Browse files
committed
+ updated code to work with react native 26+
+ added merge as dependency
1 parent 32e79a7 commit 8c9f919

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,7 @@
2121
"email": "maxime.mezrahi@gmail.com",
2222
"url": "https://github.com/maxs15"
2323
},
24-
"dependencies": {}
24+
"dependencies": {
25+
"merge": "^1.2.0"
26+
}
2527
}

recorder.ios.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
var React = require('react-native');
2-
var {
3-
PropTypes,
1+
import React, { Component, PropTypes } from 'react';
2+
import {
43
StyleSheet,
54
requireNativeComponent,
65
NativeModules,
76
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+
}
2217
/******* STYLES **********/
2318

24-
var styles = StyleSheet.create({
19+
const styles = StyleSheet.create({
2520
wrapper: {
2621
flex: 1,
2722
backgroundColor: "transparent"
@@ -30,69 +25,73 @@ var styles = StyleSheet.create({
3025

3126
/******* RECORDER COMPONENT **********/
3227

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;
3437

35-
propTypes: {
38+
static propTypes = {
3639
config: PropTypes.object,
3740
device: PropTypes.string,
3841
onNewSegment: PropTypes.func
39-
},
40-
41-
getInitialState() {
42-
return {
43-
recording: false
44-
};
45-
},
42+
}
4643

4744
/*** PUBLIC METHODS ***/
4845

4946
// Start recording of the current session
5047
record() {
5148
if (this.state.recording) return;
52-
this.state.recording = true;
49+
this.setState({
50+
recording: true
51+
});
5352
NativeModules.RNRecorderManager.record();
54-
},
53+
}
5554

5655
// Capture a picture
5756
capture(callback) {
5857
NativeModules.RNRecorderManager.capture(callback);
59-
},
58+
}
6059

6160
// Pause recording of the current session
6261
pause() {
6362
if (!this.state.recording) return;
6463

6564
var onNewSegment = this.props.onNewSegment || function() {};
6665
NativeModules.RNRecorderManager.pause(onNewSegment);
67-
this.state.recording = false;
68-
},
66+
this.setState({
67+
recording: false
68+
})
69+
}
6970

7071
// Save the recording
7172
save(callback) {
7273
NativeModules.RNRecorderManager.save(callback);
73-
},
74+
}
7475

7576
// Remove last segment of the session
7677
removeLastSegment() {
7778
NativeModules.RNRecorderManager.removeLastSegment();
78-
},
79+
}
7980

8081
// Remove all segments of the session
8182
removeAllSegments() {
8283
NativeModules.RNRecorderManager.removeAllSegments();
83-
},
84+
}
8485

8586
// Remove segment at the specified index
8687
removeSegmentAtIndex(index) {
8788
NativeModules.RNRecorderManager.removeSegmentAtIndex(index);
88-
},
89+
}
8990

9091
/*** RENDER ***/
9192

9293
render() {
93-
94-
95-
var config = merge({
94+
const config = merge({
9695
autoSetVideoOrientation: false,
9796
flashMode: constants.SCFlashModeOff,
9897

@@ -126,9 +125,9 @@ var Recorder = React.createClass({
126125
quality: "HighestQuality" // HighestQuality || MediumQuality || LowQuality
127126
}
128127

129-
},this.props.config);
128+
}, this.props.config);
130129

131-
var nativeProps = merge({}, this.props, {
130+
const nativeProps = merge({}, this.props, {
132131
config: config,
133132
device: this.props.device || "front"
134133
});
@@ -139,11 +138,8 @@ var Recorder = React.createClass({
139138
</RNRecorder>
140139
);
141140
}
141+
}
142142

143-
});
144-
145-
var RNRecorder = requireNativeComponent('RNRecorder', Recorder);
143+
const RNRecorder = requireNativeComponent('RNRecorder', Recorder);
146144

147-
Recorder.constants = constants;
148145

149-
module.exports = Recorder;

0 commit comments

Comments
 (0)