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_**
|
> **_Note_**
|
||||||
> Domain is only used on iOS
|
> 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 -->
|
### `onLoad`[⬆](#props-index)<!-- Link generated with jump2header -->
|
||||||
|
|
|
@ -214,7 +214,6 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
onLoadingError = (event: WebViewErrorEvent) => {
|
onLoadingError = (event: WebViewErrorEvent) => {
|
||||||
event.persist(); // persist this event because we need to store it
|
event.persist(); // persist this event because we need to store it
|
||||||
const { onError, onLoadEnd } = this.props;
|
const { onError, onLoadEnd } = this.props;
|
||||||
|
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(event);
|
onError(event);
|
||||||
} else {
|
} else {
|
||||||
|
@ -224,6 +223,7 @@ class WebView extends React.Component<AndroidWebViewProps, State> {
|
||||||
if (onLoadEnd) {
|
if (onLoadEnd) {
|
||||||
onLoadEnd(event);
|
onLoadEnd(event);
|
||||||
}
|
}
|
||||||
|
if (event.isDefaultPrevented()) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastErrorEvent: event.nativeEvent,
|
lastErrorEvent: event.nativeEvent,
|
||||||
|
|
|
@ -196,15 +196,16 @@ class WebView extends React.Component<IOSWebViewProps, State> {
|
||||||
event.persist(); // persist this event because we need to store it
|
event.persist(); // persist this event because we need to store it
|
||||||
const { onError, onLoadEnd } = this.props;
|
const { onError, onLoadEnd } = this.props;
|
||||||
|
|
||||||
if (onLoadEnd) {
|
|
||||||
onLoadEnd(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(event);
|
onError(event);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onLoadEnd) {
|
||||||
|
onLoadEnd(event);
|
||||||
|
}
|
||||||
|
if (event.isDefaultPrevented()) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastErrorEvent: event.nativeEvent,
|
lastErrorEvent: event.nativeEvent,
|
||||||
|
|
|
@ -184,15 +184,16 @@ class WebView extends React.Component<MacOSWebViewProps, State> {
|
||||||
event.persist(); // persist this event because we need to store it
|
event.persist(); // persist this event because we need to store it
|
||||||
const { onError, onLoadEnd } = this.props;
|
const { onError, onLoadEnd } = this.props;
|
||||||
|
|
||||||
if (onLoadEnd) {
|
|
||||||
onLoadEnd(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (onError) {
|
if (onError) {
|
||||||
onError(event);
|
onError(event);
|
||||||
} else {
|
} else {
|
||||||
console.warn('Encountered an error loading page', event.nativeEvent);
|
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (onLoadEnd) {
|
||||||
|
onLoadEnd(event);
|
||||||
|
}
|
||||||
|
if (event.isDefaultPrevented()) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastErrorEvent: event.nativeEvent,
|
lastErrorEvent: event.nativeEvent,
|
||||||
|
|
|
@ -153,19 +153,23 @@ export default class WebView extends React.Component<WebViewSharedProps, State>
|
||||||
|
|
||||||
onLoadingError = (event: WebViewErrorEvent) => {
|
onLoadingError = (event: WebViewErrorEvent) => {
|
||||||
event.persist(); // persist this event because we need to store it
|
event.persist(); // persist this event because we need to store it
|
||||||
const {onError, onLoadEnd} = this.props;
|
const { onError, onLoadEnd } = this.props;
|
||||||
if(onError) {
|
if (onError) {
|
||||||
onError(event);
|
onError(event);
|
||||||
|
} else {
|
||||||
|
console.warn('Encountered an error loading page', event.nativeEvent);
|
||||||
}
|
}
|
||||||
if(onLoadEnd) {
|
|
||||||
|
if (onLoadEnd) {
|
||||||
onLoadEnd(event);
|
onLoadEnd(event);
|
||||||
}
|
}
|
||||||
console.error('Encountered an error loading page', event.nativeEvent);
|
if (event.isDefaultPrevented()) return;
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
lastErrorEvent: event.nativeEvent,
|
lastErrorEvent: event.nativeEvent,
|
||||||
viewState: 'ERROR',
|
viewState: 'ERROR',
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
onLoadingFinish =(event: WebViewNavigationEvent) => {
|
onLoadingFinish =(event: WebViewNavigationEvent) => {
|
||||||
const {onLoad, onLoadEnd} = this.props;
|
const {onLoad, onLoadEnd} = this.props;
|
||||||
|
|
Loading…
Reference in New Issue