-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add listener, fix android window focus
Mapping func like react-native-orientation-locker typescript, fix android error window focus, update document readme
- Loading branch information
Showing
8 changed files
with
370 additions
and
78 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './useOrientationChange' | ||
export * from './useDeviceOrientationChange' | ||
export * from './useLockListener' |
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useRef, useEffect, MutableRefObject } from 'react' | ||
import Orientation, { OrientationCallback } from '../orientation' | ||
|
||
export const useDeviceOrientationChange = (callback: OrientationCallback): void => { | ||
const savedCallback: MutableRefObject<OrientationCallback | undefined> = useRef() | ||
|
||
useEffect(() => { | ||
savedCallback.current = callback | ||
}, [callback]) | ||
|
||
useEffect(() => { | ||
const listener = (ori: string): void => { | ||
if (savedCallback.current) { | ||
savedCallback.current(ori) | ||
} | ||
} | ||
const initial = Orientation.getInitialOrientation() | ||
listener(initial) | ||
Orientation.addDeviceOrientationListener(listener) | ||
|
||
return () => { | ||
Orientation.removeDeviceOrientationListener(listener) | ||
} | ||
}, []) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useRef, useEffect, MutableRefObject } from 'react' | ||
import Orientation, { OrientationCallback } from '../orientation' | ||
|
||
export const useLockListener = (callback: OrientationCallback): void => { | ||
const savedCallback: MutableRefObject<OrientationCallback | undefined> = useRef() | ||
|
||
useEffect(() => { | ||
savedCallback.current = callback | ||
}, [callback]) | ||
|
||
useEffect(() => { | ||
const listener = (ori: string): void => { | ||
if (savedCallback.current) { | ||
savedCallback.current(ori) | ||
} | ||
} | ||
Orientation.addLockListener(listener) | ||
|
||
return () => { | ||
Orientation.removeLockListener(listener) | ||
} | ||
}, []) | ||
} |
Oops, something went wrong.