From 030db36312fcbd3f40f979f005e7b177bd0e69d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C4=B1dvan=20Altun?= Date: Fri, 13 May 2022 15:14:44 +0300 Subject: [PATCH] feat: ability receive mechanic-map errors --- README.md | 4 +++- example/src/App.tsx | 3 +++ src/index.tsx | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3a96bb7..c97e49d 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,6 @@ const App = () => { rotate: 90, initialScaleFactor: 1.25, }} - style={styles.container} onMapLoaded={() => { // execute when map loaded }} @@ -88,6 +87,9 @@ const App = () => { onLocationHighlighted={(target) => { // executes when location highlighted }} + onMapError={(data) => { + // executes when occours error on mechanic map + }} /> ); }; diff --git a/example/src/App.tsx b/example/src/App.tsx index 733556a..f46bde7 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -280,6 +280,9 @@ export default function App() { onLocationHighlighted={() => { console.log('onLocationHighlighted => location highlighted'); }} + onMapError={(data) => { + console.log(`onMapError => ${JSON.stringify(data)}`); + }} /> {show && renderButtons()} diff --git a/src/index.tsx b/src/index.tsx index 47a5393..bb03496 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -41,6 +41,7 @@ export enum MapResponses { LEVEL_SWITCHED = 'levelSwitched', LOCATION_HIGHLIGHTED = 'locationsHighlighted', NAVIGATION_CANCELLED = 'navigationCancelled', + ERROR = 'error', } interface EventPayload { @@ -155,6 +156,13 @@ interface MechanicMapProps extends InitParams, WebViewProps { onMapLoaded?: () => void; onNavigationCancalled?: () => void; onLocationHighlighted?: () => void; + onMapError?: (data: { + message: String; + source: String; + lineno: Number; + colno: Number; + error: String; + }) => void; } export interface Route { @@ -236,6 +244,7 @@ const MechanicMap = forwardRef( onMapLoaded, onNavigationCancalled, onLocationHighlighted, + onMapError, ...props }, ref @@ -412,6 +421,10 @@ const MechanicMap = forwardRef( ) { onLocationHighlighted(); } + + if (action === MapResponses.ERROR && onMapError) { + onMapError(data); + } }} onLoadEnd={() => { if (disableAutoInit) return;