Skip to content

Commit b13fcc5

Browse files
Matthew ThompsonMatthew Thompson
authored andcommitted
before adding init
1 parent 5e66b1b commit b13fcc5

11 files changed

+102
-86
lines changed

README.md

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
```
1515
import RNRK from 'react-native-replaykit'
1616
17-
RNRK.startRecording() // starts the recording
18-
19-
RNRK.stopRecording() // stops the recording and opens the preview/edit modal
17+
RKRK.getRecordings(recordings => console.log(recordings)) get all recordings stored in the app's Documents/Replays folder.
2018
2119
```
2220

@@ -30,28 +28,9 @@ RNRK.stopRecording() // stops the recording and opens the preview/edit modal
3028
3. In XCode, in the project navigator, select your project. Add `libRNReactNativeReplaykit.a` to your project's `Build Phases``Link Binary With Libraries`
3129
4. Run your project (`Cmd+R`)<
3230

33-
#### Android
34-
35-
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
36-
- Add `import com.reactlibrary.RNReactNativeReplaykitPackage;` to the imports at the top of the file
37-
- Add `new RNReactNativeReplaykitPackage()` to the list returned by the `getPackages()` method
38-
2. Append the following lines to `android/settings.gradle`:
39-
```
40-
include ':react-native-replaykit'
41-
project(':react-native-replaykit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-replaykit/android')
42-
```
43-
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
44-
```
45-
compile project(':react-native-replaykit')
46-
```
47-
48-
#### Windows
49-
[Read it! :D](https://github.com/ReactWindows/react-native)
50-
51-
1. In Visual Studio add the `RNReactNativeReplaykit.sln` in `node_modules/react-native-replaykit/windows/RNReactNativeReplaykit.sln` folder to their solution, reference from their app.
52-
2. Open up your `MainPage.cs` app
53-
- Add `using React.Native.Replaykit.RNReactNativeReplaykit;` to the usings at the top of the file
54-
- Add `new RNReactNativeReplaykitPackage()` to the `List<IReactPackage>` returned by the `Packages` method
31+
### Manual installation continued (required after manual installation or linking)
32+
33+
Create a swift file in your main project (if anyone knows a better way to get the auto generated swift build settings to show up, plese open an issue). If you delete this swift file or bridging header, the build settings needed will go away and build fail. 'Objecttive-C Generated Interface Header Name'.
5534

5635

5736
## Usage
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
// Copyright © 2017 Giridhar. All rights reserved.
77
//
88

9+
910
import Foundation
1011

11-
class ReplayFileUtil
12+
@objc public class ReplayFileUtil:NSObject
1213
{
13-
internal class func createReplaysFolder()
14+
class func createReplaysFolder()
1415
{
1516
// path to documents directory
1617
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first
@@ -19,18 +20,20 @@ class ReplayFileUtil
1920
let replayDirectoryPath = documentDirectoryPath.appending("/Replays")
2021
let fileManager = FileManager.default
2122
if !fileManager.fileExists(atPath: replayDirectoryPath) {
23+
print("Creating replays dir...")
2224
do {
2325
try fileManager.createDirectory(atPath: replayDirectoryPath,
2426
withIntermediateDirectories: false,
2527
attributes: nil)
28+
2629
} catch {
2730
print("Error creating Replays folder in documents dir: \(error)")
2831
}
2932
}
3033
}
3134
}
32-
33-
internal class func filePath(_ fileName: String) -> String
35+
36+
class func filePath(_ fileName: String) -> String
3437
{
3538
createReplaysFolder()
3639
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
@@ -39,14 +42,12 @@ class ReplayFileUtil
3942
return filePath
4043
}
4144

42-
internal class func fetchAllReplays() -> Array<URL>
45+
class func fetchAllReplays() -> Array<URL>
4346
{
4447
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
4548
let replayPath = documentsDirectory?.appendingPathComponent("/Replays")
4649
let directoryContents = try! FileManager.default.contentsOfDirectory(at: replayPath!, includingPropertiesForKeys: nil, options: [])
4750
return directoryContents
4851
}
49-
5052
}
5153

52-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Use this file to import your target's public headers that you would like to expose to Swift.
3+
//
4+

ios/RNReactNativeReplaykit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#endif
77

88
#import <ReplayKit/ReplayKit.h>
9+
//#import "RNReactNativeReplaykit-Swift.h"
10+
//@class ReplayFileUtil;
911

1012

1113
@interface RNReactNativeReplaykit : NSObject <RCTBridgeModule>

ios/RNReactNativeReplaykit.m

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11

22
#import "RNReactNativeReplaykit.h"
33
#import <React/RCTLog.h>
4-
// TODO: For storing the videos in app's documents
5-
//#define documentsDirectory [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
4+
5+
#import "RNReactNativeReplaykit-Swift.h"
66

77
@implementation RNReactNativeReplaykit
88

9+
910
- (dispatch_queue_t)methodQueue
1011
{
1112
return dispatch_get_main_queue();
1213
}
1314

1415
RCT_EXPORT_METHOD(startRecording)
1516
{
16-
self.screenRecorder = [RPScreenRecorder sharedRecorder];
17-
[self.screenRecorder startRecordingWithHandler:^(NSError * _Nullable error) {
18-
19-
}];
17+
[ReplayFileUtil createReplaysFolder];
18+
// [ScreenRecorder start]
19+
}
20+
21+
RCT_EXPORT_METHOD(getRecordings:(RCTResponseSenderBlock)callback)
22+
{
23+
NSArray *recordings = [ReplayFileUtil fetchAllReplays];
24+
callback(@[[NSNull null], recordings]);
2025
}
2126

2227
RCT_EXPORT_METHOD(stopRecording)
2328
{
24-
[self.screenRecorder stopRecordingWithHandler:^(RPPreviewViewController * _Nullable previewViewController, NSError * _Nullable error) {
25-
UIViewController *controller = [UIApplication sharedApplication].keyWindow.rootViewController;
26-
self.previewViewController = previewViewController;
27-
[controller presentViewController:self.previewViewController animated:true completion:nil];
28-
}];
2929
}
3030

3131
RCT_EXPORT_MODULE()

ios/RNReactNativeReplaykit.xcodeproj/project.pbxproj

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
52ECF4762146088800301CC6 /* ScreenRecordBridge.m in Sources */ = {isa = PBXBuildFile; fileRef = 52ECF4752146088800301CC6 /* ScreenRecordBridge.m */; };
10+
52ECF58021487E1500301CC6 /* FileUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ECF57F21487E1500301CC6 /* FileUtil.swift */; };
11+
52ECF5852148A73500301CC6 /* ScreenRecordCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ECF5842148A73500301CC6 /* ScreenRecordCoordinator.swift */; };
12+
52ECF5872148A74600301CC6 /* ScreenRecorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ECF5862148A74600301CC6 /* ScreenRecorder.swift */; };
13+
52ECF5892148A75700301CC6 /* WindowUtil.swift in Sources */ = {isa = PBXBuildFile; fileRef = 52ECF5882148A75700301CC6 /* WindowUtil.swift */; };
1114
B3E7B58A1CC2AC0600A0062D /* RNReactNativeReplaykit.m in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNReactNativeReplaykit.m */; };
1215
/* End PBXBuildFile section */
1316

@@ -25,9 +28,11 @@
2528

2629
/* Begin PBXFileReference section */
2730
134814201AA4EA6300B7C361 /* libRNReactNativeReplaykit.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNReactNativeReplaykit.a; sourceTree = BUILT_PRODUCTS_DIR; };
28-
52ECF4742146084400301CC6 /* ScreenRecord */ = {isa = PBXFileReference; lastKnownFileType = folder; path = ScreenRecord; sourceTree = "<group>"; };
29-
52ECF4752146088800301CC6 /* ScreenRecordBridge.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScreenRecordBridge.m; sourceTree = "<group>"; };
30-
52ECF4772146089A00301CC6 /* ScreenRecordBridge.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScreenRecordBridge.h; sourceTree = "<group>"; };
31+
52ECF57E21487E1400301CC6 /* RNReactNativeReplaykit-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNReactNativeReplaykit-Bridging-Header.h"; sourceTree = "<group>"; };
32+
52ECF57F21487E1500301CC6 /* FileUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileUtil.swift; sourceTree = "<group>"; };
33+
52ECF5842148A73500301CC6 /* ScreenRecordCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenRecordCoordinator.swift; sourceTree = "<group>"; };
34+
52ECF5862148A74600301CC6 /* ScreenRecorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenRecorder.swift; sourceTree = "<group>"; };
35+
52ECF5882148A75700301CC6 /* WindowUtil.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WindowUtil.swift; sourceTree = "<group>"; };
3136
B3E7B5881CC2AC0600A0062D /* RNReactNativeReplaykit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNReactNativeReplaykit.h; sourceTree = "<group>"; };
3237
B3E7B5891CC2AC0600A0062D /* RNReactNativeReplaykit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNReactNativeReplaykit.m; sourceTree = "<group>"; };
3338
/* End PBXFileReference section */
@@ -54,12 +59,14 @@
5459
58B511D21A9E6C8500147676 = {
5560
isa = PBXGroup;
5661
children = (
57-
52ECF4772146089A00301CC6 /* ScreenRecordBridge.h */,
58-
52ECF4752146088800301CC6 /* ScreenRecordBridge.m */,
59-
52ECF4742146084400301CC6 /* ScreenRecord */,
62+
52ECF5882148A75700301CC6 /* WindowUtil.swift */,
63+
52ECF5862148A74600301CC6 /* ScreenRecorder.swift */,
64+
52ECF5842148A73500301CC6 /* ScreenRecordCoordinator.swift */,
65+
52ECF57F21487E1500301CC6 /* FileUtil.swift */,
6066
B3E7B5881CC2AC0600A0062D /* RNReactNativeReplaykit.h */,
6167
B3E7B5891CC2AC0600A0062D /* RNReactNativeReplaykit.m */,
6268
134814211AA4EA7D00B7C361 /* Products */,
69+
52ECF57E21487E1400301CC6 /* RNReactNativeReplaykit-Bridging-Header.h */,
6370
);
6471
sourceTree = "<group>";
6572
};
@@ -94,6 +101,7 @@
94101
TargetAttributes = {
95102
58B511DA1A9E6C8500147676 = {
96103
CreatedOnToolsVersion = 6.1.1;
104+
LastSwiftMigration = 0940;
97105
};
98106
};
99107
};
@@ -120,7 +128,10 @@
120128
buildActionMask = 2147483647;
121129
files = (
122130
B3E7B58A1CC2AC0600A0062D /* RNReactNativeReplaykit.m in Sources */,
123-
52ECF4762146088800301CC6 /* ScreenRecordBridge.m in Sources */,
131+
52ECF5872148A74600301CC6 /* ScreenRecorder.swift in Sources */,
132+
52ECF5892148A75700301CC6 /* WindowUtil.swift in Sources */,
133+
52ECF58021487E1500301CC6 /* FileUtil.swift in Sources */,
134+
52ECF5852148A73500301CC6 /* ScreenRecordCoordinator.swift in Sources */,
124135
);
125136
runOnlyForDeploymentPostprocessing = 0;
126137
};
@@ -147,6 +158,7 @@
147158
CLANG_WARN_UNREACHABLE_CODE = YES;
148159
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
149160
COPY_PHASE_STRIP = NO;
161+
DEFINES_MODULE = YES;
150162
ENABLE_STRICT_OBJC_MSGSEND = YES;
151163
ENABLE_TESTABILITY = YES;
152164
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -167,7 +179,10 @@
167179
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
168180
MTL_ENABLE_DEBUG_INFO = YES;
169181
ONLY_ACTIVE_ARCH = YES;
182+
PRODUCT_MODULE_NAME = RNReactNativeReplaykit;
170183
SDKROOT = iphoneos;
184+
SWIFT_OBJC_BRIDGING_HEADER = "RNReactNativeReplaykit-Bridging-Header.h";
185+
SWIFT_PRECOMPILE_BRIDGING_HEADER = YES;
171186
};
172187
name = Debug;
173188
};
@@ -191,6 +206,7 @@
191206
CLANG_WARN_UNREACHABLE_CODE = YES;
192207
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
193208
COPY_PHASE_STRIP = YES;
209+
DEFINES_MODULE = YES;
194210
ENABLE_NS_ASSERTIONS = NO;
195211
ENABLE_STRICT_OBJC_MSGSEND = YES;
196212
GCC_C_LANGUAGE_STANDARD = gnu99;
@@ -203,40 +219,58 @@
203219
GCC_WARN_UNUSED_VARIABLE = YES;
204220
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
205221
MTL_ENABLE_DEBUG_INFO = NO;
222+
PRODUCT_MODULE_NAME = RNReactNativeReplaykit;
206223
SDKROOT = iphoneos;
224+
SWIFT_OBJC_BRIDGING_HEADER = "RNReactNativeReplaykit-Bridging-Header.h";
225+
SWIFT_PRECOMPILE_BRIDGING_HEADER = YES;
207226
VALIDATE_PRODUCT = YES;
208227
};
209228
name = Release;
210229
};
211230
58B511F01A9E6C8500147676 /* Debug */ = {
212231
isa = XCBuildConfiguration;
213232
buildSettings = {
233+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
234+
CLANG_ENABLE_MODULES = YES;
235+
DEFINES_MODULE = YES;
214236
HEADER_SEARCH_PATHS = (
215237
"$(inherited)",
216238
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
217239
"$(SRCROOT)/../../../React/**",
218240
"$(SRCROOT)/../../react-native/React/**",
219241
);
242+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
220243
LIBRARY_SEARCH_PATHS = "$(inherited)";
221244
OTHER_LDFLAGS = "-ObjC";
222245
PRODUCT_NAME = RNReactNativeReplaykit;
223246
SKIP_INSTALL = YES;
247+
SWIFT_OBJC_BRIDGING_HEADER = "RNReactNativeReplaykit-Bridging-Header.h";
248+
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
249+
SWIFT_PRECOMPILE_BRIDGING_HEADER = YES;
250+
SWIFT_VERSION = 3.0;
224251
};
225252
name = Debug;
226253
};
227254
58B511F11A9E6C8500147676 /* Release */ = {
228255
isa = XCBuildConfiguration;
229256
buildSettings = {
257+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
258+
CLANG_ENABLE_MODULES = YES;
259+
DEFINES_MODULE = YES;
230260
HEADER_SEARCH_PATHS = (
231261
"$(inherited)",
232262
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
233263
"$(SRCROOT)/../../../React/**",
234264
"$(SRCROOT)/../../react-native/React/**",
235265
);
266+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
236267
LIBRARY_SEARCH_PATHS = "$(inherited)";
237268
OTHER_LDFLAGS = "-ObjC";
238269
PRODUCT_NAME = RNReactNativeReplaykit;
239270
SKIP_INSTALL = YES;
271+
SWIFT_OBJC_BRIDGING_HEADER = "RNReactNativeReplaykit-Bridging-Header.h";
272+
SWIFT_PRECOMPILE_BRIDGING_HEADER = YES;
273+
SWIFT_VERSION = 3.0;
240274
};
241275
name = Release;
242276
};

ios/ScreenRecordBridge.h

Lines changed: 0 additions & 2 deletions
This file was deleted.

ios/ScreenRecordBridge.m

Lines changed: 0 additions & 7 deletions
This file was deleted.

ios/ScreenRecord/ScreenRecordCoordinator.swift renamed to ios/ScreenRecordCoordinator.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88

99
import Foundation
1010

11-
class ScreenRecordCoordinator: NSObject
11+
@objc class ScreenRecordCoordinator: NSObject
1212
{
1313
let viewOverlay = WindowUtil()
1414
let screenRecorder = ScreenRecorder()
1515
var recordCompleted:((Error?) ->Void)?
16-
16+
1717
override init()
1818
{
1919
super.init()
@@ -24,7 +24,7 @@ class ScreenRecordCoordinator: NSObject
2424

2525

2626
}
27-
27+
2828
func startRecording(withFileName fileName: String, recordingHandler: @escaping (Error?) -> Void,onCompletion: @escaping (Error?)->Void)
2929
{
3030
self.viewOverlay.show()
@@ -33,19 +33,19 @@ class ScreenRecordCoordinator: NSObject
3333
self.recordCompleted = onCompletion
3434
}
3535
}
36-
36+
3737
func stopRecording()
3838
{
3939
screenRecorder.stopRecording { (error) in
4040
self.viewOverlay.hide()
4141
self.recordCompleted?(error)
4242
}
4343
}
44-
44+
4545
class func listAllReplays() -> Array<URL>
4646
{
4747
return ReplayFileUtil.fetchAllReplays()
4848
}
49-
50-
49+
50+
5151
}

0 commit comments

Comments
 (0)