Skip to content

Commit

Permalink
Merge pull request #26 from mym0404/web-navi
Browse files Browse the repository at this point in the history
Web - Navi package
  • Loading branch information
mym0404 authored May 3, 2024
2 parents c64f587 + 87d2ef9 commit 3fb60d1
Show file tree
Hide file tree
Showing 12 changed files with 225 additions and 26 deletions.
2 changes: 2 additions & 0 deletions docs/docs/install-web.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export async function initializeKakaoSDK(

:::warning
Web을 지원하지 않는다면 `web`인자에 대해 신경 쓸 필요가 없고, `Web`으로 끝나는 API들도 호출하지 말아야 합니다.

또한, `web`인자가 없으면 APIWeb에서도 기본 인자들을 사용하여 동작됩니다.
:::


12 changes: 12 additions & 0 deletions docs/docs/navi/navigate-destination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ Navi는 특별히 설치 과정을 유도하는 옵션이 있기 때문에 앱

대신, resolve되는 결과로 앱이 문제없이 실행이 되었는 지 판단할 수 있습니다.
:::

:::warning
Web 플랫폼에서는 길 안내가 제공되지 않습니다.

만약 모바일 웹이라면 카카오 내비 실행/설치 안내 스크린으로 브라우저로 이동됩니다.

만약 데스크탑 웹이라면 아무일도 일어나지 않습니다.

카카오의 JavaScript SDK에서의 웹에서의 길 안내 종료 공지입니다.

[데브톡 공지사항](https://devtalk.kakao.com/t/notice-end-of-support-for-kakao-navi-web-version/120188)
:::
12 changes: 12 additions & 0 deletions docs/docs/navi/share-destination.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ Navi는 특별히 설치 과정을 유도하는 옵션이 있기 때문에 앱

대신, resolve되는 결과로 앱이 문제없이 실행이 되었는 지 판단할 수 있습니다.
:::

:::warning
Web 플랫폼에서는 길 안내가 제공되지 않습니다.

만약 모바일 웹이라면 카카오 내비 실행/설치 안내 스크린으로 브라우저로 이동됩니다.

만약 데스크탑 웹이라면 아무일도 일어나지 않습니다.

카카오의 JavaScript SDK에서의 웹에서의 길 안내 종료 공지입니다.

[데브톡 공지사항](https://devtalk.kakao.com/t/notice-end-of-support-for-kakao-navi-web-version/120188)
:::
49 changes: 25 additions & 24 deletions packages/channel/src/index.web.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
// import type { KakaoChannelAPI } from './index';
//
// const KakaoChannel: KakaoChannelAPI = {
// followChannel: (channelPublicId: string): Promise<boolean> => {},
// addChannel: (channelPublicId: string): Promise<void> => {},
// getAddChannelUrl: (channelPublicId: string): Promise<string> => {},
// openAddChannelUrl: (channelPublicId: string): Promise<string> => {},
// chatChannel: (channelPublicId: string): Promise<void> => {},
// getChatChannelUrl: (channelPublicId: string): Promise<string> => {},
// openChatChannelUrl: (channelPublicId: string): Promise<string> => {},
// channels: (params) => {},
// };
//
// export const {
// addChannel,
// followChannel,
// channels,
// chatChannel,
// getAddChannelUrl,
// getChatChannelUrl,
// openAddChannelUrl,
// openChatChannelUrl,
// } = KakaoChannel;
// export default KakaoChannel;
import type { KakaoChannelAPI } from './index';

// @ts-ignore
const KakaoChannel: KakaoChannelAPI = {
// followChannel: (channelPublicId: string): Promise<boolean> => {},
// addChannel: (channelPublicId: string): Promise<void> => {},
// getAddChannelUrl: (channelPublicId: string): Promise<string> => {},
// openAddChannelUrl: (channelPublicId: string): Promise<string> => {},
// chatChannel: (channelPublicId: string): Promise<void> => {},
// getChatChannelUrl: (channelPublicId: string): Promise<string> => {},
// openChatChannelUrl: (channelPublicId: string): Promise<string> => {},
// channels: (params) => {},
};

export const {
addChannel,
followChannel,
channels,
chatChannel,
getAddChannelUrl,
getChatChannelUrl,
openAddChannelUrl,
openChatChannelUrl,
} = KakaoChannel;
export default KakaoChannel;
2 changes: 1 addition & 1 deletion packages/navi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,6 @@
},
"gitHead": "57203ed1725b209e814da7cfbb71b36f52d24210",
"dependencies": {
"@mj-studio/js-util": "^1.0.34"
"@mj-studio/js-util": "1.0.35"
}
}
1 change: 1 addition & 0 deletions packages/navi/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,4 @@ export function shareTo({

const KakaoNavi = { navigateTo, shareTo };
export default KakaoNavi;
export type KakaoNaviAPI = typeof KakaoNavi;
134 changes: 134 additions & 0 deletions packages/navi/src/index.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { filterNonNullishKeys } from '@mj-studio/js-util';
import { kAssert } from '@react-native-kakao/core';

import type { KakaoNaviAPI, KakaoNaviOption } from './index';

declare const Kakao: {
Navi: {
start: Function;
share: Function;
};
};

function getVehicleType(v: KakaoNaviOption['vehicleType']): number {
if (v === 'First') {
return 1;
}

if (v === 'Second') {
return 2;
}

if (v === 'Third') {
return 3;
}

if (v === 'Fourth') {
return 4;
}

if (v === 'Fifth') {
return 5;
}

if (v === 'Sixth') {
return 6;
}

if (v === 'TwoWheel') {
return 7;
}

return 1;
}

function getRpOption(v: KakaoNaviOption['rpOption']): number {
if (v === 'Fast') {
return 1;
}

if (v === 'Free') {
return 2;
}

if (v === 'Shortest') {
return 3;
}

if (v === 'NoAuto') {
return 4;
}

if (v === 'Wide') {
return 5;
}

if (v === 'Highway') {
return 6;
}

if (v === 'Normal') {
return 8;
}

if (v === 'Recommended') {
return 100;
}

return 100;
}

const KakaoNavi: KakaoNaviAPI = {
navigateTo: async ({ viaList, destination, option }) => {
kAssert(
viaList ? viaList.length <= 3 : true,
'[navigateTo] viaList length should equal or less then 3.',
);

try {
Kakao.Navi.start(
filterNonNullishKeys({
name: destination.name,
x: destination.x,
y: destination.y,
coordType: option?.coordType?.toLowerCase(),
vehicleType: option?.vehicleType ? getVehicleType(option.vehicleType) : undefined,
rpOption: option?.rpOption ? getRpOption(option.rpOption) : undefined,
routeInfo: option?.routeInfo,
sX: option?.startX,
sY: option?.startY,
sAngle: option?.startAngle,
returnUri: option?.returnUri,
viaPoints: viaList?.map((v) => ({
name: v.name,
x: v.x,
y: v.y,
})),
}),
);

return true;
} catch (e: any) {
return false;
}
},
shareTo: async ({ destination, option }) => {
try {
Kakao.Navi.share(
filterNonNullishKeys({
name: destination.name,
x: destination.x,
y: destination.y,
coordType: option?.coordType?.toLowerCase(),
}),
);

return true;
} catch (e: any) {
return false;
}
},
};

export const { navigateTo, shareTo } = KakaoNavi;
export default KakaoNavi;
1 change: 1 addition & 0 deletions packages/share/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,4 @@ const KakaoShare = {
sendCalendarTemplateToFriends,
};
export default KakaoShare;
export type KakaoShareAPI = typeof KakaoShare;
28 changes: 28 additions & 0 deletions packages/share/src/index.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { KakaoShareAPI } from './index';

// @ts-ignore
const KakaoShare: KakaoShareAPI = {};
export const {
sendCalendarTemplateToFriends,
sendCalendarTemplateToMe,
sendCommerceTemplateToFriends,
sendCommerceTemplateToMe,
sendCustomTemplateToFriends,
sendCustomTemplateToMe,
sendFeedTemplateToFriends,
sendFeedTemplateToMe,
sendListTemplateToFriends,
sendListTemplateToMe,
sendLocationTemplateToFriends,
sendLocationTemplateToMe,
sendTextTemplateToFriends,
sendTextTemplateToMe,
shareCalendarTemplate,
shareCommerceTemplate,
shareCustomTemplate,
shareFeedTemplate,
shareListTemplate,
shareLocationTemplate,
shareTextTemplate,
} = KakaoShare;
export default KakaoShare;
1 change: 1 addition & 0 deletions packages/social/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ export function getFriends({

const KakaoSocial = { getTalkProfile, selectSingleFriend, selectMultipleFriends, getFriends };
export default KakaoSocial;
export type KakaoSocialAPI = typeof KakaoSocial;
7 changes: 7 additions & 0 deletions packages/social/src/index.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { KakaoSocialAPI } from './index';

// @ts-ignore
const KakaoSocial: KakaoSocialAPI = {};
export const { getFriends, getTalkProfile, selectMultipleFriends, selectSingleFriend } =
KakaoSocial;
export default KakaoSocial;
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4792,7 +4792,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@react-native-kakao/navi@workspace:packages/navi"
dependencies:
"@mj-studio/js-util": "npm:^1.0.34"
"@mj-studio/js-util": "npm:1.0.35"
"@react-native-kakao/core": "npm:2.0.0"
"@types/invariant": "npm:^2"
"@types/jest": "npm:^29.5.5"
Expand Down

0 comments on commit 3fb60d1

Please sign in to comment.