Skip to content

Commit 59aa644

Browse files
committed
feat: torch example wip
1 parent 253c5b6 commit 59aa644

17 files changed

Lines changed: 188 additions & 3 deletions

‎.vscode/extensions.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"recommendations": [
3-
43
"nrwl.angular-console",
5-
"esbenp.prettier-vscode"
4+
"esbenp.prettier-vscode",
5+
"firsttris.vscode-jest-runner"
66
]
77
}

‎libs/nativescript-torch/.babelrc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [["@nrwl/web/babel", { "useBuiltIns": "usage" }]]
3+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"extends": [
3+
"../../.eslintrc.json"
4+
],
5+
"ignorePatterns": [
6+
"!**/*"
7+
],
8+
"overrides": [
9+
{
10+
"files": [
11+
"*.ts",
12+
"*.tsx",
13+
"*.js",
14+
"*.jsx"
15+
],
16+
"rules": {}
17+
},
18+
{
19+
"files": [
20+
"*.ts",
21+
"*.tsx"
22+
],
23+
"rules": {}
24+
},
25+
{
26+
"files": [
27+
"*.js",
28+
"*.jsx"
29+
],
30+
"rules": {}
31+
}
32+
]
33+
}

‎libs/nativescript-torch/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# nativescript-torch
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
6+
## Running unit tests
7+
8+
Run `nx test nativescript-torch` to execute the unit tests via [Jest](https://jestjs.io).
9+
10+
11+
## Running lint
12+
13+
Run `nx lint nativescript-torch` to execute the lint via [ESLint](https://eslint.org/).
14+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* eslint-disable */
2+
export default {
3+
displayName: 'nativescript-torch',
4+
preset: '../../jest.preset.js',
5+
globals: {
6+
'ts-jest': {
7+
tsconfig: '<rootDir>/tsconfig.spec.json',
8+
}
9+
},
10+
transform: {
11+
'^.+\\.[tj]sx?$': 'ts-jest'
12+
},
13+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
14+
coverageDirectory: '../../coverage/libs/nativescript-torch'
15+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"$schema": "../../node_modules/nx/schemas/project-schema.json",
3+
"sourceRoot": "libs/nativescript-torch/src",
4+
"projectType": "library",
5+
"targets": {
6+
"lint": {
7+
"executor": "@nrwl/linter:eslint",
8+
"outputs": [
9+
"{options.outputFile}"
10+
],
11+
"options": {
12+
"lintFilePatterns": [
13+
"libs/nativescript-torch/**/*.ts"
14+
]
15+
}
16+
},
17+
"test": {
18+
"executor": "@nrwl/jest:jest",
19+
"outputs": [
20+
"coverage/libs/nativescript-torch"
21+
],
22+
"options": {
23+
"jestConfig": "libs/nativescript-torch/jest.config.ts",
24+
"passWithNoTests": true
25+
}
26+
}
27+
},
28+
"tags": []
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference path="../../references.d.ts" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Utils } from "@nativescript/core";
2+
3+
export function toggleDeviceTorch(enable: boolean) {
4+
const appContext = Utils.android.getApplicationContext();
5+
const cameraManager = appContext.getSystemService(
6+
android.content.Context.CAMERA_SERVICE
7+
);
8+
const camera = cameraManager.getCameraIdList()[0];
9+
cameraManager.setTorchMode(camera, enable);
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare function toggleDeviceTorch(enable: boolean);
2+
3+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export function toggleDeviceTorch(enable: boolean) {
2+
const device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo);
3+
if (device?.hasTorch) {
4+
device.lockForConfiguration();
5+
if (enable) {
6+
device.setTorchModeOnWithLevelError(1.0);
7+
} else {
8+
device.torchMode = AVCaptureTorchMode.Off;
9+
}
10+
device.unlockForConfiguration();
11+
}
12+
}

0 commit comments

Comments
 (0)