You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1 line
7.2 KiB
1 line
7.2 KiB
{"ast":null,"code":"import _asyncToGenerator from \"@babel/runtime/helpers/asyncToGenerator\";\nimport _objectWithoutProperties from \"@babel/runtime/helpers/objectWithoutProperties\";\nimport _slicedToArray from \"@babel/runtime/helpers/slicedToArray\";\nvar _excluded = [\"get\", \"request\"];\nimport { useCallback, useEffect, useRef, useState } from 'react';\nfunction usePermission(methods, options) {\n var isMounted = useRef(true);\n var _useState = useState(null),\n _useState2 = _slicedToArray(_useState, 2),\n status = _useState2[0],\n setStatus = _useState2[1];\n var _ref = options || {},\n _ref$get = _ref.get,\n get = _ref$get === void 0 ? true : _ref$get,\n _ref$request = _ref.request,\n request = _ref$request === void 0 ? false : _ref$request,\n permissionOptions = _objectWithoutProperties(_ref, _excluded);\n var getPermission = useCallback(_asyncToGenerator(function* () {\n var response = yield methods.getMethod(Object.keys(permissionOptions).length > 0 ? permissionOptions : undefined);\n if (isMounted.current) setStatus(response);\n return response;\n }), [methods.getMethod]);\n var requestPermission = useCallback(_asyncToGenerator(function* () {\n var response = yield methods.requestMethod(Object.keys(permissionOptions).length > 0 ? permissionOptions : undefined);\n if (isMounted.current) setStatus(response);\n return response;\n }), [methods.requestMethod]);\n useEffect(function runMethods() {\n if (request) requestPermission();\n if (!request && get) getPermission();\n }, [get, request, requestPermission, getPermission]);\n useEffect(function didMount() {\n isMounted.current = true;\n return function () {\n isMounted.current = false;\n };\n }, []);\n return [status, requestPermission, getPermission];\n}\nexport function createPermissionHook(methods) {\n return function (options) {\n return usePermission(methods, options);\n };\n}","map":{"version":3,"mappings":";;;;AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AA6BhE,SAASC,aAAa,CACpBC,OAAmD,EACnDC,OAAwC;EAExC,IAAMC,SAAS,GAAGL,MAAM,CAAC,IAAI,CAAC;EAC9B,gBAA4BC,QAAQ,C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H,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO,CAACZ,MAAM,EAAEa,iBAAiB,EAAER,aAAa,CAAC;AACnD;AAMA,OAAM,SAAUY,oBAAoB,CAClCpB,OAAmD;EAEnD,OAAO,UAACC,OAAwC;IAAA,OAC9CF,aAAa,CAAsBC,OAAO,EAAEC,OAAO,CAAC;EAAA;AACxD","names":["useCallback","useEffect","useRef","useState","usePermission","methods","options","isMounted","status","setStatus","get","request","permissionOptions","getPermission","response","getMethod","Object","keys","length","undefined","current","requestPermission","requestMethod","runMethods","didMount","createPermissionHook"],"sources":["/Users/mathildejean/Documents/BUT/LaSuperMeteo/LaSuperMeteo/iut-expo-starter/node_modules/expo-modules-core/src/PermissionsHook.ts"],"sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { PermissionResponse } from './PermissionsInterface';\n\n// These types are identical, but improves the readability for suggestions in editors\ntype RequestPermissionMethod<Permission extends PermissionResponse> = () => Promise<Permission>;\ntype GetPermissionMethod<Permission extends PermissionResponse> = () => Promise<Permission>;\n\ninterface PermissionHookMethods<Permission extends PermissionResponse, Options = never> {\n /** The permission method that requests the user to grant permission. */\n requestMethod: (options?: Options) => Promise<Permission>;\n /** The permission method that only fetches the current permission status. */\n getMethod: (options?: Options) => Promise<Permission>;\n}\n\ninterface PermissionHookBehavior {\n /** If the hook should automatically fetch the current permission status, without asking the user. */\n get?: boolean;\n /** If the hook should automatically request the user to grant permission. */\n request?: boolean;\n}\n\nexport type PermissionHookOptions<Options extends object> = PermissionHookBehavior & Options;\n\n/**\n * Get or request permission for protected functionality within the app.\n * It uses separate permission requesters to interact with a single permission.\n * By default, the hook will only retrieve the permission status.\n */\nfunction usePermission<Permission extends PermissionResponse, Options extends object>(\n methods: PermissionHookMethods<Permission, Options>,\n options?: PermissionHookOptions<Options>\n): [Permission | null, RequestPermissionMethod<Permission>, GetPermissionMethod<Permission>] {\n const isMounted = useRef(true);\n const [status, setStatus] = useState<Permission | null>(null);\n const { get = true, request = false, ...permissionOptions } = options || {};\n\n const getPermission = useCallback(async () => {\n const response = await methods.getMethod(\n Object.keys(permissionOptions).length > 0 ? (permissionOptions as Options) : undefined\n );\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.getMethod]);\n\n const requestPermission = useCallback(async () => {\n const response = await methods.requestMethod(\n Object.keys(permissionOptions).length > 0 ? (permissionOptions as Options) : undefined\n );\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.requestMethod]);\n\n useEffect(\n function runMethods() {\n if (request) requestPermission();\n if (!request && get) getPermission();\n },\n [get, request, requestPermission, getPermission]\n );\n\n // Workaround for unmounting components receiving state updates\n useEffect(function didMount() {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return [status, requestPermission, getPermission];\n}\n\n/**\n * Create a new permission hook with the permission methods built-in.\n * This can be used to quickly create specific permission hooks in every module.\n */\nexport function createPermissionHook<Permission extends PermissionResponse, Options extends object>(\n methods: PermissionHookMethods<Permission, Options>\n) {\n return (options?: PermissionHookOptions<Options>) =>\n usePermission<Permission, Options>(methods, options);\n}\n"]},"metadata":{},"sourceType":"module","externalDependencies":[]} |