Skip to content
Source
Sign inSign up

useOpenWorkspaceDetail.ts

20 lines996 Bytes

1import { StackActions, useNavigation } from "@react-navigation/native";
2import { Platform } from "react-native";
3​
4import { useSelectWorkspaceDetail } from "./workspace/useSelectWorkspaceDetail";
5import type { WorkspaceDetail, WorkspaceDetailSheet } from "./workspace/workspace-detail-selection";
6​
7/**
8 * Opens a thread or pull request from another page. Android shows one detail page at a time, so
9 * it selects the detail; iOS pushes it over the current page, so Back returns there. A `sheet`
10 * opens over the detail on Android and on its own over the current page on iOS.
11 */
12export function useOpenWorkspaceDetail() {
13 const navigation = useNavigation();
14 const selectDetail = useSelectWorkspaceDetail();
15 return (detail: WorkspaceDetail, sheet?: WorkspaceDetailSheet) => {
16 if (Platform.OS === "android") selectDetail(detail, sheet);
17 else if (sheet) navigation.navigate(sheet.name, sheet.params);
18 else navigation.dispatch(StackActions.push(detail.name, detail.params));
19 };