Skip to content

Commit 8a4dc9d

Browse files
authored
Merge branch 'master' into patch-1
2 parents d482060 + 9bb5a3c commit 8a4dc9d

19 files changed

+1269
-315
lines changed

.eslintrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
extends: ['@react-native-community'],
3+
rules: {
4+
semi: 0,
5+
},
6+
}

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
bracketSpacing: false,
3+
jsxBracketSameLine: true,
4+
singleQuote: true,
5+
trailingComma: 'all',
6+
semi: false,
7+
};

.release-it.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"npm": {
3-
"publish": true
3+
"publish": true,
4+
"access": "public"
45
},
56
"github": {
67
"release": true

README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
![React Native Hooks](reactnativehooks.jpg)
22

33
## React Native Hooks
4+
5+
[![Version][version-badge]][package]
6+
47
React Native APIs turned into React Hooks allowing you to access asynchronous APIs directly in your functional components.
58

69
> Note: You must use React Native >= 0.59.0
710
811
### Installation with npm
912

1013
```sh
11-
npm install react-native-hooks
14+
npm install @react-native-community/hooks
1215
```
1316

1417
Installation with yarn
1518
```sh
16-
yarn add react-native-hooks
19+
yarn add @react-native-community/hooks
1720
```
1821

1922
## API
@@ -31,7 +34,7 @@ yarn add react-native-hooks
3134
### `useAccessibilityInfo`
3235

3336
```js
34-
import { useAccessibilityInfo } from 'react-native-hooks'
37+
import { useAccessibilityInfo } from '@react-native-community/hooks'
3538

3639
const isScreenReaderEnabled = useAccessibilityInfo()
3740
```
@@ -41,15 +44,15 @@ const isScreenReaderEnabled = useAccessibilityInfo()
4144
AppState will change between one of 'active', 'background', or (iOS) 'inactive' when the app is closed or put into the background.
4245

4346
```js
44-
import { useAppState } from 'react-native-hooks'
47+
import { useAppState } from '@react-native-community/hooks'
4548

4649
const currentAppState = useAppState()
4750
```
4851

4952
### `useBackHandler`
5053

5154
```js
52-
import { useBackHandler } from 'react-native-hooks'
55+
import { useBackHandler } from '@react-native-community/hooks'
5356

5457
useBackHandler(() => {
5558
if (shouldBeHandledHere) {
@@ -64,7 +67,7 @@ useBackHandler(() => {
6467
### `useCameraRoll`
6568

6669
```js
67-
import { useCameraRoll } from 'react-native-hooks'
70+
import { useCameraRoll } from '@react-native-community/hooks'
6871

6972
const [photos, getPhotos, saveToCameraRoll] = useCameraRoll()
7073

@@ -78,7 +81,7 @@ const [photos, getPhotos, saveToCameraRoll] = useCameraRoll()
7881
### `useClipboard`
7982

8083
```js
81-
import { useClipboard } from 'react-native-hooks'
84+
import { useClipboard } from '@react-native-community/hooks'
8285

8386
const [data, setString] = useClipboard()
8487

@@ -92,7 +95,7 @@ const [data, setString] = useClipboard()
9295
Gets dimensions and sets up a listener that will change the dimensions if the user changes device orientation.
9396

9497
```js
95-
import { useDimensions } from 'react-native-hooks'
98+
import { useDimensions } from '@react-native-community/hooks'
9699

97100
const dimensions = useDimensions()
98101
// or
@@ -104,7 +107,7 @@ const screen = useDimensions().screen
104107
### `useKeyboard`
105108

106109
```js
107-
import { useKeyboard } from 'react-native-hooks'
110+
import { useKeyboard } from '@react-native-community/hooks'
108111

109112
const keyboard = useKeyboard()
110113

@@ -115,7 +118,7 @@ console.log('keyboard keyboardHeight: ', keyboard.keyboardHeight)
115118
### `useInteractionManager`
116119

117120
```js
118-
import { useInteractionManager } from 'react-native-hooks'
121+
import { useInteractionManager } from '@react-native-community/hooks'
119122

120123
const interactionReady = useInteractionManager()
121124

@@ -125,7 +128,7 @@ console.log('interaction ready: ', interactionReady)
125128
### `useDeviceOrientation`
126129

127130
```js
128-
import { useDeviceOrientation } from 'react-native-hooks'
131+
import { useDeviceOrientation } from '@react-native-community/hooks'
129132

130133
const orientation = useDeviceOrientation()
131134

@@ -136,11 +139,14 @@ console.log('is orientation landscape: ', orientation.landscape)
136139
### `useLayout`
137140

138141
```js
139-
import { useLayout } from 'react-native-hooks'
142+
import { useLayout } from '@react-native-community/hooks'
140143

141144
const { onLayout, ...layout } = useLayout()
142145

143146
console.log('layout: ', layout)
144147

145148
<View onLayout={onLayout} style={{width: 200, height: 200, marginTop: 30}} />
146149
```
150+
151+
[version-badge]: https://img.shields.io/npm/v/@react-native-community/hooks.svg?style=flat-square
152+
[package]: https://www.npmjs.com/package/@react-native-community/hooks

index.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

package.json

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
{
2-
"name": "react-native-hooks",
3-
"version": "0.9.0",
2+
"name": "@react-native-community/hooks",
3+
"version": "2.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "lib/index.js",
6+
"types": "lib/index.d.ts",
67
"scripts": {
8+
"prepare": "yarn build",
79
"build": "yarn tsc",
810
"release": "release-it",
9-
"test": "echo \"Error: no test specified\" && exit 1"
11+
"test": "echo \"Error: no test specified\" && exit 1",
12+
"lint": "eslint src/**/*.ts"
1013
},
1114
"author": "Nader Dabit",
1215
"license": "ISC",
@@ -15,13 +18,16 @@
1518
"react-native": ">=0.59"
1619
},
1720
"devDependencies": {
21+
"@react-native-community/eslint-config": "^0.0.7",
1822
"@types/react": "^16.9.10",
19-
"@types/react-native": "^0.60.21",
23+
"@types/react-native": "^0.61.0",
24+
"eslint": "^6.8.0",
25+
"eslint-plugin-prettier": "^3.1.2",
26+
"prettier": "^1.19.1",
2027
"release-it": "^12.3.5",
2128
"typescript": "^3.6.4"
2229
},
2330
"files": [
24-
"index.js",
2531
"lib"
2632
]
2733
}

src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import useDimensions from './useDimensions'
2+
import useAppState from './useAppState'
3+
import useBackHandler from './useBackHandler'
4+
import useCameraRoll from './useCameraRoll'
5+
import useClipboard from './useClipboard'
6+
import useAccessibilityInfo from './useAccessibilityInfo'
7+
import useKeyboard from './useKeyboard'
8+
import useInteractionManager from './useInteractionManager'
9+
import useDeviceOrientation from './useDeviceOrientation'
10+
import useLayout from './useLayout'
11+
12+
export {
13+
useDimensions,
14+
useAppState,
15+
useBackHandler,
16+
useCameraRoll,
17+
useClipboard,
18+
useAccessibilityInfo,
19+
useKeyboard,
20+
useInteractionManager,
21+
useDeviceOrientation,
22+
useLayout,
23+
}

src/useAccessibilityInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react'
1+
import {useEffect, useState} from 'react'
22
import {
33
AccessibilityInfo,
44
AccessibilityChangeEvent,
@@ -39,5 +39,5 @@ export default function useAccessibilityInfo() {
3939
}
4040
}, [])
4141

42-
return { reduceMotionEnabled, screenReaderEnabled }
42+
return {reduceMotionEnabled, screenReaderEnabled}
4343
}

src/useAppState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React, { useEffect, useState } from 'react'
2-
import { AppState, AppStateStatus } from 'react-native'
1+
import {useEffect, useState} from 'react'
2+
import {AppState, AppStateStatus} from 'react-native'
33

44
export default function useAppState() {
55
const currentState = AppState.currentState
@@ -15,7 +15,7 @@ export default function useAppState() {
1515
return () => {
1616
AppState.removeEventListener('change', onChange)
1717
}
18-
})
18+
}, [])
1919

2020
return appState
2121
}

src/useBackHandler.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import React, { useEffect } from 'react'
2-
import { BackHandler } from 'react-native'
1+
import {useEffect} from 'react'
2+
import {BackHandler} from 'react-native'
33

4-
export default function useBackHandler(handler: () => void) {
4+
export default function useBackHandler(handler: () => boolean) {
55
useEffect(() => {
66
BackHandler.addEventListener('hardwareBackPress', handler)
77

8-
return () => {
9-
BackHandler.removeEventListener('hardwareBackPress', handler)
10-
}
11-
})
8+
return () => BackHandler.removeEventListener('hardwareBackPress', handler)
9+
}, [handler])
1210
}

0 commit comments

Comments
 (0)