Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 capture #28

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Packages/FlyCam/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let package = Package(
.library(name: "CameraFeature", targets: ["CameraFeature"]),
.library(name: "CameraRecordFeature", targets: ["CameraFeature"]),
.library(name: "CameraResultFeature", targets: ["CameraFeature"]),
.library(name: "CaptureFeature", targets: ["CaptureFeature"]),
.library(name: "Constants", targets: ["Constants"]),
.library(name: "DeleteAccountFeature", targets: ["DeleteAccountFeature"]),
.library(name: "DisplayNameEditFeature", targets: ["DisplayNameEditFeature"]),
Expand Down Expand Up @@ -75,6 +76,12 @@ let package = Package(
.product(name: "AVPlayerNotificationClient", package: "SDK"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "CaptureFeature", dependencies: [
.product(name: "AnalyticsClient", package: "SDK"),
.product(name: "FeedbackGeneratorClient", package: "SDK"),
.product(name: "AVPlayerNotificationClient", package: "SDK"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
]),
.target(name: "Constants"),
.target(name: "DeleteAccountFeature", dependencies: [
"Styleguide",
Expand Down
97 changes: 97 additions & 0 deletions Packages/FlyCam/Sources/CaptureFeature/CameraToolBarCapture.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import ComposableArchitecture
import SwiftUI

@Reducer
public struct ToolBarRecordingLogic {
public init() {}

public struct State: Equatable {
var isRecording = false
public init() {}
}

public enum Action {
case onTask
case captureButtonTapped
case delegate(Delegate)

public enum Delegate: Equatable {
case startRecording
case stopRecording
}
}

public var body: some Reducer<State, Action> {
Reduce<State, Action> { state, action in
switch action {
case .onTask:
return .none

case .captureButtonTapped:
defer {
state.isRecording.toggle()
}
return .send(.delegate(state.isRecording ? .stopRecording : .startRecording), animation: .default)

case .delegate:
return .none
}
}
}
}

public struct ToolBarRecordingView: View {
let store: StoreOf<ToolBarRecordingLogic>

public init(store: StoreOf<ToolBarRecordingLogic>) {
self.store = store
}

struct ViewState: Equatable {
let isRecording: Bool
let redSize: CGFloat
let cornerRadius: CGFloat

init(state: ToolBarRecordingLogic.State) {
isRecording = state.isRecording
redSize = state.isRecording ? 25 : 72
cornerRadius = state.isRecording ? 6 : 72 / 2
}
}

public var body: some View {
WithViewStore(store, observe: ViewState.init) { viewStore in
VStack(spacing: 12) {
Text("Press the button to throw the iPhone", bundle: .module)
.frame(maxHeight: .infinity)
.font(.system(.title3, weight: .semibold))

Button {
store.send(.captureButtonTapped)
} label: {
ZStack {
RoundedRectangle(cornerRadius: 80 / 2)
.stroke(Color.white, lineWidth: 6.0)
.frame(width: 80, height: 80)
.contentShape(Rectangle())

Color.red
.frame(width: viewStore.redSize, height: viewStore.redSize)
.clipShape(RoundedRectangle(cornerRadius: viewStore.cornerRadius))
}
}
}
.task { await store.send(.onTask).finish() }
.animation(.default, value: viewStore.isRecording)
}
}
}

#Preview {
ToolBarRecordingView(
store: .init(
initialState: ToolBarRecordingLogic.State(),
reducer: { ToolBarRecordingLogic() }
)
)
}
9 changes: 9 additions & 0 deletions Packages/FlyCam/Sources/CaptureFeature/Localizable.xcstrings
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"sourceLanguage" : "en",
"strings" : {
"Press the button to throw the iPhone" : {

}
},
"version" : "1.0"
}