Skip to content

Commit 6193d9b

Browse files
committed
Add version 2.3.0
1 parent 16794a4 commit 6193d9b

File tree

5 files changed

+132
-15
lines changed

5 files changed

+132
-15
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [2.3.0]
2+
3+
### Added
4+
5+
* Added `VideoEditorModal` component that can be used instead of the `VESDK.openEditor` function to modally present a video editor.
6+
17
## [2.2.2]
28

39
### Fixed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
<a href="https://npmjs.org/package/react-native-videoeditorsdk">
88
<img src="https://img.shields.io/npm/v/react-native-videoeditorsdk.svg" alt="NPM version">
99
</a>
10+
<a href="https://npmjs.org/package/react-native-videoeditorsdk">
11+
<img src="https://img.shields.io/badge/platforms-android%20|%20ios-lightgrey.svg" alt="Platform support">
12+
</a>
1013
<a href="http://twitter.com/VideoEditorSDK">
1114
<img src="https://img.shields.io/badge/twitter-@VideoEditorSDK-blue.svg?style=flat" alt="Twitter">
1215
</a>
@@ -119,7 +122,7 @@ yarn react-native link
119122
Import the module in your `App.js`:
120123

121124
```js
122-
import {VESDK, Configuration} from 'react-native-videoeditorsdk';
125+
import {VESDK, VideoEditorModal, Configuration} from 'react-native-videoeditorsdk';
123126
```
124127

125128
Unlock VideoEditor SDK with a license file:
@@ -134,6 +137,12 @@ Open the editor with a video:
134137
VESDK.openEditor(require('./video.mp4'));
135138
```
136139

140+
Or use the component to open the editor:
141+
142+
```jsx
143+
<VideoEditorModal visible={true} video={require('./video.mp4')}/>
144+
```
145+
137146
Please see the [code documentation](./index.d.ts) for more details and additional [customization and configuration options](./configuration.ts).
138147

139148
For configuring and customizing VideoEditor SDK beyond these options exposed to JavaScript the iOS bridge provides an [interface for native customization](./ios/RNVideoEditorSDK.h). Please refer to [our documentation](https://docs.videoeditorsdk.com?utm_campaign=Projects&utm_source=Github&utm_medium=VESDK&utm_content=React-Native) for more details on native customization.

index.d.ts

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Configuration} from './configuration';
1+
import { Component } from 'react';
2+
import { Configuration } from './configuration';
23

34
declare class VESDK {
45
/**
@@ -8,7 +9,7 @@ declare class VESDK {
89
* loading videos with `require('./video.mp4')` for debug builds static video assets will be
910
* resolved to remote URLs served by the development packager.
1011
*
11-
* @param {string | {uri: string} | number} videoSource The source of the video to be edited.
12+
* @param {string | {uri: string} | number} video The source of the video to be edited.
1213
* Can be either an URI (local only), an object with a member `uri`, or an asset reference
1314
* which can be optained by, e.g., `require('./video.mp4')` as `number`.
1415
* @param {Configuration} configuration The configuration used to initialize the editor.
@@ -23,7 +24,7 @@ declare class VESDK {
2324
* `null` is returned instead.
2425
*/
2526
static openEditor(
26-
videoSource: string | {uri: string} | number,
27+
video: string | {uri: string} | number,
2728
configuration: Configuration,
2829
serialization: object
2930
): Promise<{image: string, hasChanges: boolean, serialization: object}>
@@ -50,5 +51,74 @@ declare class VESDK {
5051
): Configuration
5152
}
5253

53-
export {VESDK};
54+
/**
55+
* Props for the `VideoEditorModal` component.
56+
*/
57+
interface VideoEditorModalProps {
58+
/**
59+
* This prop determines whether your modal is visible.
60+
*/
61+
visible: boolean;
62+
63+
/**
64+
* This prop determines the source of the video to be edited.
65+
* Can be either an URI (local only), an object with a member `uri`, or an asset reference
66+
* which can be optained by, e.g., `require('./video.mp4')` as `number`.
67+
*
68+
* @note Edited videos from remote resources can be previewed in the editor but their export will
69+
* fail! Remote video resources are currently supported for debugging purposes only, e.g., when
70+
* loading videos with `require('./video.mp4')` for debug builds static video assets will be
71+
* resolved to remote URLs served by the development packager.
72+
*/
73+
video: string | {uri: string} | number;
74+
75+
/**
76+
* This prop determines the configuration used to initialize the editor.
77+
*/
78+
configuration?: Configuration;
79+
80+
/**
81+
* This prop determines the serialization used to initialize the editor. This
82+
* restores a previous state of the editor by re-applying all modifications to the loaded
83+
* video.
84+
*/
85+
serialization?: object;
86+
87+
/**
88+
* This prop determines the callback function that will be called when the user exported a video.
89+
*
90+
* The object passed to this callback includes the edited `video`, an indicator (`hasChanges`) whether
91+
* the input video was modified at all, and all modifications (`serialization`) applied to the input video
92+
* if `export.serialization.enabled` of the `configuration` prop was set.
93+
*/
94+
onExport: ({video: string, hasChanges: boolean, serialization: object}) => void;
95+
96+
/**
97+
* This prop determines the callback function that will be called when the user dissmisses the editor without
98+
* exporting a video.
99+
*/
100+
onCancel?: () => void;
101+
102+
/**
103+
* This prop determines the callback function that will be called when an error occurs.
104+
*/
105+
onError?: (error: Error) => void;
106+
}
107+
108+
/**
109+
* State for the `VideoEditorModal` component.
110+
*/
111+
interface VideoEditorModalState {
112+
/**
113+
* This state determines whether the modal is visible.
114+
*/
115+
visible: boolean;
116+
}
117+
118+
/**
119+
* A component that wraps the `VESDK.openEditor` function to modally present a video editor.
120+
*/
121+
declare class VideoEditorModal extends Component<VideoEditorModalProps, VideoEditorModalState> {}
122+
123+
export { VESDK, VideoEditorModal };
54124
export * from './configuration';

index.js

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import {NativeModules, Image, Platform} from 'react-native';
2-
import {createDefaultConfiguration, Configuration} from './configuration';
1+
import { Component } from 'react';
2+
import { NativeModules, Image, Platform } from 'react-native';
3+
import { Configuration, createDefaultConfiguration } from './configuration';
34

4-
const {RNVideoEditorSDK} = NativeModules;
5+
const { RNVideoEditorSDK } = NativeModules;
56

67
function resolveStaticAsset(assetSource, extractURI = true) {
78
const resolvedSource = Image.resolveAssetSource(assetSource);
@@ -94,7 +95,7 @@ class VESDK {
9495
* loading videos with `require('./video.mp4')` for debug builds static video assets will be
9596
* resolved to remote URLs served by the development packager.
9697
*
97-
* @param {string | {uri: string} | number} videoSource The source of the video to be edited.
98+
* @param {string | {uri: string} | number} video The source of the video to be edited.
9899
* Can be either an URI (local only), an object with a member `uri`, or an asset reference
99100
* which can be optained by, e.g., `require('./video.mp4')` as `number`.
100101
* @param {Configuration} configuration The configuration used to initialize the editor.
@@ -108,13 +109,13 @@ class VESDK {
108109
* of the `configuration` was set. If the editor is dismissed without exporting the edited video
109110
* `null` is returned instead.
110111
*/
111-
static openEditor(videoSource, configuration = null, serialization = null) {
112+
static openEditor(video, configuration = null, serialization = null) {
112113
resolveStaticAssets(configuration)
113-
const video = resolveStaticAsset(videoSource, Platform.OS == 'android');
114+
const source = resolveStaticAsset(video, Platform.OS == 'android');
114115
if (Platform.OS == 'android') {
115-
return RNVideoEditorSDK.present(video, configuration, serialization != null ? JSON.stringify(serialization) : null);
116+
return RNVideoEditorSDK.present(source, configuration, serialization != null ? JSON.stringify(serialization) : null);
116117
} else {
117-
return RNVideoEditorSDK.present(video, configuration, serialization);
118+
return RNVideoEditorSDK.present(source, configuration, serialization);
118119
}
119120
}
120121

@@ -145,5 +146,36 @@ class VESDK {
145146
}
146147
}
147148

148-
export {VESDK};
149+
class VideoEditorModal extends Component {
150+
state = {
151+
visible: false
152+
}
153+
154+
static getDerivedStateFromProps = (props, state) => {
155+
const { video, configuration, serialization, onExport, onCancel, onError } = props;
156+
if (props.visible && !state.visible) {
157+
VESDK.openEditor(video, configuration, serialization).then(result => {
158+
if (result !== null) {
159+
onExport(result);
160+
} else {
161+
if (onCancel) {
162+
onCancel();
163+
}
164+
}
165+
}).catch((error) => {
166+
if (onError) {
167+
onError(error);
168+
}
169+
});
170+
}
171+
172+
return ({ visible: props.visible })
173+
}
174+
175+
render() {
176+
return null;
177+
}
178+
}
179+
180+
export { VESDK, VideoEditorModal };
149181
export * from './configuration';

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-videoeditorsdk",
33
"title": "React Native module for VideoEditor SDK",
4-
"version": "2.2.2",
4+
"version": "2.3.0",
55
"description": "A React Native module for VideoEditor SDK. Integrate the video editor into your own HTML5, iOS or Android app - in minutes!",
66
"main": "index.js",
77
"typings": "index.d.ts",

0 commit comments

Comments
 (0)