Skip to content

Commit e8af122

Browse files
committed
chore: demo update
1 parent 80a4a87 commit e8af122

File tree

2 files changed

+33
-37
lines changed

2 files changed

+33
-37
lines changed

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);

0 commit comments

Comments
 (0)