Skip to content

Commit

Permalink
Merge pull request #10 from dream11/fix/on-error-empty-null-source
Browse files Browse the repository at this point in the history
fix: on error empty null source [DylanVann#1028]
  • Loading branch information
mistryswapnil-dream11 authored Jun 11, 2024
2 parents aaf473a + 9df2f76 commit bec3d61
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ e.g. `onLoad={e => console.log(e.nativeEvent.width, e.nativeEvent.height)}`

### `onError?: () => void`

Called on an image fetching error.
Called on an image fetching error or when source is malformed (i.e: empty or null).


---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public void onAfterUpdate(

// Clear the image.
setImageDrawable(null);

ThemedReactContext context = (ThemedReactContext) getContext();
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = getId();
WritableMap event = new WritableNativeMap();
event.putString("message", "Image source uri cannot be empty or null:" + mSource);
eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, event);

return;
}

Expand All @@ -84,7 +92,7 @@ public void onAfterUpdate(
RCTEventEmitter eventEmitter = context.getJSModule(RCTEventEmitter.class);
int viewId = getId();
WritableMap event = new WritableNativeMap();
event.putString("message", "Invalid source prop:" + mSource);
event.putString("message", "Invalid source prop: " + mSource);
eventEmitter.receiveEvent(viewId, REACT_ON_ERROR_EVENT, event);

// Cancel existing requests.
Expand Down
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Platform,
AccessibilityProps,
ViewProps,
ColorValue, Text,
ColorValue
} from 'react-native'

export type ResizeMode = 'contain' | 'cover' | 'stretch' | 'center'
Expand Down

0 comments on commit bec3d61

Please sign in to comment.