Open History to see the last commit
1export interface IncomingSharePresentationState {
2 readonly presentedShareId: string | null;
3 readonly dismissedShareId: string | null;
4}
5
6export interface IncomingSharePresentationTransition {
7 readonly state: IncomingSharePresentationState;
8 readonly shareIdToPresent: string | null;
9}
10
11export const EMPTY_INCOMING_SHARE_PRESENTATION_STATE: IncomingSharePresentationState = {
12 presentedShareId: null,
13 dismissedShareId: null,
14};
15
16export function transitionIncomingSharePresentation(
17 state: IncomingSharePresentationState,
18 input: {
19 readonly isShareSheetPresented: boolean;
20 readonly pendingShareId: string | null;
21 },
22): IncomingSharePresentationTransition {
23 if (input.isShareSheetPresented) {
24 if (state.presentedShareId !== null && input.pendingShareId !== state.presentedShareId) {
25 // Consumption may happen while the sheet remains mounted. Forget the
26 // old presentation immediately so a later handoff may reuse its id.
27 return {
28 state: EMPTY_INCOMING_SHARE_PRESENTATION_STATE,
29 shareIdToPresent: null,
30 };
31 }
32 return { state, shareIdToPresent: null };
33 }
34
35 let nextState = state;
36 if (state.presentedShareId !== null) {
37 if (input.pendingShareId === state.presentedShareId) {
38 return {
39 state: {
40 presentedShareId: null,
41 dismissedShareId: state.presentedShareId,
42 },
43 shareIdToPresent: null,
44 };
45 }
46 nextState = { ...state, presentedShareId: null };
47 }
48
49 if (input.pendingShareId === null) {
50 return {
51 state: EMPTY_INCOMING_SHARE_PRESENTATION_STATE,
52 shareIdToPresent: null,
53 };
54 }
55
56 if (nextState.dismissedShareId === input.pendingShareId) {
57 return { state: nextState, shareIdToPresent: null };
58 }
59
60 return {
61 state: {
62 presentedShareId: input.pendingShareId,
63 dismissedShareId: null,
64 },
65 shareIdToPresent: input.pendingShareId,
66 };
67}