feat(onError): Add support for preventDefault when using onError method (#1706)
* Add event.isDefaultPrevented() check within onError method * Update onError in the reference regarding preventDefault * Fix return values in the 'onError' method * Minor update for Reference.md in "onError" section * Update WebView.windows.tsx * Update WebView.windows.tsx * Update WebView.android.tsx * Update WebView.ios.tsx * Update WebView.macos.tsx Co-authored-by: Jamon Holmgren <jamonholmgren@gmail.com> Co-authored-by: Thibault Malbranche <thibault.malbranche@epitech.eu> Co-authored-by: Thibault Malbranche <malbranche.thibault@gmail.com>
This commit is contained in:
parent
038b11ccce
commit
404e3e69e2
|
@ -304,6 +304,8 @@ url
|
|||
> **_Note_**
|
||||
> Domain is only used on iOS
|
||||
|
||||
The `syntheticEvent` can be stopped doing its default action by calling `syntheticEvent.preventDefault()`.
|
||||
|
||||
---
|
||||
|
||||
### `onLoad`[⬆](#props-index)<!-- Link generated with jump2header -->
|
||||
|
|
|
@ -214,7 +214,6 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
|||
onLoadingError = (event: WebViewErrorEvent) => {
|
||||
event.persist(); // persist this event because we need to store it
|
||||
const { onError, onLoadEnd } = this.props;
|
||||
|
||||
if (onError) {
|
||||
onError(event);
|
||||
} else {
|
||||
|
@ -224,6 +223,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
|||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented()) return;
|
||||
|
||||
this.setState({
|
||||
lastErrorEvent: event.nativeEvent,
|
||||
|
|
|
@ -196,16 +196,17 @@ class WebView extends React.Component<IOSWebViewProps, State> {
|
|||
event.persist(); // persist this event because we need to store it
|
||||
const { onError, onLoadEnd } = this.props;
|
||||
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
|
||||
if (onError) {
|
||||
onError(event);
|
||||
} else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented()) return;
|
||||
|
||||
this.setState({
|
||||
lastErrorEvent: event.nativeEvent,
|
||||
viewState: 'ERROR',
|
||||
|
|
|
@ -184,16 +184,17 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
|
|||
event.persist(); // persist this event because we need to store it
|
||||
const { onError, onLoadEnd } = this.props;
|
||||
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
|
||||
if (onError) {
|
||||
onError(event);
|
||||
} else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
if (event.isDefaultPrevented()) return;
|
||||
|
||||
this.setState({
|
||||
lastErrorEvent: event.nativeEvent,
|
||||
viewState: 'ERROR',
|
||||
|
|
|
@ -153,19 +153,23 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
|
|||
|
||||
onLoadingError = (event: WebViewErrorEvent) => {
|
||||
event.persist(); // persist this event because we need to store it
|
||||
const {onError, onLoadEnd} = this.props;
|
||||
if(onError) {
|
||||
const { onError, onLoadEnd } = this.props;
|
||||
if (onError) {
|
||||
onError(event);
|
||||
} else {
|
||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||
}
|
||||
if(onLoadEnd) {
|
||||
|
||||
if (onLoadEnd) {
|
||||
onLoadEnd(event);
|
||||
}
|
||||
console.error('Encountered an error loading page', event.nativeEvent);
|
||||
if (event.isDefaultPrevented()) return;
|
||||
|
||||
this.setState({
|
||||
lastErrorEvent: event.nativeEvent,
|
||||
viewState: 'ERROR',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
onLoadingFinish =(event: WebViewNavigationEvent) => {
|
||||
const {onLoad, onLoadEnd} = this.props;
|
||||
|
|
Loading…
Reference in New Issue