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

URL bar improvements #526

Merged
merged 35 commits into from
Sep 12, 2024
Merged

URL bar improvements #526

merged 35 commits into from
Sep 12, 2024

Conversation

p-malecki
Copy link
Contributor

@p-malecki p-malecki commented Sep 4, 2024

This PR introduces several enhancements to the URL bar:

  • The home button in expo router projects opens the root URL (/{}) with empty params but triggers a metro reload in projects without expo router.
    Initial params may be may be introduced in future PRs.
  • The go back button navigates back through the URL history up to a
    limit of 20 URLs.
  • A list of the 5 most recently visited URLs is added to the top of
    Select.Content in the URL bar, followed by an alphabetically sorted
    list of all visited URLs.
  • Improved responsiveness of Select.Content and Select.Trigger
    components.
  • Added a scroll buttons for long URL lists in the Select.Content.
  • Long URL names now break at dashes and display in full upon hover in
    Select.Content.
  • Added Expo Router as an optional dependency to the diagnostics view.

Screenshots:
Screenshot 2024-09-04 at 11 15 34
Screenshot 2024-09-04 at 11 15 59
Screenshot 2024-09-03 at 13 35 04

Test Plan:

  • Navigate to a non-root path and confirm that clicking the home button redirects to the root URL in project using Expo Router and the other without.
  • Visit multiple links using both the app interface and the URL bar, then click the go back button to validate correct navigation through the URL history (additionally, test with dynamic links and component previews).
  • Visit various links and verify that the top 5 most recent URLs are displayed in the correct order.
  • Visit a lot of multiple links or component previews to test scroll functionality when the list exceeds the available space.

Copy link

vercel bot commented Sep 4, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-native-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 11, 2024 1:01pm

@@ -237,7 +237,7 @@ export class Project
}

public async goHome() {
await this.reloadMetro();
await this.openNavigation("/{}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure that it always doesn't take any initial args?

<span className="codicon codicon-home" />
</IconButton>
<UrlSelect
onValueChange={(value: string) => {
project.openNavigation(value);
}}
items={urlList}
recentItems={recentUrlList}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're filtering out URLs if they have no name, do we want to store them then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When changing from a preview to another URL, two route changes happen: {displayName: '', id: '{}'} and {displayName: '/', id: '/{}'}. We skip storing the first route with an empty displayName to prevent saving home URL entries twice.

Comment on lines 242 to 244
if (this.expoRouterInstalled) {
await this.openNavigation(homeUrl);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it's not installed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It that case we reload metro. I've changed it.

export function isExpoRouterProject() {
try {
const appRoot = getAppRootFolder();
const packageJson = require(path.join(appRoot, "package.json"));
Copy link
Collaborator

@filip131311 filip131311 Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requireNoCache

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some inline comments please address them before marging

useEffect(() => {
function moveAsMostRecent(urls: UrlItem[], newUrl: UrlItem) {
return [newUrl, ...urls.filter((record) => record.id !== newUrl.id)];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it would be better to write it like this:

const result = urls.filter((record) => record.id !== newUrl.id);
result.unshift(newUrl);
return result

I made a simple benchmark to check the approaches:

let testCases = new Array(1000).fill(0).map(()=>{
    const list = new Array(1000).fill(0);

    return list.map((e,i)=>{
        return i;
    });
});

const movedURL = 560; 
let start = performance.now();
for ( let testCase of testCases){
    const newTestCase = [ movedURL, ...testCase.filter((element)=>element !==movedURL)];
}
let end = performance.now();


testCases = new Array(1000).fill(0).map(()=>{
    const list = new Array(1000).fill(0);

    return list.map((e,i)=>{
        return i;
    });
});
console.log("old approach",start - end);
 start = performance.now();

for ( let testCase of testCases){
    const filtered = testCase.filter((element)=>element !==movedURL);
    filtered.unshift(movedURL);
    const newTestCase = filtered;
}

end = performance.now();

console.log("new approach",start - end);

and got following results:
Screenshot 2024-09-09 at 17 55 45

Copy link
Member

@jakub-gonet jakub-gonet Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't agree, trading 2ms of performance for worse readability isn't worth it. Especially when you tested it on 1k long list, we won't get anywhere that list length ever.

Copy link
Collaborator

@filip131311 filip131311 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I aprove but left some coments

const appRoot = getAppRootFolder();
const packageJson = requireNoCache(path.join(appRoot, "package.json"));
const hasExpoRouter = Object.values<string>(packageJson.dependencies).some(
(dependency) => dependency === "expo-router"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can expo router ever be a dev dependency?

try {
const appRoot = getAppRootFolder();
const packageJson = requireNoCache(path.join(appRoot, "package.json"));
const hasExpoRouter = Object.values<string>(packageJson.dependencies).some(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@p-malecki p-malecki merged commit 4b1fbd5 into main Sep 12, 2024
3 checks passed
@p-malecki p-malecki deleted the @p-malecki/urlbar-enhance branch September 12, 2024 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants