Skip to content

Commit

Permalink
feat: ability receive mechanic-map errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ridvanaltun committed May 13, 2022
1 parent 77adffd commit 030db36
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const App = () => {
rotate: 90,
initialScaleFactor: 1.25,
}}
style={styles.container}
onMapLoaded={() => {
// execute when map loaded
}}
Expand All @@ -88,6 +87,9 @@ const App = () => {
onLocationHighlighted={(target) => {
// executes when location highlighted
}}
onMapError={(data) => {
// executes when occours error on mechanic map
}}
/>
);
};
Expand Down
3 changes: 3 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ export default function App() {
onLocationHighlighted={() => {
console.log('onLocationHighlighted => location highlighted');
}}
onMapError={(data) => {
console.log(`onMapError => ${JSON.stringify(data)}`);
}}
/>
<View style={styles.actions}>
{show && renderButtons()}
Expand Down
13 changes: 13 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export enum MapResponses {
LEVEL_SWITCHED = 'levelSwitched',
LOCATION_HIGHLIGHTED = 'locationsHighlighted',
NAVIGATION_CANCELLED = 'navigationCancelled',
ERROR = 'error',
}

interface EventPayload {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -236,6 +244,7 @@ const MechanicMap = forwardRef<MechanicMapHandle, MechanicMapProps>(
onMapLoaded,
onNavigationCancalled,
onLocationHighlighted,
onMapError,
...props
},
ref
Expand Down Expand Up @@ -412,6 +421,10 @@ const MechanicMap = forwardRef<MechanicMapHandle, MechanicMapProps>(
) {
onLocationHighlighted();
}

if (action === MapResponses.ERROR && onMapError) {
onMapError(data);
}
}}
onLoadEnd={() => {
if (disableAutoInit) return;
Expand Down

0 comments on commit 030db36

Please sign in to comment.