Skip to content

Commit

Permalink
feat: 🎸 video preview
Browse files Browse the repository at this point in the history
  • Loading branch information
tomokisun committed Dec 27, 2023
1 parent 52e5f9b commit 596209b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
10 changes: 9 additions & 1 deletion Packages/FlyCam/Sources/CameraFeature/Camera.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import CameraRecordFeature
import CameraResultFeature
import ComposableArchitecture
import FeedbackGeneratorClient
import Photos
import SwiftUI

@Reducer
Expand Down Expand Up @@ -47,6 +48,13 @@ public struct CameraLogic {
state.child = .result(
CameraResultLogic.State(altitude: altitude, videoURL: videoURL)
)
PHPhotoLibrary.shared().performChanges({
PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: videoURL)
}) { _, error in
if let error = error {
print("PHPhotoLibrary.shared().performChanges: \(error.localizedDescription)")
}
}
return .none

case .child(.result(.sendButtonTapped)):
Expand Down Expand Up @@ -101,7 +109,7 @@ public struct CameraView: View {
)
}
}
.navigationTitle("Camera")
.navigationTitle("FlyCam")
.navigationBarTitleDisplayMode(.inline)
.task { await store.send(.onTask).finish() }
.onAppear { store.send(.onAppear) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"sourceLanguage" : "en",
"strings" : {
"Camera" : {
"FlyCam" : {

}
},
Expand Down
16 changes: 16 additions & 0 deletions Packages/FlyCam/Sources/CameraResultFeature/CALayerView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import SwiftUI

struct CALayerView: UIViewControllerRepresentable {
var caLayer: CALayer

func makeUIViewController(context: Context) -> UIViewController {
let viewController = UIViewController()
viewController.view.layer.addSublayer(caLayer)
caLayer.frame = viewController.view.layer.frame
return viewController
}

func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
caLayer.frame = uiViewController.view.layer.frame
}
}
14 changes: 1 addition & 13 deletions Packages/FlyCam/Sources/CameraResultFeature/CameraResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public struct CameraResultView: View {
public var body: some View {
WithViewStore(store, observe: { $0 }) { viewStore in
VStack(spacing: 24) {
VideoPlayer(player: viewStore.player)
CALayerView(caLayer: AVPlayerLayer(player: viewStore.player))
.aspectRatio(3 / 4, contentMode: .fill)
.frame(width: UIScreen.main.bounds.width)
.clipShape(RoundedRectangle(cornerRadius: 24))
Expand All @@ -89,15 +89,3 @@ public struct CameraResultView: View {
}
}
}

#Preview {
CameraResultView(
store: .init(
initialState: CameraResultLogic.State(
altitude: 1.0,
videoURL: .applicationDirectory
),
reducer: { CameraResultLogic() }
)
)
}

0 comments on commit 596209b

Please sign in to comment.