Skip to content

Commit

Permalink
whattheduck: Fix native layout for camera preview
Browse files Browse the repository at this point in the history
  • Loading branch information
bperel committed Jul 9, 2024
1 parent 1d127ea commit a4cda03
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
8 changes: 4 additions & 4 deletions apps/whattheduck/.env
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
BASE_URL=http://localhost:8003

#VITE_DM_SOCKET_URL=https://api-websocket.ducksmanager.net
#VITE_DM_SOCKET_URL_NATIVE=https://api-websocket.ducksmanager.net
VITE_DM_SOCKET_URL=https://api-websocket.ducksmanager.net
VITE_DM_SOCKET_URL_NATIVE=https://api-websocket.ducksmanager.net

VITE_DM_SOCKET_URL=http://localhost:3000
VITE_DM_SOCKET_URL_NATIVE=http://192.168.1.209:3000
#VITE_DM_SOCKET_URL=http://localhost:3000
#VITE_DM_SOCKET_URL_NATIVE=http://192.168.1.209:3000

VITE_DM_URL=https://ducksmanager.net

Expand Down
43 changes: 32 additions & 11 deletions apps/whattheduck/src/components/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@

<template v-if="isCameraPreviewShown">
<div :id="cameraPreviewElementId"></div>
<div class="overlay">
<ion-button @click="takePhoto().then(() => (isCameraPreviewShown = false))" size="large">
<div class="overlay" ref="overlay">
<ion-button ref="takePhotoButton" @click="takePhoto().then(() => (isCameraPreviewShown = false))" size="large">
<ion-icon :ios="apertureOutline" :md="apertureSharp" />
</ion-button>
<ion-button size="large" color="danger" @click="isCameraPreviewShown = false">
Expand Down Expand Up @@ -109,6 +109,9 @@ const props = defineProps<{
const emit = defineEmits<(e: 'items-filtered', items: string[]) => void>();
const overlay = ref<HTMLElement>();
const takePhotoButton = ref<{ $el: HTMLElement }>();
const {
coverId: { services: coverIdServices },
} = injectLocal(dmSocketInjectionKey)!;
Expand All @@ -120,15 +123,33 @@ const { isCameraPreviewShown, filterText, selectedIssuenumbers, currentNavigatio
watch(isCameraPreviewShown, async () => {
if (isCameraPreviewShown.value) {
await nextTick();
const cameraPreviewElementBoundingRect = document.getElementById('camera-preview')!.getBoundingClientRect();
const cameraPreviewOptions: CameraPreviewOptions = {
parent: cameraPreviewElementId,
position: 'rear',
...cameraPreviewElementBoundingRect,
};
CameraPreview.start(cameraPreviewOptions);
let loopIteration = 0;
const interval = setInterval(() => {
const boundingClientRect = Object.entries(overlay.value!.getBoundingClientRect().toJSON()).reduce(
(acc, [key, value]) => ({
...acc,
[key]: parseInt(
((value as number) - (key === 'height' ? takePhotoButton.value!.$el.clientHeight : 0)).toFixed(),
),
}),
{},
) as DOMRect;
console.log(boundingClientRect);
if (boundingClientRect.height) {
clearInterval(interval);
const cameraPreviewOptions: CameraPreviewOptions = {
parent: cameraPreviewElementId,
position: 'rear',
...boundingClientRect,
};
CameraPreview.start(cameraPreviewOptions);
} else if (loopIteration > 10) {
console.error('Could not get overlayElement height');
clearInterval(interval);
}
loopIteration++;
}, 50);
} else {
CameraPreview.stop();
}
Expand Down
4 changes: 2 additions & 2 deletions apps/whattheduck/src/components/NavigationDrawer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ const { token, isOfflineMode } = storeToRefs(app());
const collectionStore = wtdcollection();
const points = computed(() => webStores.users().points);
type AppPage = {
interface AppPage {
title: string;
url: string;
disabledOnOfflineMode?: boolean;
iosIcon: string;
mdIcon: string;
chip?: number;
};
}
const appPages: AppPage[] = [
{
Expand Down

0 comments on commit a4cda03

Please sign in to comment.