Skip to content

Commit

Permalink
Rearrange CameraButtonUI parameters, update readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdrobne committed Dec 13, 2022
1 parent a206e93 commit e3aa5f2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
7 changes: 4 additions & 3 deletions CameraButtonExample/CameraButtonExample/PhotoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import CameraButton
struct PhotoView: View {

@State var isRecording: Bool = false
@State var didFinishProgress: Bool = false

var body: some View {
CameraButtonUI(
size: 72,
borderColor: .red,
fillColor: (.purple, .orange),
progressColor: .green,
progressDuration: 5,
isRecording: self.$isRecording,
didFinishProgress: self.$didFinishProgress
isRecording: self.$isRecording
)
.simultaneousGesture(
TapGesture()
Expand Down
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ A simple camera button that can be used for photo and video capturing. It's a su

## Requirements

**iOS 10.0** or higher
**iOS 14.0** or higher

## Instalation

Expand All @@ -27,6 +27,8 @@ dependencies: [
import CameraButton
```

### UIKit

### Initialize

```Swift
Expand Down Expand Up @@ -70,3 +72,42 @@ The `CameraButtonDelegate` requires you to implement the following methods:
func didTap(_ button: CameraButton)
func didFinishProgress()
```

### SwiftUI

```Swift
struct PhotoView: View {

@State var isRecording: Bool = false
@State var didFinishProgress: Bool = false

var body: some View {
CameraButtonUI(
size: 72,
borderColor: .red,
fillColor: (.purple, .orange),
progressColor: .green,
progressDuration: 5,
isRecording: self.$isRecording
)
// Handle tap gesture
.simultaneousGesture(
TapGesture()
.onEnded { _ in
print("tap")
}
)
// Start recording on Long-press gesture
.gesture(
LongPressGesture(minimumDuration: 1)
.onChanged { val in
isRecording = true
}
)
// Observe state changes
.onChange(of: isRecording, perform: { [isRecording] newValue in
print("isRecording", isRecording, newValue)
})
}
}
```
11 changes: 5 additions & 6 deletions Sources/CameraButtonUI/CameraButtonUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ public struct CameraButtonUI: View {

public init(
size: CGFloat = 72,
fillColor: (`default`: Color, record: Color) = (.white, .white),
borderColor: Color = .white,
fillColor: (`default`: Color, record: Color) = (.white, .white),
progressColor: Color = .red,
progressDuration: TimeInterval,
isRecording: Binding<Bool>,
didFinishProgress: Binding<Bool>
isRecording: Binding<Bool>
) {
self.size = size
self.borderColor = borderColor
Expand All @@ -50,7 +49,7 @@ public struct CameraButtonUI: View {
ZStack {
if isRecording {
Circle()
.fill(progressColor)
.fill(borderColor)
.frame(width: size, height: size)
} else {
Circle()
Expand All @@ -71,7 +70,7 @@ public struct CameraButtonUI: View {
Circle()
.trim(from: 0, to: percentage)
.stroke(
fillColor.record,
progressColor,
style: StrokeStyle(lineWidth: size * 0.08, lineCap: .round)
)
.rotationEffect(-.radians(.pi)/2)
Expand Down Expand Up @@ -125,6 +124,6 @@ public struct CameraButtonUI: View {

struct SwiftUIView_Previews: PreviewProvider {
static var previews: some View {
CameraButtonUI(progressDuration: 5, isRecording: .constant(false), didFinishProgress: .constant(false))
CameraButtonUI(progressDuration: 5, isRecording: .constant(false))
}
}

0 comments on commit e3aa5f2

Please sign in to comment.