create TestRecorder iOS test app
This commit is contained in:
37
package/ios/TestRecorder/AppDelegate.swift
Normal file
37
package/ios/TestRecorder/AppDelegate.swift
Normal file
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// AppDelegate.swift
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 11/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
@main
|
||||
class AppDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
||||
// Override point for customization after application launch.
|
||||
return true
|
||||
}
|
||||
|
||||
// MARK: UISceneSession Lifecycle
|
||||
|
||||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
|
||||
// Called when a new scene session is being created.
|
||||
// Use this method to select a configuration to create the new scene with.
|
||||
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
|
||||
}
|
||||
|
||||
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
|
||||
// Called when the user discards a scene session.
|
||||
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
|
||||
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"platform" : "ios",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
6
package/ios/TestRecorder/Assets.xcassets/Contents.json
Normal file
6
package/ios/TestRecorder/Assets.xcassets/Contents.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
25
package/ios/TestRecorder/Base.lproj/LaunchScreen.storyboard
Normal file
25
package/ios/TestRecorder/Base.lproj/LaunchScreen.storyboard
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
|
||||
<dependencies>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="EHf-IW-A2E">
|
||||
<objects>
|
||||
<viewController id="01J-lp-oVM" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="53" y="375"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
</document>
|
51
package/ios/TestRecorder/Base.lproj/Main.storyboard
Normal file
51
package/ios/TestRecorder/Base.lproj/Main.storyboard
Normal file
@@ -0,0 +1,51 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="32700.99.1234" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
|
||||
<device id="retina6_12" orientation="portrait" appearance="light"/>
|
||||
<dependencies>
|
||||
<deployment identifier="iOS"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22685"/>
|
||||
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
||||
<capability name="System colors in document resources" minToolsVersion="11.0"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--View Controller-->
|
||||
<scene sceneID="tne-QT-ifu">
|
||||
<objects>
|
||||
<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="TestRecorder" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
|
||||
<rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="VWP-nN-U6K">
|
||||
<rect key="frame" x="157.33333333333334" y="722.66666666666663" width="78.333333333333343" height="34.333333333333371"/>
|
||||
<inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
|
||||
<state key="normal" title="Record"/>
|
||||
<buttonConfiguration key="configuration" style="filled" title="Record"/>
|
||||
<connections>
|
||||
<action selector="toggleRecord:" destination="BYZ-38-t0r" eventType="touchUpInside" id="63a-uH-hTe"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||
<constraints>
|
||||
<constraint firstItem="6Tk-OE-BBY" firstAttribute="bottom" secondItem="VWP-nN-U6K" secondAttribute="bottom" constant="61" id="0iW-h7-WDE"/>
|
||||
<constraint firstItem="VWP-nN-U6K" firstAttribute="centerX" secondItem="6Tk-OE-BBY" secondAttribute="centerX" id="yZb-ba-qfO"/>
|
||||
</constraints>
|
||||
</view>
|
||||
<connections>
|
||||
<outlet property="recordButton" destination="VWP-nN-U6K" id="gSk-uh-nDX"/>
|
||||
</connections>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
|
||||
</objects>
|
||||
<point key="canvasLocation" x="115" y="-27"/>
|
||||
</scene>
|
||||
</scenes>
|
||||
<resources>
|
||||
<systemColor name="systemBackgroundColor">
|
||||
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
||||
</systemColor>
|
||||
</resources>
|
||||
</document>
|
25
package/ios/TestRecorder/Info.plist
Normal file
25
package/ios/TestRecorder/Info.plist
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
<false/>
|
||||
<key>UISceneConfigurations</key>
|
||||
<dict>
|
||||
<key>UIWindowSceneSessionRoleApplication</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>Default Configuration</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
|
||||
<key>UISceneStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
15
package/ios/TestRecorder/ReactStubs.h
Normal file
15
package/ios/TestRecorder/ReactStubs.h
Normal file
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// ReactStubs.h
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 12/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
@interface UIView (React)
|
||||
|
||||
- (void)didSetProps:(NSArray<NSString *> *)changedProps;
|
||||
|
||||
@end
|
17
package/ios/TestRecorder/ReactStubs.m
Normal file
17
package/ios/TestRecorder/ReactStubs.m
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// ReactStubs.m
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 12/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ReactStubs.h"
|
||||
|
||||
@implementation UIView (React)
|
||||
|
||||
- (void)didSetProps:(__unused NSArray<NSString *> *)changedProps
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
82
package/ios/TestRecorder/ReactStubs.swift
Normal file
82
package/ios/TestRecorder/ReactStubs.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// ReactStubs.swift
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 11/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
|
||||
enum RCTLogLevel: String {
|
||||
case trace
|
||||
case info
|
||||
case warning
|
||||
case error
|
||||
}
|
||||
|
||||
enum RCTLogSource {
|
||||
case native
|
||||
}
|
||||
|
||||
func RCTDefaultLogFunction(_ level: RCTLogLevel, _ source: RCTLogSource, _ file: String, _ line: NSNumber, _ message: String) {
|
||||
print(level.rawValue, "-", message)
|
||||
}
|
||||
|
||||
typealias RCTDirectEventBlock = (Any?) -> Void
|
||||
typealias RCTPromiseResolveBlock = (Any?) -> Void
|
||||
typealias RCTPromiseRejectBlock = (String, String, NSError?) -> Void
|
||||
typealias RCTResponseSenderBlock = (Any) -> Void
|
||||
|
||||
func NSNull() -> [String: String] {
|
||||
return [:]
|
||||
}
|
||||
|
||||
|
||||
func makeReactError(_ cameraError: CameraError, cause: NSError?) -> [String: Any] {
|
||||
var causeDictionary: [String: Any]?
|
||||
if let cause = cause {
|
||||
causeDictionary = [
|
||||
"cause": "\(cause.domain): \(cause.code) \(cause.description)",
|
||||
"userInfo": cause.userInfo
|
||||
]
|
||||
}
|
||||
return [
|
||||
"error": "\(cameraError.code): \(cameraError.message)",
|
||||
"extra": [
|
||||
"code": cameraError.code,
|
||||
"message": cameraError.message,
|
||||
"cause": causeDictionary ?? NSNull(),
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
func makeReactError(_ cameraError: CameraError) -> [String: Any] {
|
||||
return makeReactError(cameraError, cause: nil)
|
||||
}
|
||||
|
||||
|
||||
class RCTFPSGraph: UIView {
|
||||
convenience init(frame: CGRect, color: UIColor) {
|
||||
self.init(frame: frame)
|
||||
}
|
||||
|
||||
func onTick(_ tick: CFTimeInterval) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func RCTTempFilePath(_ ext: String, _ error: ErrorPointer) -> String? {
|
||||
let directory = NSTemporaryDirectory().appending("ReactNative")
|
||||
let fm = FileManager.default
|
||||
if fm.fileExists(atPath: directory) {
|
||||
try! fm.removeItem(atPath: directory)
|
||||
}
|
||||
if !fm.fileExists(atPath: directory) {
|
||||
try! fm.createDirectory(atPath: directory, withIntermediateDirectories: true)
|
||||
}
|
||||
return directory
|
||||
.appending("/").appending(UUID().uuidString)
|
||||
.appending(".").appending(ext)
|
||||
}
|
53
package/ios/TestRecorder/SceneDelegate.swift
Normal file
53
package/ios/TestRecorder/SceneDelegate.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// SceneDelegate.swift
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 11/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
|
||||
|
||||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
||||
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
|
||||
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
|
||||
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
|
||||
guard let _ = (scene as? UIWindowScene) else { return }
|
||||
}
|
||||
|
||||
func sceneDidDisconnect(_ scene: UIScene) {
|
||||
// Called as the scene is being released by the system.
|
||||
// This occurs shortly after the scene enters the background, or when its session is discarded.
|
||||
// Release any resources associated with this scene that can be re-created the next time the scene connects.
|
||||
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead).
|
||||
}
|
||||
|
||||
func sceneDidBecomeActive(_ scene: UIScene) {
|
||||
// Called when the scene has moved from an inactive state to an active state.
|
||||
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive.
|
||||
}
|
||||
|
||||
func sceneWillResignActive(_ scene: UIScene) {
|
||||
// Called when the scene will move from an active state to an inactive state.
|
||||
// This may occur due to temporary interruptions (ex. an incoming phone call).
|
||||
}
|
||||
|
||||
func sceneWillEnterForeground(_ scene: UIScene) {
|
||||
// Called as the scene transitions from the background to the foreground.
|
||||
// Use this method to undo the changes made on entering the background.
|
||||
}
|
||||
|
||||
func sceneDidEnterBackground(_ scene: UIScene) {
|
||||
// Called as the scene transitions from the foreground to the background.
|
||||
// Use this method to save data, release shared resources, and store enough scene-specific state information
|
||||
// to restore the scene back to its current state.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
6
package/ios/TestRecorder/TestRecorder-Bridging-Header.h
Normal file
6
package/ios/TestRecorder/TestRecorder-Bridging-Header.h
Normal file
@@ -0,0 +1,6 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
|
||||
#import "ReactStubs.h"
|
104
package/ios/TestRecorder/ViewController.swift
Normal file
104
package/ios/TestRecorder/ViewController.swift
Normal file
@@ -0,0 +1,104 @@
|
||||
//
|
||||
// ViewController.swift
|
||||
// TestRecorder
|
||||
//
|
||||
// Created by Rafael Bastos on 11/07/2024.
|
||||
// Copyright © 2024 mrousavy. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import AVFoundation
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var recordButton: UIButton!
|
||||
|
||||
let cameraView = CameraView()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
cameraView.translatesAutoresizingMaskIntoConstraints = false;
|
||||
view.insertSubview(cameraView, at: 0)
|
||||
NSLayoutConstraint.activate([
|
||||
cameraView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
cameraView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
cameraView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
cameraView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
recordButton.isHidden = true
|
||||
cameraView.onInitialized = { _ in
|
||||
DispatchQueue.main.async {
|
||||
self.recordButton.isHidden = false
|
||||
}
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
await requestAuthorizations()
|
||||
|
||||
cameraView.photo = true
|
||||
cameraView.video = true
|
||||
cameraView.audio = true
|
||||
cameraView.isActive = true
|
||||
cameraView.cameraId = getCameraDeviceId() as NSString?
|
||||
cameraView.didSetProps([])
|
||||
}
|
||||
}
|
||||
|
||||
func isAuthorized(for mediaType: AVMediaType) async -> Bool {
|
||||
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
||||
var isAuthorized = status == .authorized
|
||||
if status == .notDetermined {
|
||||
isAuthorized = await AVCaptureDevice.requestAccess(for: mediaType)
|
||||
}
|
||||
return isAuthorized
|
||||
}
|
||||
|
||||
|
||||
func requestAuthorizations() async {
|
||||
guard await isAuthorized(for: .video) else { return }
|
||||
guard await isAuthorized(for: .audio) else { return }
|
||||
// Set up the capture session.
|
||||
}
|
||||
|
||||
private func getCameraDeviceId() -> String? {
|
||||
let deviceTypes: [AVCaptureDevice.DeviceType] = [
|
||||
.builtInWideAngleCamera
|
||||
]
|
||||
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: .back)
|
||||
|
||||
let device = discoverySession.devices.first
|
||||
|
||||
return device?.uniqueID
|
||||
}
|
||||
|
||||
@IBAction
|
||||
func toggleRecord(_ button: UIButton) {
|
||||
if button.title(for: .normal) == "Stop" {
|
||||
|
||||
cameraView.stopRecording(promise: Promise(
|
||||
resolver: { result in
|
||||
print("result")
|
||||
}, rejecter: { code, message, cause in
|
||||
print("error")
|
||||
}))
|
||||
|
||||
button.setTitle("Record", for: .normal)
|
||||
button.configuration = .filled()
|
||||
|
||||
} else {
|
||||
cameraView.startRecording(
|
||||
options: [
|
||||
"videoCodec": "h265",
|
||||
]) { callback in
|
||||
print("callback", callback)
|
||||
}
|
||||
|
||||
button.setTitle("Stop", for: .normal)
|
||||
button.configuration = .bordered()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user