-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aeb16e0
commit dfad4a7
Showing
10 changed files
with
128 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import {useEffect, useState} from 'react'; | ||
import { | ||
AccessibilityInfo, | ||
AccessibilityChangeEvent, | ||
AccessibilityEvent, | ||
} from 'react-native' | ||
} from 'react-native'; | ||
|
||
export default function useAccessibilityInfo() { | ||
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false) | ||
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false) | ||
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false); | ||
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false); | ||
|
||
const handleReduceMotionChanged = (enabled: AccessibilityChangeEvent) => | ||
setReduceMotionEnabled(enabled) | ||
setReduceMotionEnabled(enabled); | ||
const handleScreenReaderChanged = (enabled: AccessibilityChangeEvent) => | ||
setScreenReaderEnabled(enabled) | ||
setScreenReaderEnabled(enabled); | ||
|
||
useEffect(() => { | ||
AccessibilityInfo.isReduceMotionEnabled().then(handleReduceMotionChanged) | ||
AccessibilityInfo.isScreenReaderEnabled().then(handleScreenReaderChanged) | ||
AccessibilityInfo.isReduceMotionEnabled().then(handleReduceMotionChanged); | ||
AccessibilityInfo.isScreenReaderEnabled().then(handleScreenReaderChanged); | ||
|
||
AccessibilityInfo.addEventListener( | ||
'reduceMotionChanged', | ||
handleReduceMotionChanged as (event: AccessibilityEvent) => void, | ||
) | ||
); | ||
AccessibilityInfo.addEventListener( | ||
'screenReaderChanged', | ||
handleScreenReaderChanged as (event: AccessibilityEvent) => void, | ||
) | ||
); | ||
|
||
return () => { | ||
AccessibilityInfo.removeEventListener( | ||
'reduceMotionChanged', | ||
handleReduceMotionChanged as (event: AccessibilityEvent) => void, | ||
) | ||
); | ||
AccessibilityInfo.removeEventListener( | ||
'screenReaderChanged', | ||
handleScreenReaderChanged as (event: AccessibilityEvent) => void, | ||
) | ||
} | ||
}, []) | ||
); | ||
}; | ||
}, []); | ||
|
||
return { reduceMotionEnabled, screenReaderEnabled } | ||
return {reduceMotionEnabled, screenReaderEnabled}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { AppState, AppStateStatus } from 'react-native' | ||
import {useEffect, useState} from 'react'; | ||
import {AppState, AppStateStatus} from 'react-native'; | ||
|
||
export default function useAppState() { | ||
const currentState = AppState.currentState | ||
const [appState, setAppState] = useState(currentState) | ||
const currentState = AppState.currentState; | ||
const [appState, setAppState] = useState(currentState); | ||
|
||
function onChange(newState: AppStateStatus) { | ||
setAppState(newState) | ||
setAppState(newState); | ||
} | ||
|
||
useEffect(() => { | ||
AppState.addEventListener('change', onChange) | ||
AppState.addEventListener('change', onChange); | ||
|
||
return () => { | ||
AppState.removeEventListener('change', onChange) | ||
} | ||
}) | ||
AppState.removeEventListener('change', onChange); | ||
}; | ||
}); | ||
|
||
return appState | ||
return appState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import React, { useEffect } from 'react' | ||
import { BackHandler } from 'react-native' | ||
import {useEffect} from 'react'; | ||
import {BackHandler} from 'react-native'; | ||
|
||
export default function useBackHandler(handler: () => void) { | ||
useEffect(() => { | ||
BackHandler.addEventListener('hardwareBackPress', handler) | ||
BackHandler.addEventListener('hardwareBackPress', handler); | ||
|
||
return () => { | ||
BackHandler.removeEventListener('hardwareBackPress', handler) | ||
} | ||
}) | ||
BackHandler.removeEventListener('hardwareBackPress', handler); | ||
}; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Clipboard } from 'react-native' | ||
import {useEffect, useState} from 'react'; | ||
import {Clipboard} from 'react-native'; | ||
|
||
export default function useClipBoard() { | ||
const [data, updateClipboardData] = useState('') | ||
const [data, updateClipboardData] = useState(''); | ||
|
||
async function updateClipboard() { | ||
const content = await Clipboard.getString() | ||
updateClipboardData(content) | ||
const content = await Clipboard.getString(); | ||
updateClipboardData(content); | ||
} | ||
|
||
useEffect(() => { | ||
updateClipboard() | ||
}, []) | ||
updateClipboard(); | ||
}, []); | ||
|
||
function setString(content: string) { | ||
Clipboard.setString(content) | ||
updateClipboardData(content) | ||
Clipboard.setString(content); | ||
updateClipboardData(content); | ||
} | ||
|
||
return [data, setString] | ||
return [data, setString]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,43 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Dimensions, ScaledSize } from 'react-native' | ||
import {useEffect, useState, useCallback} from 'react'; | ||
import {Dimensions, ScaledSize} from 'react-native'; | ||
|
||
const screen = Dimensions.get('screen') | ||
const screen = Dimensions.get('screen'); | ||
|
||
export default function() { | ||
const isOrientationPortrait = ({ | ||
width, | ||
height, | ||
}: { | ||
width: number | ||
height: number | ||
}) => height >= width | ||
width: number; | ||
height: number; | ||
}) => height >= width; | ||
const isOrientationLandscape = ({ | ||
width, | ||
height, | ||
}: { | ||
width: number | ||
height: number | ||
}) => width >= height | ||
width: number; | ||
height: number; | ||
}) => width >= height; | ||
|
||
const [orientation, setOrientation] = useState({ | ||
portrait: isOrientationPortrait(screen), | ||
landscape: isOrientationLandscape(screen), | ||
}) | ||
}); | ||
|
||
const onChange = ({ screen }: { screen: ScaledSize }) => { | ||
const onChange = useCallback(({screen}: {screen: ScaledSize}) => { | ||
setOrientation({ | ||
portrait: isOrientationPortrait(screen), | ||
landscape: isOrientationLandscape(screen), | ||
}) | ||
} | ||
}); | ||
}, []); | ||
|
||
useEffect(() => { | ||
Dimensions.addEventListener('change', onChange) | ||
Dimensions.addEventListener('change', onChange); | ||
|
||
return () => { | ||
Dimensions.removeEventListener('change', onChange) | ||
} | ||
}, [orientation.portrait, orientation.landscape]) | ||
Dimensions.removeEventListener('change', onChange); | ||
}; | ||
}, [orientation.portrait, orientation.landscape, onChange]); | ||
|
||
return orientation | ||
return orientation; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { Dimensions, ScaledSize } from 'react-native' | ||
import {useEffect, useState} from 'react'; | ||
import {Dimensions, ScaledSize} from 'react-native'; | ||
|
||
const window = Dimensions.get('window') | ||
const screen = Dimensions.get('screen') | ||
const window = Dimensions.get('window'); | ||
const screen = Dimensions.get('screen'); | ||
|
||
export default function useDimensions() { | ||
const [dimensions, setDimensions] = useState({ | ||
window, | ||
screen, | ||
}) | ||
}); | ||
|
||
const onChange = ({ | ||
window, | ||
screen, | ||
}: { | ||
window: ScaledSize | ||
screen: ScaledSize | ||
window: ScaledSize; | ||
screen: ScaledSize; | ||
}) => { | ||
setDimensions({ window, screen }) | ||
} | ||
setDimensions({window, screen}); | ||
}; | ||
|
||
useEffect(() => { | ||
Dimensions.addEventListener('change', onChange) | ||
Dimensions.addEventListener('change', onChange); | ||
|
||
return () => Dimensions.removeEventListener('change', onChange) | ||
}, []) | ||
return () => Dimensions.removeEventListener('change', onChange); | ||
}, []); | ||
|
||
return dimensions | ||
return dimensions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import React, { useEffect, useState } from 'react' | ||
import { InteractionManager } from 'react-native' | ||
import {useEffect, useState} from 'react'; | ||
import {InteractionManager} from 'react-native'; | ||
|
||
export default function useInteractionManager() { | ||
const [complete, updateInteractionStatus] = useState(false) | ||
const [complete, updateInteractionStatus] = useState(false); | ||
|
||
useEffect(() => { | ||
InteractionManager.runAfterInteractions(() => { | ||
updateInteractionStatus(true) | ||
}) | ||
}, []) | ||
return complete | ||
updateInteractionStatus(true); | ||
}); | ||
}, []); | ||
return complete; | ||
} |
Oops, something went wrong.