Skip to content

Commit dbfbe3e

Browse files
authored
upgrades and types (#322)
1 parent 8180637 commit dbfbe3e

21 files changed

+4369
-5776
lines changed

.circleci/config.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
version: 2.1
22

3-
43
orbs:
5-
rn: react-native-community/[email protected]
6-
4+
rn: react-native-community/[email protected]
75

86
jobs:
97
checkout_code:
@@ -44,23 +42,22 @@ jobs:
4442
name: Publish a release to NPM
4543
command: yarn release
4644

47-
4845
workflows:
49-
build-test-release:
50-
jobs:
51-
- checkout_code
52-
- analyze:
53-
requires:
54-
- checkout_code
55-
# - release-canary:
56-
# requires:
57-
# - analyze
58-
# filters:
59-
# branches:
60-
# ignore: master
61-
- release:
62-
requires:
63-
- analyze
64-
filters:
65-
branches:
66-
only: master
46+
build-test-release:
47+
jobs:
48+
- checkout_code
49+
- analyze:
50+
requires:
51+
- checkout_code
52+
# - release-canary:
53+
# requires:
54+
# - analyze
55+
# filters:
56+
# branches:
57+
# ignore: master
58+
- release:
59+
requires:
60+
- analyze
61+
filters:
62+
branches:
63+
only: master

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*.json]
2+
indent_style = space
3+
indent_size = 2

.github/workflows/release.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
name: Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Fetch tags # we need them for auto to work correctly
15+
run: git fetch --unshallow --tags
16+
- uses: actions/setup-node@v3
17+
with:
18+
node-version: 18
19+
cache: 'yarn'
20+
env:
21+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
22+
- name: Install deps
23+
run: yarn install
24+
- name: Build palette-mobile
25+
run: yarn build-lib:clean
26+
- name: Release new version
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
30+
run: yarn release

README.md

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ npm install @react-native-community/hooks
1515
```
1616

1717
Installation with yarn
18+
1819
```sh
1920
yarn add @react-native-community/hooks
2021
```
2122

2223
## API
24+
2325
- [useAccessibilityInfo](https://github.com/react-native-community/hooks#useaccessibilityinfo)
2426
- [useAppState](https://github.com/react-native-community/hooks#useappstate)
2527
- [useBackHandler](https://github.com/react-native-community/hooks#usebackhandler)
26-
- ~~[useCameraRoll](https://github.com/react-native-community/hooks#usecameraroll)~~
27-
- ~~[useClipboard](https://github.com/react-native-community/hooks#useclipboard)~~
28-
- [useDimensions](https://github.com/react-native-community/hooks#usedimensions)
2928
- [useImageDimensions](https://github.com/react-native-community/hooks#useImageDimensions)
3029
- [useKeyboard](https://github.com/react-native-community/hooks#usekeyboard)
3130
- [useInteractionManager](https://github.com/react-native-community/hooks#useinteractionmanager)
@@ -35,15 +34,15 @@ yarn add @react-native-community/hooks
3534
### `useAccessibilityInfo`
3635

3736
```js
38-
import { useAccessibilityInfo } from '@react-native-community/hooks'
37+
import {useAccessibilityInfo} from '@react-native-community/hooks'
3938

4039
const {
4140
boldTextEnabled,
4241
screenReaderEnabled,
4342
reduceMotionEnabled, // requires RN60 or newer
4443
grayscaleEnabled, // requires RN60 or newer
4544
invertColorsEnabled, // requires RN60 or newer
46-
reduceTransparencyEnabled // requires RN60 or newer
45+
reduceTransparencyEnabled, // requires RN60 or newer
4746
} = useAccessibilityInfo()
4847
```
4948

@@ -52,15 +51,15 @@ const {
5251
AppState will change between one of 'active', 'background', or (iOS) 'inactive' when the app is closed or put into the background.
5352

5453
```js
55-
import { useAppState } from '@react-native-community/hooks'
54+
import {useAppState} from '@react-native-community/hooks'
5655

5756
const currentAppState = useAppState()
5857
```
5958

6059
### `useBackHandler`
6160

6261
```js
63-
import { useBackHandler } from '@react-native-community/hooks'
62+
import {useBackHandler} from '@react-native-community/hooks'
6463

6564
useBackHandler(() => {
6665
if (shouldBeHandledHere) {
@@ -72,50 +71,6 @@ useBackHandler(() => {
7271
})
7372
```
7473

75-
### `useCameraRoll`
76-
77-
⚠️ **Deprecated**. Please use `useCameraRoll()` from [`@react-native-camera-roll/camera-roll`](https://github.com/react-native-cameraroll/react-native-cameraroll#usecameraroll)
78-
79-
```js
80-
import { useCameraRoll } from '@react-native-community/hooks'
81-
82-
const [photos, getPhotos, saveToCameraRoll] = useCameraRoll()
83-
84-
{
85-
photos.map((photo, index) => /* render photos */)
86-
}
87-
88-
<Button title='Get Photos' onPress={() => getPhotos()}>Get Photos</Button>
89-
```
90-
91-
### `useClipboard`
92-
93-
⚠️ **Deprecated**. Please use `useClipboard()` from [`@react-native-clipboard/clipboard`](https://github.com/react-native-clipboard/clipboard#useclipboard)
94-
95-
```js
96-
import { useClipboard } from '@react-native-community/hooks'
97-
98-
const [data, setString] = useClipboard()
99-
100-
<Text>{data}</Text>
101-
102-
<Button title='Update Clipboard' onPress={() => setString('new clipboard data')}>Set Clipboard</Button>
103-
```
104-
105-
### `useDimensions`
106-
107-
Gets dimensions and sets up a listener that will change the dimensions if the user changes device orientation.
108-
109-
```js
110-
import { useDimensions } from '@react-native-community/hooks'
111-
112-
const dimensions = useDimensions()
113-
// or
114-
const { width, height } = useDimensions().window
115-
// or
116-
const screen = useDimensions().screen
117-
```
118-
11974
### `useImageDimensions`
12075

12176
```js
@@ -127,7 +82,7 @@ const source = {uri: 'https://your.image.URI'}
12782

12883
const {dimensions, loading, error} = useImageDimensions(source)
12984

130-
if(loading || error || !dimensions) {
85+
if (loading || error || !dimensions) {
13186
return null
13287
}
13388
const {width, height, aspectRatio} = dimensions
@@ -136,7 +91,7 @@ const {width, height, aspectRatio} = dimensions
13691
### `useKeyboard`
13792

13893
```js
139-
import { useKeyboard } from '@react-native-community/hooks'
94+
import {useKeyboard} from '@react-native-community/hooks'
14095

14196
const keyboard = useKeyboard()
14297

@@ -147,7 +102,7 @@ console.log('keyboard keyboardHeight: ', keyboard.keyboardHeight)
147102
### `useInteractionManager`
148103

149104
```js
150-
import { useInteractionManager } from '@react-native-community/hooks'
105+
import {useInteractionManager} from '@react-native-community/hooks'
151106

152107
const interactionReady = useInteractionManager()
153108

@@ -157,12 +112,11 @@ console.log('interaction ready: ', interactionReady)
157112
### `useDeviceOrientation`
158113

159114
```js
160-
import { useDeviceOrientation } from '@react-native-community/hooks'
115+
import {useDeviceOrientation} from '@react-native-community/hooks'
161116

162117
const orientation = useDeviceOrientation()
163118

164-
console.log('is orientation portrait: ', orientation.portrait)
165-
console.log('is orientation landscape: ', orientation.landscape)
119+
console.log('orientation is:', orientation)
166120
```
167121

168122
### `useLayout`

jest.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
module.exports = {
22
testEnvironment: 'node',
33
preset: 'react-native',
4-
globals: {
5-
'ts-jest': {
6-
tsconfig: 'tsconfig.json',
7-
},
8-
},
94
transform: {
105
'^.+\\.jsx$': 'babel-jest',
116
'^.+\\.tsx?$': 'ts-jest',

package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@
1919
"react-native": ">=0.59"
2020
},
2121
"devDependencies": {
22-
"@auto-it/all-contributors": "9.28.3",
23-
"@auto-it/first-time-contributor": "9.28.3",
24-
"@react-native-community/eslint-config": "3.0.1",
25-
"@testing-library/react-hooks": "7.0.2",
26-
"@testing-library/react-native": "8.0.0",
27-
"@types/jest": "27.0.3",
28-
"@types/react": "16.14.21",
29-
"@types/react-native": "0.64.19",
30-
"all-contributors-cli": "6.20.0",
31-
"auto": "9.26.8",
32-
"eslint": "7.3.1",
33-
"eslint-plugin-prettier": "3.4.1",
34-
"jest": "27.4.3",
35-
"prettier": "2.5.1",
36-
"react": "17.0.2",
37-
"react-native": "0.62.3",
38-
"react-test-renderer": "17.0.2",
39-
"ts-jest": "27.1.1",
40-
"typescript": "3.9.10"
22+
"@auto-it/all-contributors": "10.37.6",
23+
"@auto-it/first-time-contributor": "10.37.6",
24+
"@react-native-community/eslint-config": "3.2.0",
25+
"@testing-library/react-hooks": "8.0.1",
26+
"@testing-library/react-native": "11.5.1",
27+
"@types/jest": "29.4.0",
28+
"@types/react": "18.0.27",
29+
"@types/react-native": "0.71.1",
30+
"all-contributors-cli": "6.24.0",
31+
"auto": "10.37.6",
32+
"eslint": "8.33.0",
33+
"eslint-plugin-prettier": "4.2.1",
34+
"jest": "29.4.1",
35+
"prettier": "2.8.3",
36+
"react": "18.2.0",
37+
"react-native": "0.71.1",
38+
"react-test-renderer": "18.2.0",
39+
"ts-jest": "29.0.5",
40+
"typescript": "4.9.5"
4141
},
4242
"author": "Nader Dabit",
4343
"repository": {

renovate.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"extends": [
3-
"config:base",
4-
":automergePatch"
5-
]
6-
}
2+
"extends": [
3+
"config:base",
4+
":automergePatch"
5+
]
6+
}

src/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import {useDimensions} from './useDimensions'
2-
import {useAppState, AppStateStatus} from './useAppState'
1+
import {useAppState} from './useAppState'
32
import {useBackHandler} from './useBackHandler'
4-
import {useCameraRoll} from './useCameraRoll'
5-
import {useClipboard} from './useClipboard'
63
import {useAccessibilityInfo} from './useAccessibilityInfo'
74
import {useKeyboard} from './useKeyboard'
85
import {useInteractionManager} from './useInteractionManager'
@@ -11,16 +8,12 @@ import {useLayout} from './useLayout'
118
import {useImageDimensions} from './useImageDimensions'
129

1310
export {
14-
useDimensions,
11+
useAccessibilityInfo,
1512
useAppState,
16-
AppStateStatus,
1713
useBackHandler,
18-
useCameraRoll,
19-
useClipboard,
20-
useAccessibilityInfo,
21-
useKeyboard,
22-
useInteractionManager,
2314
useDeviceOrientation,
24-
useLayout,
2515
useImageDimensions,
16+
useInteractionManager,
17+
useKeyboard,
18+
useLayout,
2619
}

src/useAccessibilityInfo.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ function useAccessibilityStateListener(
2828
)
2929

3030
return () => {
31-
// @ts-expect-error - React Native >= 0.65
32-
if (typeof subscription?.remove === 'function') {
33-
// @ts-expect-error - need update @types/[email protected]
34-
subscription.remove()
35-
} else {
36-
// React Native < 0.65
37-
AccessibilityInfo.removeEventListener(eventName, setIsEnabled)
38-
}
31+
subscription.remove()
3932
}
4033
}, [eventName, initializerName])
4134

src/useAppState.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,9 @@ export function useAppState() {
1313
const subscription = AppState.addEventListener('change', onChange)
1414

1515
return () => {
16-
// @ts-expect-error - React Native >= 0.65
17-
if (typeof subscription?.remove === 'function') {
18-
// @ts-expect-error - need update @types/[email protected]
19-
subscription.remove()
20-
} else {
21-
// React Native < 0.65
22-
AppState.removeEventListener('change', onChange)
23-
}
16+
subscription.remove()
2417
}
2518
}, [])
2619

2720
return appState
2821
}
29-
30-
export {AppStateStatus}

0 commit comments

Comments
 (0)