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: Update navigation bar on start loading #8126

Merged
merged 4 commits into from
Feb 2, 2024
Merged
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
57 changes: 28 additions & 29 deletions app/components/Views/BrowserTab/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const BrowserTab = (props) => {
const [progress, setProgress] = useState(0);
const [initialUrl, setInitialUrl] = useState('');
const [firstUrlLoaded, setFirstUrlLoaded] = useState(false);
const [error, setError] = useState(null);
const [error, setError] = useState(false);
const [showOptions, setShowOptions] = useState(false);
const [entryScriptWeb3, setEntryScriptWeb3] = useState(null);
const [showPhishingModal, setShowPhishingModal] = useState(false);
Expand Down Expand Up @@ -883,10 +883,15 @@ export const BrowserTab = (props) => {
setProgress(progress);
};

// We need to be sure we can remove this property https://github.com/react-native-webview/react-native-webview/issues/2970
// We should check if this is fixed on the newest versions of react-native-webview
const onLoad = ({ nativeEvent }) => {
//For iOS url on the navigation bar should only update upon load.
if (Device.isIos()) {
changeUrl(nativeEvent);
const { origin, pathname = '', query = '' } = new URL(nativeEvent.url);
const realUrl = `${origin}${pathname}${query}`;
changeUrl({ ...nativeEvent, url: realUrl, icon: favicon });
changeAddressBar({ ...nativeEvent, url: realUrl, icon: favicon });
}
};

Expand All @@ -898,13 +903,6 @@ export const BrowserTab = (props) => {
if (nativeEvent.loading) {
return;
}
// Use URL to produce real url. This should be the actual website that the user is viewing.
const urlObj = new URL(nativeEvent.url);
const { origin, pathname = '', query = '' } = urlObj;
const realUrl = `${origin}${pathname}${query}`;
// Update navigation bar address with title of loaded url.
changeUrl({ ...nativeEvent, url: realUrl, icon: favicon });
changeAddressBar({ ...nativeEvent, url: realUrl, icon: favicon });
};

/**
Expand Down Expand Up @@ -1031,25 +1029,13 @@ export const BrowserTab = (props) => {
* Website started to load
*/
const onLoadStart = async ({ nativeEvent }) => {
const { hostname } = new URL(nativeEvent.url);

if (
nativeEvent.url !== url.current &&
nativeEvent.loading &&
nativeEvent.navigationType === 'backforward'
) {
changeAddressBar({ ...nativeEvent });
}

setError(false);

changeUrl(nativeEvent);
sendActiveAccount();

icon.current = null;
if (isHomepage(nativeEvent.url)) {
injectHomePageScripts();
}
// Use URL to produce real url. This should be the actual website that the user is viewing.
const {
origin,
pathname = '',
query = '',
hostname,
} = new URL(nativeEvent.url);

// Reset the previous bridges
backgroundBridges.current.length &&
Expand All @@ -1061,8 +1047,21 @@ export const BrowserTab = (props) => {
return false;
}

const realUrl = `${origin}${pathname}${query}`;
if (nativeEvent.url !== url.current) {
// Update navigation bar address with title of loaded url.
changeUrl({ ...nativeEvent, url: realUrl, icon: favicon });
changeAddressBar({ ...nativeEvent, url: realUrl, icon: favicon });
}

sendActiveAccount();

icon.current = null;
if (isHomepage(nativeEvent.url)) {
injectHomePageScripts();
}

backgroundBridges.current = [];
const origin = new URL(nativeEvent.url).origin;
initializeBackgroundBridge(origin, true);
};

Expand Down
Loading