-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: (#342) 모바일 안드로이드, IOS에서 접속했을 경우 하단에 설치를 해달라는 문구 보이도록 구현
- Loading branch information
1 parent
99a5ac0
commit 79f15be
Showing
5 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Fragment, useEffect, useState } from 'react'; | ||
|
||
import MobileInstallPrompt from './MobileInstallPrompt'; | ||
|
||
export default function AppInstallPrompt() { | ||
const [deferredPrompt, setDeferredPrompt] = useState<any>(null); | ||
const isDeviceIOS = /iPad|iPhone|iPod/.test(window.navigator.userAgent); | ||
|
||
useEffect(() => { | ||
window.addEventListener('beforeinstallprompt', handleBeforeInstallPrompt); | ||
|
||
return () => { | ||
window.removeEventListener('beforeinstallprompt', handleBeforeInstallPrompt); | ||
}; | ||
}, []); | ||
|
||
const handleBeforeInstallPrompt = (event: Event) => { | ||
event.preventDefault(); | ||
setDeferredPrompt(event); | ||
}; | ||
|
||
const handleInstallClick = () => { | ||
if (deferredPrompt) { | ||
deferredPrompt.prompt(); | ||
|
||
deferredPrompt.userChoice.then((choiceResult: { outcome: string }) => { | ||
if (choiceResult.outcome === 'accepted') { | ||
window.console.log('사용자가 설치 프롬프트에 동의했습니다.'); | ||
} else { | ||
window.console.log('사용자가 설치 프롬프트를 무시했습니다.'); | ||
} | ||
|
||
setDeferredPrompt(null); | ||
}); | ||
} | ||
}; | ||
|
||
const handleCancelClick = () => { | ||
setDeferredPrompt(null); | ||
}; | ||
|
||
return ( | ||
<Fragment> | ||
{deferredPrompt && ( | ||
<MobileInstallPrompt | ||
handleInstallClick={handleInstallClick} | ||
handleCancelClick={handleCancelClick} | ||
platform={isDeviceIOS ? 'ios' : 'android'} | ||
/> | ||
)} | ||
</Fragment> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
import AppInstallPrompt from '@components/common/AppInstallPrompt'; | ||
import MobileInstallPrompt from '@components/common/AppInstallPrompt/MobileInstallPrompt'; | ||
import Layout from '@components/common/Layout'; | ||
import PostListPage from '@components/post/PostListPage'; | ||
|
||
export default function Home() { | ||
return ( | ||
<Layout isSidebarVisible={true}> | ||
<PostListPage /> | ||
<AppInstallPrompt /> | ||
<MobileInstallPrompt | ||
platform="ios" | ||
handleCancelClick={() => {}} | ||
handleInstallClick={() => {}} | ||
/> | ||
</Layout> | ||
); | ||
} |