Skip to content

Commit 9535b18

Browse files
author
farfromrefug
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # packages/ui-cameraview/platforms/ios/src/NSCameraView.swift
2 parents 0fcca78 + 70544d3 commit 9535b18

File tree

13 files changed

+500
-446
lines changed

13 files changed

+500
-446
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.2.3](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.2...v0.2.3) (2024-02-06)
7+
8+
### Bug Fixes
9+
10+
* **ios:** bug fixes and corrections ([3dee096](https://github.com/nativescript-community/ui-cameraview/commit/3dee0969202356b0ddec6047ded6bda528587456))
11+
* **ios:** more bug fixes and improvements ([dad765f](https://github.com/nativescript-community/ui-cameraview/commit/dad765f4003bee62a78eff5d87edc0f0781a563a))
12+
13+
## [0.2.2](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.1...v0.2.2) (2024-02-05)
14+
15+
### Bug Fixes
16+
17+
* **ios:** improvements and bug fixes ([0d02660](https://github.com/nativescript-community/ui-cameraview/commit/0d02660787b68cafcdbaa861e636818a3f6ceb42))
18+
619
## [0.2.1](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.0...v0.2.1) (2024-02-02)
720

821
### Bug Fixes

demo-snippets/svelte/Basic.svelte renamed to demo-snippets/svelte/Camera.svelte

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<script lang="typescript">
1+
<script lang="ts">
22
import { View, ImageSource } from '@nativescript/core';
33
import { NativeViewElementNode } from 'svelte-native/dom';
44
import { goBack } from 'svelte-native';
55
import { CameraView } from '@nativescript-community/ui-cameraview';
66
let cropView: NativeViewElementNode<View>;
77
let cameraView: NativeViewElementNode<CameraView>;
88
let flashMode = 'off';
9+
let torchEnabled = false;
910
let imageSource: ImageSource;
1011
async function applyProcessor() {
1112
try {
@@ -39,6 +40,17 @@
3940
}
4041
}
4142
43+
function setTorchEnabled(enabled: boolean) {
44+
cameraView.nativeView.flashMode = enabled ? 'torch' : (flashMode as any);
45+
}
46+
function switchTorch() {
47+
if (cameraView) {
48+
const current = cameraView.nativeView.flashMode;
49+
torchEnabled = !(current === 'torch');
50+
setTorchEnabled(torchEnabled);
51+
}
52+
}
53+
4254
async function takePicture() {
4355
console.log('takePicture')
4456
try {
@@ -71,14 +83,12 @@
7183
<navigationButton text="Go back" on:tap={() => goBack()} />
7284
</actionBar>
7385
<cameraview bind:this={cameraView} {flashMode} captureMode={1} on:tap={onCameraTap}>
74-
<cropview bind:this={cropView} />
86+
<!-- <cropview bind:this={cropView} /> -->
7587
<image src={imageSource} width={100} verticalAlignment="bottom" horizontalAlignment="left" marginBottom={60} backgroundColor="red"/>
76-
<button text="toggleCamera" on:tap={toggleCamera} verticalAlignment="top" horizontalAlignment="right" marginTop={60}/>
88+
<button text="toggleCamera" on:tap={toggleCamera} verticalAlignment="top" horizontalAlignment="left" marginTop={60}/>
7789
<button text="picture" on:tap={takePicture} verticalAlignment="bottom" horizontalAlignment="right"/>
7890
<button text="test processor" on:tap={applyProcessor} verticalAlignment="bottom" horizontalAlignment="left"/>
79-
<button text={flashMode} on:tap={switchFlashMode} verticalAlignment="top" horizontalAlignment="right" /></cameraview
80-
>
81-
</page>
82-
83-
<style>
84-
</style>
91+
<button text={flashMode} on:tap={switchFlashMode} verticalAlignment="top" horizontalAlignment="right" />
92+
<button text='torch' on:tap={switchTorch} verticalAlignment="top" horizontalAlignment="right" marginTop="50"/>
93+
</cameraview>
94+
</page>

demo-snippets/svelte/install.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,27 @@ import { request } from '@nativescript-community/perms';
22
import CameraViewViewElement from '@nativescript-community/ui-cameraview/svelte';
33
import { View } from '@nativescript/core';
44
import { registerNativeViewElement } from 'svelte-native/dom';
5-
import Basic from './Basic.svelte';
5+
import Camera from './Camera.svelte';
66

7-
class CropView extends View {
8-
createNativeView() {
9-
if (__ANDROID__) {
10-
return new com.nativescript.cameraviewdemo.CropView(this._context);
11-
} else if (__IOS__) {
12-
return NSCropView.alloc().init();
13-
}
14-
return null;
15-
}
16-
}
7+
// class CropView extends View {
8+
// createNativeView() {
9+
// if (__ANDROID__) {
10+
// return new com.nativescript.cameraviewdemo.CropView(this._context);
11+
// } else if (__IOS__) {
12+
// return NSCropView.alloc().init();
13+
// }
14+
// return null;
15+
// }
16+
// }
1717

1818
export function installPlugin() {
19-
registerNativeViewElement('cropview', () => CropView);
19+
// registerNativeViewElement('cropview', () => CropView);
2020
CameraViewViewElement.register();
2121
setTimeout(() => {
2222
request('camera');
2323
}, 1000);
2424
}
2525

26-
export const demos = [{ name: 'Basic', path: 'basic', component: Basic }];
26+
// export const demos = [];
27+
export const demos = [{ name: 'Camera', path: 'camera', component: Camera }];
2728

28-
// let start = Date.now();
29-
// for (let index = 0; index < 10000; index++) {
30-
// new java.lang.Float(2.3);
31-
// }
32-
// console.log('java.lang.Float', Date.now() -start);
33-
// start = Date.now();
34-
// for (let index = 0; index < 10000; index++) {
35-
// java.lang.Float.valueOf(2.3);
36-
// }
37-
// console.log('java.lang.Float.valueOf', Date.now() -start);
38-
// start = Date.now();
39-
// for (let index = 0; index < 10000; index++) {
40-
// float(2.3);
41-
// }
42-
// console.log('float', Date.now() -start);

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.2.1",
2+
"version": "0.2.3",
33
"$schema": "node_modules/@lerna-lite/cli/schemas/lerna-schema.json",
44
"packages": [
55
"packages/*"

packages/ui-cameraview/CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
## [0.2.3](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.2...v0.2.3) (2024-02-06)
7+
8+
### Bug Fixes
9+
10+
* **ios:** bug fixes and corrections ([3dee096](https://github.com/nativescript-community/ui-cameraview/commit/3dee0969202356b0ddec6047ded6bda528587456))
11+
* **ios:** more bug fixes and improvements ([dad765f](https://github.com/nativescript-community/ui-cameraview/commit/dad765f4003bee62a78eff5d87edc0f0781a563a))
12+
13+
## [0.2.2](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.1...v0.2.2) (2024-02-05)
14+
15+
### Bug Fixes
16+
17+
* **ios:** improvements and bug fixes ([0d02660](https://github.com/nativescript-community/ui-cameraview/commit/0d02660787b68cafcdbaa861e636818a3f6ceb42))
18+
619
## [0.2.1](https://github.com/nativescript-community/ui-cameraview/compare/v0.2.0...v0.2.1) (2024-02-02)
720

821
### Bug Fixes

packages/ui-cameraview/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@nativescript-community/ui-cameraview",
3-
"version": "0.2.1",
3+
"version": "0.2.3",
44
"description": "A CameraView allowing custom live processing for NativeScript",
55
"main": "index",
66
"typings": "index.d.ts",
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pod "NextLevel", "~> 0.16.3"
1+
pod "NextLevel", :git => 'https://github.com/Akylas/NextLevel.git', :branch => "0.16.4"
2+
# pod "NextLevel", :path => '/Volumes/dev/ios/NextLevel'

packages/ui-cameraview/platforms/ios/src/NSCameraView.swift

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
2727
public weak var delegate: NSCameraViewDelegate?
2828
var nextLevel: NextLevel?
2929
var captureModeCompletionHandler: (()->Void)?
30+
private var captureModeBeforePhoto: NextLevelCaptureMode = .photo
3031
override init(frame: CGRect) {
3132
super.init(frame: frame )
3233
commonInit()
@@ -87,6 +88,25 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
8788
}
8889
}
8990

91+
public var automaticallyUpdatesDeviceOrientation: Bool {
92+
get {
93+
return self.nextLevel?.automaticallyUpdatesDeviceOrientation ?? true
94+
}
95+
set {
96+
self.nextLevel?.automaticallyUpdatesDeviceOrientation = newValue
97+
}
98+
}
99+
100+
public var captureMode: Int {
101+
get {
102+
return (self.nextLevel?.captureMode ?? NextLevelCaptureMode.photo).rawValue
103+
}
104+
set {
105+
captureModeBeforePhoto = NextLevelCaptureMode(rawValue: newValue)!
106+
self.nextLevel?.captureMode = captureModeBeforePhoto
107+
}
108+
}
109+
90110
func commonInit() {
91111
self.autoresizingMask = [.flexibleWidth, .flexibleHeight]
92112
self.backgroundColor = UIColor.black
@@ -117,9 +137,8 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
117137
nextLevel.videoConfiguration.maxKeyFrameInterval = 30
118138
nextLevel.videoConfiguration.profileLevel = AVVideoProfileLevelH264HighAutoLevel
119139

120-
// audio configuration
121-
// for now disable audio
122-
nextLevel.captureMode = NextLevelCaptureMode.videoWithoutAudio
140+
nextLevel.captureMode = NextLevelCaptureMode.photo
141+
nextLevel.photoConfiguration.isHighResolutionEnabled = true
123142
// nextLevel.audioConfiguration.bitRate = 96000
124143
// nextLevel.disableAudioInputDevice()
125144
// metadata objects configuration
@@ -160,23 +179,30 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
160179
return self.nextLevel?.canCaptureVideo ?? false
161180
}
162181
}
182+
public var videoOrientation: Int {
183+
get {
184+
return (self.nextLevel?.previewLayer.connection?.videoOrientation ?? AVCaptureVideoOrientation.portrait).rawValue
185+
}
186+
}
163187
public func capturePhoto(_ options: String) {
164188
if let nextLevel = self.nextLevel , self.canCapturePhoto {
165-
if ( nextLevel.captureMode == NextLevelCaptureMode.photo) {
189+
// if ( nextLevel.captureMode == NextLevelCaptureMode.photo) {
166190
nextLevel.capturePhoto()
167-
} else {
168-
captureModeCompletionHandler = {
169-
nextLevel.capturePhoto()
170-
}
171-
nextLevel.captureMode = NextLevelCaptureMode.photo
172-
}
191+
// } else {
192+
// captureModeBeforePhoto = nextLevel.captureMode
193+
// captureModeCompletionHandler = {
194+
// nextLevel.capturePhoto()
195+
// }
196+
// nextLevel.captureMode = NextLevelCaptureMode.photo
197+
// }
173198
}
174199
}
175200
public func capturePhotoFromVideo() {
176201
if let nextLevel = self.nextLevel , self.canCaptureVideo {
177202
if ( nextLevel.captureMode == NextLevelCaptureMode.videoWithoutAudio || nextLevel.captureMode == NextLevelCaptureMode.video) {
178203
nextLevel.capturePhotoFromVideo()
179204
} else {
205+
captureModeBeforePhoto = nextLevel.captureMode
180206
captureModeCompletionHandler = {
181207
nextLevel.capturePhotoFromVideo()
182208
}
@@ -196,7 +222,18 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
196222
}
197223

198224
public func nextLevelSessionWillStart(_ nextLevel: NextLevel) {
199-
225+
// DispatchQueue.main.async {
226+
// var uiOrientation: UIInterfaceOrientation = .portrait
227+
//// if #available(iOS 13.0, *) {
228+
//// uiOrientation = UIApplication.shared.windows.first?.windowScene?.interfaceOrientation ?? UIApplication.shared.statusBarOrientation
229+
//// } else {
230+
// uiOrientation = UIApplication.shared.statusBarOrientation
231+
//// }
232+
//
233+
// let orientation = AVCaptureVideoOrientation.init(rawValue: uiOrientation.rawValue) ?? AVCaptureVideoOrientation.portrait
234+
// nextLevel.previewLayer.connection?.videoOrientation = orientation;
235+
// }
236+
200237
}
201238

202239
public func nextLevelSessionDidStart(_ nextLevel: NextLevel) {
@@ -221,7 +258,7 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
221258
}
222259

223260
public func nextLevelCaptureModeDidChange(_ nextLevel: NextLevel) {
224-
captureModeCompletionHandler?()
261+
self.captureModeCompletionHandler?()
225262
}
226263

227264
// MARK: NextLevelPhotoDelegate
@@ -288,6 +325,9 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
288325

289326
public func nextLevel(_ nextLevel: NextLevel, didCompletePhotoCaptureFromVideoFrame photoDict: [String : Any]?) {
290327
self.videoDelegate?.cameraView(self, didCompletePhotoCaptureFromVideoFrame: photoDict)
328+
if (captureModeBeforePhoto != nextLevel.captureMode) {
329+
nextLevel.captureMode = captureModeBeforePhoto
330+
}
291331
}
292332

293333
// MARK: NextLevelPhotoDelegate
@@ -308,8 +348,6 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
308348
// Returns corresponting NSCFNumber. It seems to specify the origin of the image
309349
// print("Metadata orientation: ",photoMetadata["Orientation"])
310350

311-
// Returns corresponting NSCFNumber. It seems to specify the origin of the image
312-
print("Metadata orientation with key: ",photoMetadata[String(kCGImagePropertyOrientation)] as Any)
313351

314352
guard let imageData = photo.fileDataRepresentation() else {
315353
print("Error while generating image from photo capture data.");
@@ -335,6 +373,9 @@ public class NSCameraView: UIView, NextLevelVideoDelegate, NextLevelPhotoDelegat
335373
let image = UIImage(cgImage: cgImage, scale: 1.0, orientation: deviceOrientationOnCapture.getUIImageOrientationFromDevice())
336374

337375
self.photoDelegate?.cameraView(self, didFinishProcessingPhoto: image, photoDict: photoDict, photoConfiguration: NSCameraViewPhotoConfiguration(configuration: photoConfiguration))
376+
if (captureModeBeforePhoto != nextLevel.captureMode) {
377+
nextLevel.captureMode = captureModeBeforePhoto
378+
}
338379
}
339380

340381
public func nextLevelDidCompletePhotoCapture(_ nextLevel: NextLevel) {

0 commit comments

Comments
 (0)