Skip to content

Commit bdf8f63

Browse files
committed
more
1 parent 77409d3 commit bdf8f63

9 files changed

+44
-13
lines changed

src/useAccessibilityInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'
22
import { AccessibilityInfo } from 'react-native'
33

44

5-
export default () => {
5+
export default function useAccessibilityInfo() {
66
const [screenReaderEnabled, updateScreenReaderInfo] = useState(null)
77

88

src/useAppState.ts

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

44

5-
const currentState = AppState.currentState
6-
7-
export default () => {
5+
export default function useAppState() {
6+
const currentState = AppState.currentState
87
const [appState, setAppState] = useState(currentState)
98

109
function onChange(newState: AppStateStatus) {

src/useBackHandler.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React, { useEffect } from 'react'
2+
import { BackHandler } from 'react-native'
3+
4+
5+
export default function useBackHandler(handler) {
6+
useEffect(() => {
7+
BackHandler.addEventListener('hardwareBackPress', handler)
8+
9+
return () => {
10+
BackHandler.removeEventListener('hardwareBackPress', handler)
11+
}
12+
})
13+
}

src/useCameraRoll.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const defaultConfig: GetPhotosParamType = {
1818
groupTypes: 'All'
1919
}
2020

21-
export default function() {
21+
export default function useCameraRoll() {
2222
const [photos, setPhotos] = useState(initialState)
2323

2424
async function getPhotos(config = defaultConfig) {

src/useClipboard.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import React, { useEffect, useState } from 'react'
22
import { Clipboard } from 'react-native'
33

44

5-
export default () => {
5+
export default function useClipBoard() {
66
const [data, updateClipboardData] = useState('')
77

8+
async function updateClipboard() {
9+
const content = await Clipboard.getString()
10+
updateClipboardData(content);
11+
}
12+
813
useEffect(() => {
9-
(async () => {
10-
const content = await Clipboard.getString()
11-
updateClipboardData(content)
12-
})()
14+
updateClipboard()
1315
}, [])
1416

1517
function setString(content: string) {

src/useDeviceOrientation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Dimensions, ScaledSize } from 'react-native';
44

55
const screen = Dimensions.get('screen');
66

7-
export default () => {
7+
export default function() {
88
const isOrientationPortrait = ({ width, height }: { width: number, height: number }) => height >= width;
99
const isOrientationLandscape = ({ width, height }: { width: number, height: number }) => width >= height;
1010

src/useDimensions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Dimensions, ScaledSize } from 'react-native'
55
const window = Dimensions.get('window')
66
const screen = Dimensions.get('screen')
77

8-
export default () => {
8+
export default function useDimensions() {
99
const [dimensions, setDimensions] = useState({
1010
window, screen
1111
})

src/useInteractionManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import { InteractionManager } from 'react-native';
33

44

5-
export default () => {
5+
export default function useInteractionManager() {
66
const [complete, updateInteractionStatus] = useState(false);
77

88
useEffect(() => {

src/useLayout.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react'
2+
3+
4+
export default function useLayout() {
5+
const [layout, setLayout] = React.useState({
6+
x: 0,
7+
y: 0,
8+
width: 0,
9+
height: 0,
10+
})
11+
const onLayout = React.useCallback(e => setLayout(e.nativeEvent.layout), [])
12+
13+
return {
14+
onLayout,
15+
...layout,
16+
}
17+
}

0 commit comments

Comments
 (0)