Gathering detailed insights and metrics for @capacitor-community/device-react
Gathering detailed insights and metrics for @capacitor-community/device-react
Gathering detailed insights and metrics for @capacitor-community/device-react
Gathering detailed insights and metrics for @capacitor-community/device-react
npm install @capacitor-community/device-react
@capacitor-community/browser-react@0.1.0
Published on 17 Oct 2021
@capacitor-community/app-react@0.1.0
Published on 17 Oct 2021
@capacitor-community/clipboard-react@0.1.0
Published on 17 Oct 2021
@capacitor-community/camera-react@0.1.0
Published on 17 Oct 2021
@capacitor-community/device-react@0.1.0
Published on 17 Oct 2021
@capacitor-community/geolocation-react@0.1.0
Published on 17 Oct 2021
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
249 Stars
88 Commits
22 Forks
7 Watching
11 Branches
27 Contributors
Updated on 28 Oct 2024
TypeScript (75.39%)
JavaScript (11.8%)
CSS (7.56%)
Swift (3.21%)
Ruby (1.29%)
HTML (0.75%)
Cumulative downloads
Total Downloads
Last day
0%
3
Compared to previous day
Last week
5%
21
Compared to previous week
Last month
-10.9%
82
Compared to previous month
Last year
-69.6%
1,731
Compared to previous year
3
A set of hooks to help Capacitor developers use native Capacitor APIs.
Maintainer | GitHub | Social |
---|---|---|
Ely Lucas | elylucas | @elylucas |
These docs are for Capacitor 3 plugins. For docs that target v2 plugins, see the capv2 branch.
To start using Capacitor Hooks in your app, you install the React Hook package along with the Capacitor plugin you want to use. Here is an example of using the Storage plugin along with it's React hook:
1# Install the Capacitor Plugin 2npm install @capacitor/storage 3# And then the React hook package: 4npm install @capacitor-community/storage-react
Import the hooks:
1import { useStorage } from '@capacitor-community/storage-react'
Then use the hooks in your app:
1const [value, setValue] = useStorage('mykey');
While Capacitor allows you to write to one API across several platforms, not all features are supported on all platforms. It is encouraged to check if the feature you intend to use is available before using it to avoid any runtime errors.
Each of the hook plugin paths exports an availableFeatures
object, which contains a list features for that plugin. If the feature is supported for the current platform the app is running on, that feature will be true:
1const { useStorageItem, availableFeatures } = `@capacitor-community/storage-react`; 2const [value, setValue] = useStorage('mykey'); 3... 4if(availableFeatures.useStorage) { 5 // Storage is available, feel free to use it! 6 setValue('cake'); 7}
In Capacitor 3, all the plugins were separated into their own packages. Likewise, the new React hooks plugins were also put into their own package, so you will need to install the hook for each plugin you use.
Any deprecated API'S from Capacitor 2 to 3 were also removed and updated, so you might need to make some modifications to account for API changes. See the Capacitor Plugin API for to learn more.
Installation:
1npm install @capacitor-community/app-react
Usage:
1import { useAppState, useAppUrlOpen, useLaunchUrl, availableFeatures } from '@capacitor-community/app-react';
useAppState
provides access to App status information, such as whether the app is active or inactive. This value will update dynamically.
1const {state} = useAppState();
useLaunchUrl
useLaunchUrl
provides the URL the app was initially launched with. If you'd like to track future inbound URL events, use useAppUrlOpen
below instead.
1const { launchUrl } = useLaunchUrl();
useAppUrlOpen
useAppUrlOpen
provides the most recent URL used to activate the app. For example, if the user followed a link in another app that opened your app.
1const { appUrlOpen } = useAppUrlOpen();
See the App Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/browser-react
Usage:
1import { useClose, useOpen, availableFeatures } from '@capacitor-community/browser-react';
useOpen
, useClose
provides a way to launch, and close an in-app browser for external content:
1// Open url in browser 2const { open } = useOpen(); 3 4open({ url: 'http://ionicframework.com' }); 5 6// Close url in browser 7const { close } = useClose(); 8useClose();
See the Browser Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/camera-react
Usage:
1import { useCamera, availableFeatures } from '@capacitor-community/camera-react';
useCamera
provides a way to take a photo:
1const { photo, getPhoto } = useCamera(); 2const triggerCamera = useCallback(async () => { 3 getPhoto({ 4 quality: 100, 5 allowEditing: false, 6 resultType: CameraResultType.DataUrl 7 }) 8}, [getPhoto]); 9 10<div>{photo && <img alt="" src={photo.dataUrl} />}</div>
See the Camera Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/clipboard-react
Usage:
1import { useClipboard, availableFeatures } from '@capacitor-community/clipboard-react';
useClipboard
reads and writes clipboard data:
1const { value, getValue, setValue } = useClipboard(); 2 3const paste = useCallback(async () => { 4 await setValue('http://ionicframework.com/); 5}, [setValue]); 6 7const copy = useCallback(async () => { 8 getValue(); 9}, [getValue])
See the Clipboard Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/device-react
Usage:
1import { useGetInfo, useGetLanguageCode, availableFeatures } from '@capacitor-community/device-react';
useGetInfo
, useGetLanguageCode
gives access to device information and device language settings:
1const { info } = useGetInfo(); 2const { languageCode } = useGetLanguageCode();
See the Device Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/filesystem-react
Usage:
1import { useFilesystem, base64FromPath, availableFeatures } from '@capacitor-community/filesystem-react';
useFilesystem
returns back common methods to gain access to file system apis.
1const { readFile } = useFilesystem();
2
3const file = await readFile({
4 path: filepath,
5 directory: FilesystemDirectory.Data
6});
base64FromPath
is a helper method that will take in a path to a file and return back the base64 encoded representation of that file.
See the Filesystem Capacitor Plugin docs for more info on the plugin API.
1const base64String = await base64FromPath(path);
Installation:
1npm install @capacitor-community/geolocation-react
Usage:
1import { useCurrentPosition, useWatchPosition, availableFeatures } from '@capacitor-community/geolocation-react';
useCurrentPosition
returns a single geolocation position using the Geolocation API in Capacitor. The position can be manually updated by calling getPosition
:
1const { currentPosition, getPosition } = useCurrentPosition(); 2 3const handleRefreshPosition = () => { 4 getPosition(); 5}
useWatchPosition
tracks a geolocation position using the watchPosition
in the Geolocation API in Capacitor. The location will automatically begin updating, and you can use the clearWatch
and startWatch
methods to manually stop and restart the watch.
1const { currentPosition, startWatch, clearWatch } = useWatchPosition();
See the Geolocation Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/keyboard-react
Usage:
1import { useKeyboardState } from '@capacitor-community/keyboard';
useKeyboard
returns whether or not the on-screen keyboard is shown as well as an approximation of the keyboard height in pixels.
1const { isOpen, keyboardHeight } = useKeyboard(); 2// Use keyboardHeight to translate an input that would otherwise be hidden by the keyboard
See the Keyboard Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/network-react
Usage:
1import { useStatus, availableFeatures } from '@capacitor-community/network-react';
useStatus
monitors network status and information:
1 const { networkStatus } = useStatus();
See the Network Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/screen-reader-react
Usage:
1import { useIsScreenReaderEnabled, useSpeak, availableFeatures } from '@capacitor-community/screen-reader-react';
useIsScreenReaderEnabled
provides access to detecting and responding to a screen reading device or OS setting being enabled:
1const {isScreenReaderEnabled} = useIsScreenReaderEnabled();
useSpeak
activates a text-to-speech engine (if available) to read spoken text.
1const { speak } = useSpeak(); 2speak({value: textToSpeak})
See the ScreenReader Capacitor Plugin docs for more info on the plugin API.
Installation:
1npm install @capacitor-community/storage-react
Usage:
1import { useStorage, useStorageItem, availableFeatures } from '@capacitor-community/storage-react';
useStorage
provides access to Capacitor's storage engine. There is also a helper called useStorageItem
which makes managing a single item easy if you don't need to access the full Storage API (see below)
1const { get, set, remove, getKeys, clear } = useStorage(); 2useEffect(() => { 3 async function example() { 4 const value = await get('name'); 5 await set('name', 'Max'); 6 await remove('name'); 7 const allKeys = await getKeys(); 8 await clear(); 9 } 10}, [ get, set, remove, keys, clear ]);
useStorageItem
useStorageItem
tracks a single item and provides a nice way to read and write that item:
1const [ name , setName ] = useStorageItem('name', 'Max'); 2 3// Example: 4const updateName = useCallback((n) => { 5 setName(n); 6}, [ setName ]);
useStorageItem
will use the initial value already in storage, or the one provided if there is no existing value.
See the Storage Capacitor Plugin docs for more info on the plugin API.
This is an evolving project and not all of the Capacitor Plugins are supported yet. If there is one you need, feel free top open an issue for it, or better yet, submit a PR!
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
Found 7/29 approved changesets -- score normalized to 2
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
78 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More