GeezerVison is showing github.com — feat(mobile): add One UI navigation preference on Android by PixPMusic · Pull Request #25758 · pingdotgg/t3code
feat(mobile): add One UI navigation preference on Android
#25758
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
Uh oh!
There was an error while loading. Please reload this page.
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter
Filter by extension
.ts
(2)
.tsx
(9)
All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Hide whitespace
Diff view
Hide whitespace
fix(mobile): keep floating navigation width stable and fill cover rows
Loading branch information
Uh oh!
There was an error while loading. Please reload this page.
commit e630897ba4d2ea65b70f9c7b592d9594333e4946
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Original file line number
Diff line number
Diff line change
Expand Up
@@ -17,12 +17,11 @@ import { updateFabScroll } from "./fab-scroll";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
import { WorkspaceTabsContext, useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
import {
useAppearancePreferences,
useAndroidFloatingTabs,
FLOATING_TABS,
floatingTabsMetrics,
} from "../workspace/floating-workspace-tabs";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
} from "../settings/appearance/AppearancePreferencesProvider";
export function AndroidHomeFabLayout(props: ComponentProps<typeof SharedAndroidHomeFabLayout>) {
const floatingTabsEnabled = useAndroidFloatingTabs();
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider";
import { useState } from "react";
import { useKeyboardState } from "react-native-keyboard-controller";
import { Platform, View } from "react-native";
Expand All
@@ -10,7 +11,6 @@ import {
useNativeColumnLayoutMetrics,
} from "../../native/native-layout-metrics";
import { workspaceSearchBottomClearance } from "../workspace/workspace-tabs-state";
import { useAndroidFloatingTabs } from "../workspace/floating-workspace-tabs";
import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
import {
dismissThreadUndoNotice,
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider";
import { SafeAreaInsetsContext, useSafeAreaInsets } from "react-native-safe-area-context";
import { AdaptiveWorkspaceContext, useAdaptiveWorkspaceLayout } from "./adaptive-workspace-context";
import { threadSelectionDeferral } from "./deferred-navigation";
Expand Down
Expand Up
@@ -57,11 +58,7 @@ import {
} from "../keyboard/hardwareKeyboardCommands";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
import {
useAndroidFloatingTabs,
FLOATING_TABS,
floatingTabsMetrics,
} from "../workspace/floating-workspace-tabs";
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
import { AndroidHomeFabLayout } from "../home/AndroidHomeFab";
import {
AndroidWorkspaceNavigation,
Expand Down
Expand Up
@@ -955,7 +952,13 @@ function AdaptiveWorkspaceLayoutContent(
</SafeAreaInsetsContext>
{floatingTabsEnabled &&
(compactAndroidSettings || (layout.usesSplitView && workspacePage)) ? (
<FloatingWorkspaceTabs onNewThread={handleStartNewTask} />
<FloatingWorkspaceTabs
paneWidth={
layout.usesSplitView ? (layout.listPaneWidth ?? undefined) : undefined
}
fillWidth={compactAndroidSettings}
onNewThread={handleStartNewTask}
/>
) : compactAndroidSettings ? (
<AndroidWorkspaceNavigation onNewThread={handleStartNewTask} />
) : null}
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -390,3 +390,8 @@ export function useAppearancePreferences(): AppearancePreferencesContextValue {
}
return context;
}
export function useAndroidFloatingTabs() {
const { androidNavigationStyle } = useAppearancePreferences();
return Platform.OS === "android" && androidNavigationStyle === "one-ui";
}
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,7 +2,10 @@ import { useActiveNewTask } from "../../state/active-new-task";
import { ThreadUndoNotice } from "../home/ThreadUndoNotice";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import { resolveScratchProjectScopeKey } from "@t3tools/client-runtime/state/project-grouping";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
import {
useAppearancePreferences,
useAndroidFloatingTabs,
} from "../settings/appearance/AppearancePreferencesProvider";
import type {
EnvironmentProject,
EnvironmentThreadShell,
Expand All
@@ -18,11 +21,7 @@ import { Platform, StyleSheet, TextInput, View } from "react-native";
import { GestureDetector, useNativeGesture } from "react-native-gesture-handler";
import type { SwipeableMethods } from "react-native-gesture-handler/ReanimatedSwipeable";
import { useEnabledNavigationTabs } from "../workspace/navigation-tabs";
import {
useAndroidFloatingTabs,
FLOATING_TABS,
floatingTabsMetrics,
} from "../workspace/floating-workspace-tabs";
import { FLOATING_TABS, floatingTabsMetrics } from "../workspace/floating-workspace-tabs";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import type { SearchBarCommands } from "react-native-screens";
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -64,6 +64,7 @@ export function AndroidWorkspaceNavigation(props: {
readonly onNewThread: () => void;
readonly rail?: boolean;
readonly floating?: boolean;
readonly fillWidth?: boolean;
readonly paneWidth?: number;
readonly onSelect?: () => void;
/** The rail needs the whole workspace while it widens over the list. */
Expand All
@@ -84,7 +85,13 @@ export function AndroidWorkspaceNavigation(props: {
const rail = Boolean(props.rail);
const floating = !rail && Boolean(props.floating);
const tabs = [...visibleNavigationTabs(order, hidden, rail ? 5 : 4), "settings"];
const metrics = floatingTabsMetrics(tabs.length, scale, fabSize, props.paneWidth ?? window.width);
const metrics = floatingTabsMetrics(
tabs.length,
scale,
fabSize,
props.paneWidth ?? window.width,
props.fillWidth,
);
const { containerColor, indicatorColor, selectedColor, unselectedColor } =
androidWorkspaceNavigationColors(colors, rail, floating);
const selectedTab = selectedNavigationTab(
Expand Down
Expand Up
@@ -159,6 +166,7 @@ export function AndroidWorkspaceNavigation(props: {
}
export function FloatingWorkspaceTabs(props: {
readonly fillWidth?: boolean;
readonly onNewThread: () => void;
readonly paneWidth?: number;
readonly onSelect?: () => void;
Expand Down
Original file line number
Diff line number
Diff line change
Expand Up
@@ -2,6 +2,7 @@ export function AndroidWorkspaceNavigation(_props: {
readonly onNewThread: () => void;
readonly rail?: boolean;
readonly floating?: boolean;
readonly fillWidth?: boolean;
readonly paneWidth?: number;
readonly onSelect?: () => void;
readonly onOverlayChange?: (overlay: boolean) => void;
Expand All
@@ -12,6 +13,7 @@ export function AndroidWorkspaceNavigation(_props: {
export const ANDROID_WORKSPACE_RAIL_WIDTH = 72;
export function FloatingWorkspaceTabs(_props: {
readonly fillWidth?: boolean;
readonly onNewThread: () => void;
readonly paneWidth?: number;
readonly onSelect?: () => void;
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,11 @@
import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider";
import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
import { useEnabledNavigationTabs } from "./navigation-tabs";
import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
import { useMemo, type ReactNode } from "react";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { useAndroidControlSizing } from "../../components/ui/useAndroidControlSizing";
import {
useAndroidFloatingTabs,
FLOATING_TABS,
floatingTabsMetrics,
} from "./floating-workspace-tabs";
import { FLOATING_TABS, floatingTabsMetrics } from "./floating-workspace-tabs";
import { View } from "react-native";
import { ScreenContent } from "../../components/ui/ScreenContent";
import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
import { useAndroidFloatingTabs } from "../settings/appearance/AppearancePreferencesProvider";
import { WorkspaceNoTabs } from "./WorkspaceNoTabs";
import { useEnabledNavigationTabs } from "./navigation-tabs";
import { NAVIGATION_TAB_ORDER } from "./navigation-tab-order";
Expand All
@@ -15,11 +16,7 @@ import { PullRequestsScreen } from "../pull-requests/PullRequestsScreen";
import { PullRequestToolbar } from "../pull-requests/PullRequestToolbar.android";
import { useAdaptiveWorkspaceLayout } from "../layout/AdaptiveWorkspaceLayout";
import { AndroidWorkspaceNavigation, FloatingWorkspaceTabs } from "./AndroidWorkspaceNavigation";
import {
useAndroidFloatingTabs,
FLOATING_TABS,
floatingTabsMetrics,
} from "./floating-workspace-tabs";
import { FLOATING_TABS, floatingTabsMetrics } from "./floating-workspace-tabs";
import { WorkspaceTabsContext, useWorkspaceTabs } from "./WorkspaceTabsContext";
import { WorkspaceTabPanes } from "./WorkspaceTabPanes";
import type { WorkspaceTab } from "./workspace-tabs-state";
Expand Down
Expand Up
@@ -129,7 +126,7 @@ export function WorkspaceRootScreen() {
)}
</SafeAreaInsetsContext>
{floatingTabsEnabled ? (
<FloatingWorkspaceTabs onNewThread={startNewTask} />
<FloatingWorkspaceTabs fillWidth onNewThread={startNewTask} />
) : (
<AndroidWorkspaceNavigation onNewThread={startNewTask} />
)}
Expand Down
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
import { expect, it } from "vite-plus/test";
import { floatingTabsMetrics } from "./floating-workspace-tabs";
import { resolveAndroidNavigationStyle } from "../../lib/androidNavigationStyle";
it.each([
Expand All
@@ -17,3 +18,24 @@ it.each([
expect(resolveAndroidNavigationStyle(preference, manufacturer, preview)).toBe(expected);
},
);
it.each([
[475, 1, 56],
[411, 1, 56],
[475, 1.25, 70],
] as const)(
"fills a %sdp cover row at scale %s with a %sdp compose button",
(width, scale, fabSize) => {
const metrics = floatingTabsMetrics(4, scale, fabSize, width, true);
expect(metrics.sharesRow).toBe(true);
expect(metrics.pill + 2 * 16 + 12 + fabSize).toBe(width);
expect(metrics.height).toBe(fabSize);
},
);
it("stacks compose above a full-width pill when a cover row is too narrow", () => {
const metrics = floatingTabsMetrics(4, 1, 56, 300, true);
expect(metrics.sharesRow).toBe(false);
expect(metrics.pill).toBe(268);
expect(metrics.fabOffset).toBe(68);
});
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,3 @@
import { Platform } from "react-native";
import { useAppearancePreferences } from "../settings/appearance/AppearancePreferencesProvider";
export function useAndroidFloatingTabs() {
const { androidNavigationStyle } = useAppearancePreferences();
return Platform.OS === "android" && androidNavigationStyle === "one-ui";
}
// Native shadows need room inside the Expo view, which clips its children.
export const FLOATING_TABS = { edge: 16, gap: 12, shadow: 8 };
Expand All
@@ -14,6 +6,7 @@ export function floatingTabsMetrics(
scale: number,
fabSize: number,
paneWidth?: number,
fillWidth = false,
) {
const unit = Math.max(1, scale);
const height = fabSize;
Expand All
@@ -27,7 +20,8 @@ export function floatingTabsMetrics(
? paneWidth - beside
: paneWidth - 2 * FLOATING_TABS.edge;
return {
pill: Math.min(count * 72 * unit, Math.max(0, room)),
// Reserve the compose slot even while its button is hidden.
pill: Math.max(0, fillWidth ? room : Math.min(count * 72 * unit, room)),
height,
row,
sharesRow,
Expand Down
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.