Skip to content

Add mobile framework and version selector to doc pages#367

Open
raffaelefarinaro wants to merge 1 commit into
mainfrom
mobile-framework-version-selector
Open

Add mobile framework and version selector to doc pages#367
raffaelefarinaro wants to merge 1 commit into
mainfrom
mobile-framework-version-selector

Conversation

@raffaelefarinaro

Copy link
Copy Markdown
Contributor

Why

Feedback from Jenny: on mobile it's difficult or impossible to switch frameworks without going back to the homepage. We deep-link to framework-level pages from the corp site and ~50% of that traffic is mobile.

The only existing path was the easy-to-miss ← Back to main menu link in the hamburger, behind an entry labeled SDKs (nothing says "framework"), and its links dropped users on the Installation page instead of keeping the page they were reading.

What

Phones (<768px) — an in-page framework + version selector, styled like the homepage one, at the top of every doc page (above "On this page"):

  • Switching framework keeps the current page and version (e.g. /sdks/android/id-capture/intro/sdks/ios/id-capture/intro); pages that don't exist in the target framework fall back via the existing NotFound redirect, same as desktop today.
  • Version pill mirrors the navbar version dropdown: Stable/Legacy tags, keeps the current page, offers only 7.6.14/6.28.10 on Xamarin pages.
  • Breadcrumbs and the "Back to main menu" button are hidden on mobile (the sidebar already highlights the open page), and the content top padding is reduced 48px → 16px.

Tablets (768–996px) — the existing navbar version/framework dropdowns are shown next to the search (they were CSS-hidden below 997px); the in-page selector is hidden in this range. Dropdowns open on tap.

Desktop (≥997px) — unchanged.

Also:

  • Extracted the desktop dropdown's path-preserving link logic into a shared useFrameworkItems hook (the DropdownNavbarItem override shrinks by ~190 lines, identical behavior). The mobile SDKs dropdown entries now also keep the current page.
  • Fixed the homepage framework selector dropdown being painted over by the SkillsCallout (equal z-index, later DOM order — panel raised to z-index 20).
  • src/theme/DocItem/Layout is a faithful copy of the stock component with one added line (selector above the mobile TOC).

Notes for reviewers

  • ⚠️ Hiding "Back to main menu" means Log In / Sign Up are no longer reachable on mobile doc pages (they only lived in the hamburger primary menu). One-line CSS revert in navbar-sidebar.scss if we want them back.
  • Framework links are computed after hydration (same as before this PR) so the broken-link checker stays green for pages that don't exist in every framework.

Testing

  • yarn typecheck and yarn build pass.
  • Playwright-verified on iPhone 13 viewport, 768px and 915px tablet widths, and 1440px desktop: switching frameworks/versions navigates correctly and preserves the page, Xamarin filtering works on legacy versions, no console errors.

On mobile there was no visible way to switch frameworks: the only path
was the easy-to-miss 'Back to main menu' link in the hamburger, behind
an entry labeled 'SDKs', and its links dropped users on the add-sdk
page instead of keeping the page they were reading.

- Add an in-page framework + version selector (homepage pill style) at
  the top of doc pages, shown below 768px. Switching keeps the current
  page and version; Xamarin entries only appear on legacy versions.
- On tablets (768-996px) show the existing navbar version/framework
  dropdowns next to the search instead of the in-page selector.
- Extract the desktop dropdown's path-preserving link logic into a
  shared useFrameworkItems hook; the mobile SDKs dropdown now also
  keeps the current page when switching.
- Hide breadcrumbs and the 'Back to main menu' button on mobile; the
  sidebar already highlights the open page.
- Reduce mobile doc content top padding (48px -> 16px).
- Fix homepage framework selector dropdown being painted over by the
  SkillsCallout (z-index).
isActive: v === activeVersion,
}));

const versionTag = (category: string) => (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

getVersionMainDoc can return undefined here if a version has no doc matching mainDocId, and .path would throw. The ?? only guards the first operand — maybe (... ?? getVersionMainDoc(v))?.path ?? "/".

<span className={`version-tag version-tag-${category}`}>
{TAG_LABEL[category]}
</span>
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

v comes from useVersions() and activeVersion from useActiveDocContext() — different hooks, so reference equality may never hold and the active version highlight won't show. Compare v.name === activeVersion?.name instead.

/>
))}
{effectiveItems.map((childItemProps, i) => {
const { sidebarId, ...rest } = childItemProps;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Worth a short comment on why sidebarId is dropped here while type stays "docsVersion" (so the explicit to wins). It's the subtlest behavior change in the PR and the desktop path keeps it.

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