Skip to content

Commit 2e3a557

Browse files
authored
feat: add openUrl app message (#54)
* feat: add openUrl app message * feat: add openUrl function when clicking external url
1 parent 8bc71ab commit 2e3a557

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

src/entities/slope/model/model.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type WebcamRaw = {
1717
number: number;
1818
description: string;
1919
url: string;
20+
isExternal?: boolean;
2021
};
2122

2223
export type SlopeResponse = {

src/features/slope/ui/slope-camera.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ interface SlopeWebcamProps {
2424

2525
const SlopeCamera = ({
2626
isWebview = false,
27-
webcam: { scale, name, position, url, id },
27+
webcam: { scale, name, position, url, id, isExternal },
2828
webcamScale,
2929
isOpen,
3030
containerRef,
@@ -45,8 +45,6 @@ const SlopeCamera = ({
4545
}, [id, updateCameraPosition, cameraRef]);
4646

4747
const openVideo = () => {
48-
setOpenCamera();
49-
5048
if (!url) {
5149
postAppMessage('showToast', '선택한 웹캠은 아직 준비중 이에요', isWebview, (message) =>
5250
toast(
@@ -55,6 +53,13 @@ const SlopeCamera = ({
5553
</>
5654
)
5755
);
56+
return;
57+
}
58+
59+
if (isExternal) {
60+
postAppMessage('openUrl', url, isWebview, () => window.open(url, '_blank'));
61+
} else {
62+
setOpenCamera();
5863
}
5964
};
6065

src/shared/lib/postAppMessage.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
type AppMessageMethod = 'showToast' | 'setHeight';
1+
type AppMessageMethod = 'showToast' | 'setHeight' | 'openUrl';
22

33
declare global {
44
interface Window {
55
Android: {
66
showToast: (message: string) => void;
77
setHeight: (message: string) => void;
8+
openUrl: (message: string) => void;
89
};
910
webkit: {
1011
messageHandlers: {
@@ -28,6 +29,8 @@ const postAppMessage = (method: AppMessageMethod, message: string, isWebview: bo
2829
return window.Android.showToast(message);
2930
case 'setHeight':
3031
return window.Android.setHeight(message);
32+
case 'openUrl':
33+
return window.Android.openUrl(message);
3134
}
3235
} else if (iphone !== null) {
3336
return window.webkit.messageHandlers.weski.postMessage({ method: method, message: message });

0 commit comments

Comments
 (0)