forked from Blazity/next-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MYB-2071 send message to RN (Blazity#32)
* MYB-2071 send message to RN * MYB-2071 send unauthorized error message to RN * MYB-2071 change validation of window * MYB-2071 test error * MYB-2071 test error 2 * MYB-2071 test error 3 * MYB-2071 test error 4 * MYB-2071 test error 5
- Loading branch information
1 parent
5c3e9eb
commit e7bc014
Showing
4 changed files
with
48 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
'use client'; | ||
import Image from 'next/image'; | ||
import { useRouter } from 'next/navigation'; | ||
import { useRouter, usePathname } from 'next/navigation'; | ||
import BackArrow from 'public/images/backArrow.svg'; | ||
import { sendMessageToRN } from 'utils/sendMessageToRN'; | ||
|
||
export const BackButton = () => { | ||
const pathname = usePathname(); | ||
const router = useRouter(); | ||
return <Image onClick={router.back} priority src={BackArrow} alt="back button" />; | ||
|
||
const handleClick = () => { | ||
if (pathname === '/') { | ||
sendMessageToRN('close-view'); | ||
} else { | ||
router.back(); | ||
} | ||
}; | ||
return <Image onClick={handleClick} priority src={BackArrow} alt="back button" />; | ||
}; |
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,9 @@ | ||
declare global { | ||
interface Window { | ||
ReactNativeWebView?: { | ||
postMessage: (message: string) => void; | ||
}; | ||
} | ||
} | ||
|
||
export {}; |
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,6 @@ | ||
export function sendMessageToRN(text: string) { | ||
if (typeof window === 'undefined') return; | ||
if (window.ReactNativeWebView) { | ||
window.ReactNativeWebView.postMessage(text); | ||
} | ||
} |