All Projects → capacitor-community → React Hooks

capacitor-community / React Hooks

Licence: other
⚡️ React hooks for Capacitor ⚡️

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Hooks

Guark
Build awesome Golang desktop apps and beautiful interfaces with Vue.js, React.js, Framework 7, and more...
Stars: ✭ 334 (+140.29%)
Mutual labels:  hybrid-apps
Hiapp
A simple and interesting hybrid app. React Native version: http://t.cn/R5LqqLz Demo:
Stars: ✭ 791 (+469.06%)
Mutual labels:  hybrid-apps
Micro sparrow
语雀的第三方APP
Stars: ✭ 71 (-48.92%)
Mutual labels:  hybrid-apps
Bookchatapp
通用书籍阅读APP,BookChat 的 uni-app 实现版本,支持多端分发,编译生成Android和iOS 手机APP以及各平台的小程序
Stars: ✭ 410 (+194.96%)
Mutual labels:  hybrid-apps
React Native Hiapp
HiApp written in react-native.
Stars: ✭ 634 (+356.12%)
Mutual labels:  hybrid-apps
Google Login With Ionic Framework
Ionic example app of how to add Google Plus authentication into an Ionic Framework app. Add google login to your ionic app!
Stars: ✭ 24 (-82.73%)
Mutual labels:  hybrid-apps
Corber
CLI for building hybrid apps with Ember/Vue/Glimmer/Cordova
Stars: ✭ 327 (+135.25%)
Mutual labels:  hybrid-apps
Nwjs rpi
[NW.js port for Raspberry Pi] binary compiled for the ARMv6 used in Raspberry Pi (compatible with RPi 2 and RPi 3)
Stars: ✭ 91 (-34.53%)
Mutual labels:  hybrid-apps
Blog
博客
Stars: ✭ 781 (+461.87%)
Mutual labels:  hybrid-apps
Shopping List
A series of Offline First shopping list demo apps, each built using a different stack.
Stars: ✭ 68 (-51.08%)
Mutual labels:  hybrid-apps
Phonon
Phonon is a responsive front-end framework with a focus on simplicity and flexibility
Stars: ✭ 425 (+205.76%)
Mutual labels:  hybrid-apps
Rexxar Ios
Mobile Hybrid Framework Rexxar iOS Container
Stars: ✭ 578 (+315.83%)
Mutual labels:  hybrid-apps
Mobile restaurant
👾 Online Restaurant App on Mobile DEVICE
Stars: ✭ 33 (-76.26%)
Mutual labels:  hybrid-apps
Pull To Reload
Pull to reload implementation for the web. Designed to work with both mobile and websites.
Stars: ✭ 396 (+184.89%)
Mutual labels:  hybrid-apps
Weexplus
🔨基于阿里WeexSDK跨平台方案,在原有的组件基础上,提供weex调用android native方法的一套扩展通信交互库,包含页面导航、数据存储、图片选择、二维码识别、权限等。
Stars: ✭ 73 (-47.48%)
Mutual labels:  hybrid-apps
Vue2 Hybridapp Haoshiqi
vue2+vue-router+vuex+cordova 实现单页面webapp以及hybridapp
Stars: ✭ 332 (+138.85%)
Mutual labels:  hybrid-apps
Polyonic
A managed Electron wrapper for Ionic Apps
Stars: ✭ 24 (-82.73%)
Mutual labels:  hybrid-apps
Mobiscroll
Cross platform UI controls for progressive web and hybrid apps (plain JS, jQuery, Angular and React)
Stars: ✭ 1,510 (+986.33%)
Mutual labels:  hybrid-apps
React Native Line
Line SDK wrapper for React Native 🚀
Stars: ✭ 80 (-42.45%)
Mutual labels:  hybrid-apps
Onsenui
Mobile app development framework and SDK using HTML5 and JavaScript. Create beautiful and performant cross-platform mobile apps. Based on Web Components, and provides bindings for Angular 1, 2, React and Vue.js.
Stars: ✭ 8,518 (+6028.06%)
Mutual labels:  hybrid-apps

React Hooks for Capacitor

A set of hooks to help Capacitor developers use native Capacitor APIs.

This is a new project and we'd love your feedback! Is there a hook that we don't have in here you'd like to see? Or maybe a hook that should function differently than it does today? Let us know by filing an issue!

Support Status

This is a community-supported add-on to Capacitor. If you'd like to help maintain this repo or have an idea for a hook please file an issue or reach out to the team on Twitter.

This also means the core Capacitor team doesn't guarantee regular updates to this repo, but rather encourages the community to pitch in.

Getting Started

To start using Capacitor Hooks in your app, install the hooks library:

npm install @capacitor-community/react-hooks

Import the hooks from their own path: import { useStorage } from '@capacitor-community/react-hooks/storage'

Then use the hooks from that namespace in your app:

const [value, setValue] = useStorage('mykey');

Feature Detection

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.:

const { useStorageItem, availableFeatures } = `@capacitor-community/react-hooks/storage`;
const [value, setValue] = useStorage('mykey');
...
if(availableFeatures.useStorage) {
  setValue('cake');
}

Hook Usage

Accessibility Hooks

Import:

import { useIsScreenReaderEnabled, useSpeak, availableFeatures } from '@capacitor-community/react-hooks/accessibility';

useIsScreenReaderEnabled provides access to detecting and responding to a screen reading device or OS setting being enabled:

const {isScreenReaderEnabled} = useIsScreenReaderEnabled();

useSpeak activates a text-to-speech engine (if available) to read spoken text.

const { speak } = useSpeak();
speak({value: textToSpeak})

AppState Hooks

Import:

import { useAppState, useAppUrlOpen, useLaunchUrl, availableFeatures } from '@capacitor-community/react-hooks/app';

useAppState provides access to App status information, such as whether the app is active or inactive. This value will update dynamically.

const {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.

const { 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.

const { appUrlOpen } = useAppUrlOpen();

Browser Hooks

Import:

import { useClose, useOpen, usePrefetch, availableFeatures } from '@capacitor-community/react-hooks/browser';

useOpen, usePrefetch, useClose provides a way to launch, prefetch, and close an in-app browser for external content:

useEffect(() => {
  await usePrefetch(['http://ionicframework.com']);
  await useOpen('http://ionicframework.com');
  await useClose();
}, [useOpen, useClose, usePrefetch]);

Camera Hooks

Import:

import { useCamera, availableFeatures } from '@capacitor-community/react-hooks/camera';

useCamera provides a way to take a photo:

const { photo, getPhoto } = useCamera();
const triggerCamera = useCallback(async () => {
  getPhoto({
      quality: 100,
      allowEditing: false,
      resultType: CameraResultType.DataUrl
    })
}, [getPhoto]);

<div>{photo && <img alt="" src={photo.dataUrl} />}</div>

See the Camera Capacitor API for the options expected.

Clipboard Hooks

Import:

import { useClipboard, availableFeatures } from '@capacitor-community/react-hooks/clipboard';

useClipboard reads and writes clipboard data:

const { value, getValue, setValue } = useClipboard();

const paste = useCallback(async () => {
  await setValue('http://ionicframework.com/);
}, [setValue]);

const copy = useCallback(async () => {
  getValue(); 
}, [getValue])

Device Hooks

Import:

import { useGetInfo, useGetLanguageCode, availableFeatures } from '@capacitor-community/react-hooks/device';

useGetInfo, useGetLanguageCode gives access to device information and device language settings:

const { info } = useGetInfo();
const { languageCode } = useGetLanguageCode();

See the Device Capacitor API for the return type information.

Filesystem Hooks

import:

import { useFilesystem, base64FromPath, availableFeatures } from '@capacitor-community/react-hooks/filesystem';

useFilesystem returns back common methods to gain access to file system apis.

const { readFile } = useFilesystem();

const file = await readFile({
  path: filepath,
  directory: FilesystemDirectory.Data
});

See the Filesystem Capacitor API for description of all the methods and options.

base64FromPath is a helper method that will take in a path to a file and return back the base64 encoded representation of that file.

const base64String = await base64FromPath(path);

Geolocation Hooks

Import:

import { useCurrentPosition, useWatchPosition, availableFeatures } from '@capacitor-community/react-hooks/geolocation';

useCurrentPosition returns a single geolocation position using the Geolocation API in Capacitor. The position can be manually updated by calling getPosition:

const { currentPosition, getPosition } = useCurrentPosition();

const handleRefreshPosition = () => {
  getPosition();
}

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.

const { currentPosition, startWatch, clearWatch } = useWatchPosition();

See the Geolocation Capacitor API for the options expected.

Keyboard Hooks

Import:

import { useKeyboardState } from '@capacitor-community/react-hooks/keyboard';

useKeyboardState returns whether or not the on-screen keyboard is shown as well as an approximation of the keyboard height in pixels.

const { isOpen, keyboardHeight } = useKeyboardState();

// Use keyboardHeight to translate an input that would otherwise be hidden by the keyboard

Network Hooks

Import:

import { useStatus, availableFeatures } from '@capacitor-community/react-hooks/network';

useStatus monitors network status and information:

 const { networkStatus } = useStatus();

See the Network Capacitor API for the type of status.

Platform Hooks

Import:

import { usePlatform } from '@capacitor-community/react-hooks/platform';

usePlatform return the current platform supported by Capacitor. Can be web, ios, android, or electron.

const { platform } = usePlatform();

Storage Hooks

Import:

import { useStorage, useStorageItem, availableFeatures } from '@capacitor-community/react-hooks/storage';

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)

const { get, set, remove, getKeys, clear } = useStorage();
useEffect(() => {
  async function example() {
    const value = await get('name');
    await set('name', 'Max');
    await remove('name');
    const allKeys = await getKeys();
    await clear();
  }
}, [ get, set, remove, keys, clear ]);

useStorageItem

useStorageItem tracks a single item and provides a nice way to read and write that item:

const [ name , setName ] = useStorageItem('name', 'Max');

// Example:
const updateName = useCallback((n) => {
  setName(n);
}, [ setName ]);

useStorageItem will use the initial value already in storage, or the one provided if there is no existing value.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].