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 UrlSelect trigger value reset for non expo router projects #873

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

p-malecki
Copy link
Contributor

This PR changes the UrlBar behaviour in projects not using Expo Router navigation.
When the user intends to close the preview by pressing the goHome button (or reload), the UrlSelect's trigger value needs to be reset to a placeholder ("/").
In this solution it is achieved by using the urlSelectKey and urlSelectValue states to force a full re-render of the Radix Select when the key changes.

Additionally, this update disables the goBack button for projects that do not use Expo Router.

How Has This Been Tested:

  • Tested on expo-router and react-native-76 apps.
Before After
Screen.Recording.2024-12-20.at.18.45.00.mov
Screen.Recording.2024-12-20.at.18.35.50.mov

Copy link

vercel bot commented Dec 20, 2024

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

Name Status Preview Comments Updated (UTC)
radon-ide ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 20, 2024 6:02pm

value: string;
onValueChange: (newValue: string) => void;
recentItems: UrlItem[];
items: UrlItem[];
disabled?: boolean;
}

function UrlSelect({ onValueChange, recentItems, items, value, disabled }: UrlSelectProps) {
function UrlSelect({ onValueChange, recentItems, items, key, value, disabled }: UrlSelectProps) {
Copy link
Member

Choose a reason for hiding this comment

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

I believe that it only has been added in React 19 that you can receive key prop like this. I don't think in the current version in propagates down to the component

@@ -35,7 +36,7 @@ function UrlSelect({ onValueChange, recentItems, items, value, disabled }: UrlSe
};

return (
<Select.Root onValueChange={handleValueChange} value={value} disabled={disabled}>
<Select.Root onValueChange={handleValueChange} key={key} value={value} disabled={disabled}>
Copy link
Member

Choose a reason for hiding this comment

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

It should be enough to do something along these lines, instead of having the whole logic for urlSelectKey in the parent component:

<Select.root key={value ? "has-value : "no-value"}>

@@ -117,8 +130,9 @@ function UrlBar({ disabled }: { disabled?: boolean }) {
}}
recentItems={recentUrlList}
items={sortedUrlList}
value={urlList[0]?.id}
disabled={disabledAlsoWhenStarting || urlList.length < 2}
key={urlSelectKey}
Copy link
Member

Choose a reason for hiding this comment

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

setting this here is enough to re-mount the whole component. It doesn't have to be accessed in the underlying component

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.

2 participants