react-native-permission-handler 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,146 @@
1
+ import { Permission, PermissionStatus } from 'react-native-permissions';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { ReactNode } from 'react';
4
+
5
+ /**
6
+ * States of the permission flow state machine.
7
+ */
8
+ type PermissionFlowState = "idle" | "checking" | "prePrompt" | "requesting" | "granted" | "denied" | "blocked" | "blockedPrompt" | "openingSettings" | "recheckingAfterSettings" | "unavailable";
9
+ /**
10
+ * Events that drive state transitions.
11
+ */
12
+ type PermissionFlowEvent = {
13
+ type: "CHECK";
14
+ } | {
15
+ type: "CHECK_RESULT";
16
+ status: PermissionStatus;
17
+ } | {
18
+ type: "PRE_PROMPT_CONFIRM";
19
+ } | {
20
+ type: "PRE_PROMPT_DISMISS";
21
+ } | {
22
+ type: "REQUEST_RESULT";
23
+ status: PermissionStatus;
24
+ } | {
25
+ type: "OPEN_SETTINGS";
26
+ } | {
27
+ type: "SETTINGS_RETURN";
28
+ } | {
29
+ type: "RECHECK_RESULT";
30
+ status: PermissionStatus;
31
+ };
32
+ /**
33
+ * Configuration for the pre-prompt modal.
34
+ */
35
+ interface PrePromptConfig {
36
+ title: string;
37
+ message: string;
38
+ confirmLabel?: string;
39
+ cancelLabel?: string;
40
+ }
41
+ /**
42
+ * Configuration for the blocked-prompt modal.
43
+ */
44
+ interface BlockedPromptConfig {
45
+ title: string;
46
+ message: string;
47
+ settingsLabel?: string;
48
+ }
49
+ /**
50
+ * Callbacks for analytics and side effects.
51
+ */
52
+ interface PermissionCallbacks {
53
+ onGrant?: () => void;
54
+ onDeny?: () => void;
55
+ onBlock?: () => void;
56
+ onSettingsReturn?: (granted: boolean) => void;
57
+ }
58
+ /**
59
+ * Configuration for usePermissionHandler.
60
+ */
61
+ interface PermissionHandlerConfig extends PermissionCallbacks {
62
+ permission: Permission | "notifications";
63
+ prePrompt: PrePromptConfig;
64
+ blockedPrompt: BlockedPromptConfig;
65
+ autoCheck?: boolean;
66
+ recheckOnForeground?: boolean;
67
+ }
68
+ /**
69
+ * Return type of usePermissionHandler.
70
+ */
71
+ interface PermissionHandlerResult {
72
+ state: PermissionFlowState;
73
+ nativeStatus: PermissionStatus | null;
74
+ isGranted: boolean;
75
+ isDenied: boolean;
76
+ isBlocked: boolean;
77
+ isChecking: boolean;
78
+ isUnavailable: boolean;
79
+ request: () => void;
80
+ check: () => void;
81
+ dismiss: () => void;
82
+ openSettings: () => void;
83
+ }
84
+ /**
85
+ * Configuration for a single permission within useMultiplePermissions.
86
+ */
87
+ interface MultiPermissionEntry extends PermissionCallbacks {
88
+ permission: Permission | "notifications";
89
+ prePrompt: PrePromptConfig;
90
+ blockedPrompt: BlockedPromptConfig;
91
+ }
92
+ /**
93
+ * Configuration for useMultiplePermissions.
94
+ */
95
+ interface MultiplePermissionsConfig {
96
+ permissions: MultiPermissionEntry[];
97
+ strategy: "sequential" | "parallel";
98
+ onAllGranted?: () => void;
99
+ }
100
+ /**
101
+ * Return type of useMultiplePermissions.
102
+ */
103
+ interface MultiplePermissionsResult {
104
+ statuses: Record<string, PermissionFlowState>;
105
+ allGranted: boolean;
106
+ request: () => void;
107
+ }
108
+
109
+ declare function transition(state: PermissionFlowState, event: PermissionFlowEvent): PermissionFlowState;
110
+
111
+ declare function usePermissionHandler(config: PermissionHandlerConfig): PermissionHandlerResult;
112
+
113
+ declare function useMultiplePermissions(config: MultiplePermissionsConfig): MultiplePermissionsResult;
114
+
115
+ interface PermissionGateProps extends PermissionCallbacks {
116
+ permission: Permission | "notifications";
117
+ prePrompt: PrePromptConfig;
118
+ blockedPrompt: BlockedPromptConfig;
119
+ children: ReactNode;
120
+ fallback?: ReactNode;
121
+ renderPrePrompt?: (props: {
122
+ config: PrePromptConfig;
123
+ onConfirm: () => void;
124
+ onCancel: () => void;
125
+ }) => ReactNode;
126
+ renderBlockedPrompt?: (props: {
127
+ config: BlockedPromptConfig;
128
+ onOpenSettings: () => void;
129
+ }) => ReactNode;
130
+ }
131
+ declare function PermissionGate({ permission, prePrompt, blockedPrompt, children, fallback, renderPrePrompt, renderBlockedPrompt, onGrant, onDeny, onBlock, onSettingsReturn, }: PermissionGateProps): react_jsx_runtime.JSX.Element;
132
+
133
+ interface DefaultPrePromptProps extends PrePromptConfig {
134
+ visible: boolean;
135
+ onConfirm: () => void;
136
+ onCancel: () => void;
137
+ }
138
+ declare function DefaultPrePrompt({ visible, title, message, confirmLabel, cancelLabel, onConfirm, onCancel, }: DefaultPrePromptProps): react_jsx_runtime.JSX.Element;
139
+
140
+ interface DefaultBlockedPromptProps extends BlockedPromptConfig {
141
+ visible: boolean;
142
+ onOpenSettings: () => void;
143
+ }
144
+ declare function DefaultBlockedPrompt({ visible, title, message, settingsLabel, onOpenSettings, }: DefaultBlockedPromptProps): react_jsx_runtime.JSX.Element;
145
+
146
+ export { type BlockedPromptConfig, DefaultBlockedPrompt, type DefaultBlockedPromptProps, DefaultPrePrompt, type DefaultPrePromptProps, type MultiPermissionEntry, type MultiplePermissionsConfig, type MultiplePermissionsResult, type PermissionCallbacks, type PermissionFlowEvent, type PermissionFlowState, PermissionGate, type PermissionGateProps, type PermissionHandlerConfig, type PermissionHandlerResult, type PrePromptConfig, transition, useMultiplePermissions, usePermissionHandler };