-
Notifications
You must be signed in to change notification settings - Fork 58
[menu-bar] Show minimal popover when opened via deep link #312
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
Open
krystofwoldrich
wants to merge
5
commits into
main
Choose a base branch
from
@krystofwoldrich/deeplink-minimal-popover
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−39
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
83f369d
[menu-bar] Show minimal popover with only progress bar when opened vi…
krystofwoldrich c50fbb2
[menu-bar] Fix lint errors in Core.tsx
krystofwoldrich d2f09d5
[menu-bar] Add changelog entry for minimal deep link popover
krystofwoldrich 812b7ed
update pr num
krystofwoldrich 1a0e304
Apply suggestions from code review
gabrieldonadel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { InternalError } from 'common-types'; | ||
| import { MultipleAppsInTarballErrorDetails } from 'common-types/build/InternalError'; | ||
| import { Device } from 'common-types/build/devices'; | ||
| import React, { memo, useCallback, useState } from 'react'; | ||
| import React, { memo, useCallback, useEffect, useRef, useState } from 'react'; | ||
| import { SectionList } from 'react-native'; | ||
|
|
||
| import BuildsSection, { BUILDS_SECTION_HEIGHT } from './BuildsSection'; | ||
|
|
@@ -27,6 +27,8 @@ import { useGetPinnedApps } from '../hooks/useGetPinnedApps'; | |
| import { usePopoverFocusEffect } from '../hooks/usePopoverFocus'; | ||
| import { useSafeDisplayDimensions } from '../hooks/useSafeDisplayDimensions'; | ||
| import Alert from '../modules/Alert'; | ||
| import { DeviceEventEmitter } from '../modules/DeviceEventEmitter'; | ||
| import { Linking } from '../modules/Linking'; | ||
| import MenuBarModule from '../modules/MenuBarModule'; | ||
| import { | ||
| SelectedDevicesIds, | ||
|
|
@@ -48,6 +50,7 @@ import { WindowsNavigator } from '../windows'; | |
|
|
||
| type Props = { | ||
| isDevWindow: boolean; | ||
| onDeepLinkModeChange?: (isDeepLinkMode: boolean) => void; | ||
| }; | ||
|
|
||
| function Core(props: Props) { | ||
|
|
@@ -96,6 +99,48 @@ function Core(props: Props) { | |
| [setTasks] | ||
| ); | ||
|
|
||
| // Track whether the popover was opened via a deep link (browser) or user click. | ||
| // In deep link mode, only the progress UI is shown. | ||
| const [isDeepLinkMode, setIsDeepLinkMode] = useState(false); | ||
| const deepLinkPending = useRef(false); | ||
|
|
||
| // Handle cold start: if app was launched via URL scheme, React wasn't mounted | ||
| // when deepLinkOpened fired, so check the initial URL instead. | ||
| useEffect(() => { | ||
| Linking.getInitialURL().then((url) => { | ||
| if (url) { | ||
| setIsDeepLinkMode(true); | ||
| } | ||
| }); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| const listener = DeviceEventEmitter.addListener('deepLinkOpened', () => { | ||
| deepLinkPending.current = true; | ||
| }); | ||
| return () => listener.remove(); | ||
| }, []); | ||
|
|
||
| // When popover is focused by user click, exit deep link mode. | ||
| // Deep link opens also trigger popoverFocused, but deepLinkPending | ||
| // distinguishes them: the native side emits deepLinkOpened before | ||
| // popoverFocused, so we check and consume the flag here. | ||
| usePopoverFocusEffect( | ||
| useCallback(() => { | ||
| if (deepLinkPending.current) { | ||
| deepLinkPending.current = false; | ||
| setIsDeepLinkMode(true); | ||
|
Comment on lines
+102
to
+132
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we can incorporate this logic into the useDeepLinking hook? |
||
| } else { | ||
| setIsDeepLinkMode(false); | ||
| } | ||
| }, []) | ||
| ); | ||
|
|
||
| const { onDeepLinkModeChange } = props; | ||
| useEffect(() => { | ||
| onDeepLinkModeChange?.(isDeepLinkMode); | ||
| }, [isDeepLinkMode, onDeepLinkModeChange]); | ||
|
|
||
| const { | ||
| devicesPerPlatform, | ||
| numberOfDevices, | ||
|
|
@@ -543,40 +588,44 @@ function Core(props: Props) { | |
| return ( | ||
| <View shrink="1"> | ||
| <BuildsSection installAppFromURI={installAppFromURI} tasks={tasks} /> | ||
| <ProjectsSection apps={apps} /> | ||
| <View shrink="1" pt="tiny" overflow="hidden"> | ||
| {devicesError ? ( | ||
| <DevicesListError error={devicesError} /> | ||
| ) : ( | ||
| <SectionList | ||
| sections={sections} | ||
| style={{ minHeight: estimatedListHeight }} | ||
| contentContainerStyle={{ width: '100%' }} | ||
| showsHorizontalScrollIndicator={false} | ||
| SectionSeparatorComponent={Separator} | ||
| renderSectionHeader={({ section: { label, error } }) => ( | ||
| <DeviceListSectionHeader label={label} errorMessage={error?.message} /> | ||
| {!isDeepLinkMode && ( | ||
| <> | ||
| <ProjectsSection apps={apps} /> | ||
| <View shrink="1" pt="tiny" overflow="hidden"> | ||
| {devicesError ? ( | ||
| <DevicesListError error={devicesError} /> | ||
| ) : ( | ||
| <SectionList | ||
| sections={sections} | ||
| style={{ minHeight: estimatedListHeight }} | ||
| contentContainerStyle={{ width: '100%' }} | ||
| showsHorizontalScrollIndicator={false} | ||
| SectionSeparatorComponent={Separator} | ||
| renderSectionHeader={({ section: { label, error } }) => ( | ||
| <DeviceListSectionHeader label={label} errorMessage={error?.message} /> | ||
| )} | ||
| renderItem={({ item: device }: { item: Device }) => { | ||
| const platform = getDeviceOS(device); | ||
| const id = getDeviceId(device); | ||
| return ( | ||
| <DeviceItem | ||
| device={device} | ||
| key={device.name} | ||
| onPress={() => onSelectDevice(device)} | ||
| onPressLaunch={async () => { | ||
| Analytics.track(Event.LAUNCH_SIMULATOR); | ||
| await bootDeviceAsync({ platform, id }); | ||
| refetch(); | ||
| }} | ||
| selected={selectedDevicesIds[platform] === id} | ||
| /> | ||
| ); | ||
| }} | ||
| /> | ||
| )} | ||
| renderItem={({ item: device }: { item: Device }) => { | ||
| const platform = getDeviceOS(device); | ||
| const id = getDeviceId(device); | ||
| return ( | ||
| <DeviceItem | ||
| device={device} | ||
| key={device.name} | ||
| onPress={() => onSelectDevice(device)} | ||
| onPressLaunch={async () => { | ||
| Analytics.track(Event.LAUNCH_SIMULATOR); | ||
| await bootDeviceAsync({ platform, id }); | ||
| refetch(); | ||
| }} | ||
| selected={selectedDevicesIds[platform] === id} | ||
| /> | ||
| ); | ||
| }} | ||
| /> | ||
| )} | ||
| </View> | ||
| </View> | ||
| </> | ||
| )} | ||
| </View> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.