File tree Expand file tree Collapse file tree 3 files changed +28
-0
lines changed
Expand file tree Collapse file tree 3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -10,13 +10,31 @@ import * as S from './MemeDetailPage.styles';
1010import { useTheme } from '@emotion/react' ;
1111import { useParams } from 'react-router-dom' ;
1212import { useMemeDetailQuery } from '@meme_wiki/apis' ;
13+ import { useEffect } from 'react' ;
14+ import { COMMAND_TYPE } from '@/types/bridge' ;
1315
1416const MemeDetailPage = ( ) => {
1517 const { memeId } = useParams ( ) ;
1618 const { data : memeDetail } = useMemeDetailQuery ( memeId ! ) ;
1719
1820 const theme = useTheme ( ) ;
1921
22+ useEffect ( ( ) => {
23+ window . onNativeEvent = ( type : string ) => {
24+ if ( type === COMMAND_TYPE . APP_ENTERED ) {
25+ alert ( '앱 접속!' ) ;
26+ } else {
27+ alert ( '웹 접속!' ) ;
28+ }
29+ } ;
30+
31+ nativeBridge . webEntered ( ) ;
32+
33+ return ( ) => {
34+ window . onNativeEvent = undefined ;
35+ } ;
36+ } , [ ] ) ;
37+
2038 return (
2139 < Layout
2240 layoutStyle = { {
Original file line number Diff line number Diff line change 11export const COMMAND_TYPE = {
22 SHARE_MEME : 'SHARE_MEME' ,
33 CUSTOM_MEME : 'CUSTOM_MEME' ,
4+ WEB_ENTERED : 'WEB_ENTERED' ,
5+ APP_ENTERED : 'APP_ENTERED' ,
46} as const ;
57
68export type CommandType = ( typeof COMMAND_TYPE ) [ keyof typeof COMMAND_TYPE ] ;
@@ -18,6 +20,8 @@ export interface CustomMemeData {
1820export type CommandDataMap = {
1921 [ COMMAND_TYPE . SHARE_MEME ] : ShareMemeData ;
2022 [ COMMAND_TYPE . CUSTOM_MEME ] : CustomMemeData ;
23+ [ COMMAND_TYPE . WEB_ENTERED ] : null ;
24+ [ COMMAND_TYPE . APP_ENTERED ] : null ;
2125} ;
2226
2327export interface BridgeCommand < T extends CommandType > {
@@ -37,5 +41,6 @@ declare global {
3741 } ;
3842 } ;
3943 } ;
44+ onNativeEvent ?: ( type : string ) => void ;
4045 }
4146}
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ class NativeBridge {
9797 customMeme ( data : CustomMemeData ) {
9898 this . sendCommand ( COMMAND_TYPE . CUSTOM_MEME , data ) ;
9999 }
100+
101+ // 웹 페이지 진입
102+ webEntered ( ) {
103+ this . sendCommand ( COMMAND_TYPE . WEB_ENTERED ) ;
104+ }
100105}
101106
102107export const nativeBridge = NativeBridge . getInstance ( ) ;
You can’t perform that action at this time.
0 commit comments