Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: on error empty null source [#1028] #10

Merged
merged 6 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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