Skip to content

Commit

Permalink
Merge commit '714008203f805c4114174933d640360ed72f5c16' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
Isaac committed Jan 18, 2024
2 parents c8123be + 7140082 commit 5ddcd47
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public final class CameraButton: Component {
let minSize: CGSize?
let tag: AnyObject?
let isEnabled: Bool
let isExclusive: Bool
let action: () -> Void
let longTapAction: (() -> Void)?

Expand All @@ -15,13 +16,15 @@ public final class CameraButton: Component {
minSize: CGSize? = nil,
tag: AnyObject? = nil,
isEnabled: Bool = true,
isExclusive: Bool = true,
action: @escaping () -> Void,
longTapAction: (() -> Void)? = nil
) {
self.content = content
self.minSize = minSize
self.tag = tag
self.isEnabled = isEnabled
self.isExclusive = isExclusive
self.action = action
self.longTapAction = longTapAction
}
Expand All @@ -32,6 +35,7 @@ public final class CameraButton: Component {
minSize: self.minSize,
tag: tag,
isEnabled: self.isEnabled,
isExclusive: self.isExclusive,
action: self.action,
longTapAction: self.longTapAction
)
Expand All @@ -50,6 +54,9 @@ public final class CameraButton: Component {
if lhs.isEnabled != rhs.isEnabled {
return false
}
if lhs.isExclusive != rhs.isExclusive {
return false
}
return true
}

Expand Down Expand Up @@ -90,8 +97,6 @@ public final class CameraButton: Component {

super.init(frame: frame)

self.isExclusiveTouch = true

self.addSubview(self.containerView)
self.containerView.addSubview(self.contentView)

Expand Down Expand Up @@ -175,6 +180,8 @@ public final class CameraButton: Component {

self.component = component

self.isExclusiveTouch = component.isExclusive

self.updateScale(transition: transition)
self.isEnabled = component.isEnabled
self.longTapGestureRecognizer?.isEnabled = component.longTapAction != nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ final class StoryInteractionGuideComponent: Component {
transition: transition,
component: AnyComponent(List(items)),
environment: {},
containerSize: CGSize(width: availableSize.width - sideInset * 2.0, height: availableSize.height)
containerSize: CGSize(width: min(500.0, availableSize.width - sideInset * 2.0), height: availableSize.height)
)

let textSpacing: CGFloat = 7.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
private var resultDisposable = MetaDisposable()

var cameraState: CameraState?

var didDisplayViewOnce = false

private let hapticFeedback = HapticFeedback()

Expand Down Expand Up @@ -355,14 +357,20 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
}

if let controller = component.getController() {
if controller.isSendingImmediately || controller.scheduledLock {
if controller.scheduledLock {
showViewOnce = true
}
if !controller.viewOnceAvailable {
showViewOnce = false
}
}

if state.didDisplayViewOnce {
showViewOnce = true
} else if showViewOnce {
state.didDisplayViewOnce = true
}

if !component.isPreviewing {
let flipButton = flipButton.update(
component: CameraButton(
Expand All @@ -377,6 +385,7 @@ private final class VideoMessageCameraScreenComponent: CombinedComponent {
)
),
minSize: CGSize(width: 44.0, height: 44.0),
isExclusive: false,
action: { [weak state] in
if let state {
state.togglePosition()
Expand Down Expand Up @@ -672,15 +681,9 @@ public class VideoMessageCameraScreen: ViewController {
}
self.loadingView.alpha = 0.0
self.additionalPreviewView.removePlaceholder(delay: 0.0)

Queue.mainQueue().after(0.15) {
self.startRecording.invoke(Void())
}
})

self.idleTimerExtensionDisposable.set(self.context.sharedContext.applicationBindings.pushIdleTimerExtension())

self.setupCamera()
}

deinit {
Expand All @@ -689,28 +692,19 @@ public class VideoMessageCameraScreen: ViewController {
}

func withReadyCamera(isFirstTime: Bool = false, _ f: @escaping () -> Void) {
guard let controller = self.controller else {
return
}
let previewReady: Signal<Bool, NoError>
if #available(iOS 13.0, *) {
let _ = (combineLatest(queue: Queue.mainQueue(),
self.cameraState.isDualCameraEnabled ? self.additionalPreviewView.isPreviewing : self.mainPreviewView.isPreviewing,
controller.audioSessionReady.get()
)
|> filter { $0 && $1 }
|> take(1)).startStandalone(next: { _, _ in
f()
})
previewReady = self.cameraState.isDualCameraEnabled ? self.additionalPreviewView.isPreviewing : self.mainPreviewView.isPreviewing
} else {
let _ = (combineLatest(queue: Queue.mainQueue(),
.single(true) |> delay(0.35, queue: Queue.mainQueue()),
controller.audioSessionReady.get()
)
|> filter { $0 && $1 }
|> take(1)).startStandalone(next: { _, _ in
f()
})
previewReady = .single(true) |> delay(0.35, queue: Queue.mainQueue())
}

let _ = (previewReady
|> filter { $0 }
|> take(1)
|> deliverOnMainQueue).startStandalone(next: { _ in
f()
})
}

func setupLiveUpload(filePath: String) {
Expand All @@ -734,7 +728,7 @@ public class VideoMessageCameraScreen: ViewController {
self.view.addGestureRecognizer(pinchGestureRecognizer)
}

private func setupCamera() {
fileprivate func setupCamera() {
guard self.camera == nil else {
return
}
Expand Down Expand Up @@ -771,6 +765,10 @@ public class VideoMessageCameraScreen: ViewController {
camera.startCapture()

self.camera = camera

Queue.mainQueue().justDispatch {
self.startRecording.invoke(Void())
}
}

@objc private func handlePinch(_ gestureRecognizer: UIPinchGestureRecognizer) {
Expand Down Expand Up @@ -1252,7 +1250,6 @@ public class VideoMessageCameraScreen: ViewController {
fileprivate let completion: (EnqueueMessage?, Bool?, Int32?) -> Void

private var audioSessionDisposable: Disposable?
fileprivate let audioSessionReady = ValuePromise<Bool>(false)

private let hapticFeedback = HapticFeedback()

Expand Down Expand Up @@ -1633,7 +1630,7 @@ public class VideoMessageCameraScreen: ViewController {
try? AVAudioSession.sharedInstance().setAllowHapticsAndSystemSoundsDuringRecording(true)
}
if let self {
self.audioSessionReady.set(true)
self.node.setupCamera()
}
}, deactivate: { _ in
return .single(Void())
Expand Down

0 comments on commit 5ddcd47

Please sign in to comment.