Skip to content

Commit 754aeda

Browse files
committed
chore: demo
1 parent 1848ff1 commit 754aeda

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

demo-snippets/svelte/Basic.svelte

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script lang="typescript">
2-
import { View } from '@nativescript/core';
2+
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 imageSource: ImageSource;
910
async function applyProcessor() {
1011
try {
1112
if (__ANDROID__) {
@@ -39,19 +40,40 @@
3940
}
4041
4142
async function takePicture() {
42-
const start = Date.now()
43+
console.log('takePicture')
44+
try {
45+
const start = Date.now()
4346
const {image, info} = await cameraView.nativeView.takePicture({savePhotoToDisk:false})
47+
if (imageSource) {
48+
if(__ANDROID__) {
49+
imageSource.android.recycle()
50+
}
51+
}
4452
console.log('onpicture', image, info, Date.now() -start, 'ms')
45-
image.recycle()
53+
imageSource = new ImageSource(image)
54+
} catch (error) {
55+
console.error(error)
56+
}
57+
58+
59+
}
60+
61+
function onCameraTap(event) {
62+
cameraView.nativeView.focusAtPoint(event.getX(), event.getY());
63+
}
64+
function toggleCamera(event) {
65+
cameraView.nativeView.toggleCamera();
4666
}
4767
</script>
4868

4969
<page>
5070
<actionBar title="Basic CameraView">
5171
<navigationButton text="Go back" on:tap={() => goBack()} />
5272
</actionBar>
53-
<cameraview bind:this={cameraView} {flashMode} captureMode={1}>
73+
<cameraview bind:this={cameraView} {flashMode} captureMode={1} on:tap={onCameraTap}>
5474
<cropview bind:this={cropView} />
75+
<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}/>
5577
<button text="picture" on:tap={takePicture} verticalAlignment="bottom" horizontalAlignment="right"/>
5678
<button text="test processor" on:tap={applyProcessor} verticalAlignment="bottom" horizontalAlignment="left"/>
5779
<button text={flashMode} on:tap={switchFlashMode} verticalAlignment="top" horizontalAlignment="right" /></cameraview

0 commit comments

Comments
 (0)