[WIP] Clean code // Remove unnecessary props — PART 1

Over time, WebView has evolved a lot and has gone through many updates, resulting today in a hard and messy code to maintain.

In order to keep the webview API as clean as possible, we are going to remove some props and do some code refactoring. But keep in mind that this will not affect what you can achieve with WebView.

Affected props:

  • originWhitelist: this prop is used to limit the URLs that webview can actually load.

Motivations

  1. This prop can be completely emulated with onShouldStartLoadWithRequest().

Current code is

({ nativeEvent }: WebViewNavigationEvent) => {
    let shouldStart = true;
    const { url, lockIdentifier } = nativeEvent;

    if (!passesWhitelist(compileWhitelist(originWhitelist), url)) {
      Linking.openURL(url);
      shouldStart = false;
    }

    if (onShouldStartLoadWithRequest) {
      shouldStart = onShouldStartLoadWithRequest(nativeEvent);
    }

    loadRequest(shouldStart, url, lockIdentifier);
  };

The future code will be something like

({ nativeEvent }: WebViewNavigationEvent) => {
	const { url, lockIdentifier } = nativeEvent;

    if (
      onShouldStartLoadWithRequest
      && !onShouldStartLoadWithRequest(nativeEvent)
    ) {
      loadRequest(false, url, lockIdentifier);
    }
    loadRequest(true, url, lockIdentifier);
  };

This means that if you want to limit URLs, you’ll need to do it directly inside your onShouldStartLoadWithRequest prop.

  1. Removing it will even improve the current API by giving the user control over what should happen when the whitelist does not match, (So instead of doing #423 and adding a prop we can actually remove one) right now the webview forces Linking.openURL()

2 thoughts on “[WIP] Clean code // Remove unnecessary props — PART 1

  1. Discussed this yesterday with you but for public visibility, I also agree with this removal. There’s no point in having 2 features where one can also provide what the other does anyway.

Comments are closed.