Skip to content

Commit

Permalink
Merged PR 37873: Create reusable screenlock hook
Browse files Browse the repository at this point in the history
Create reusable screenlock hook
  • Loading branch information
frankfe-amsterdam committed Jan 6, 2025
2 parents 6a7980c + 7752f38 commit e7dab42
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
12 changes: 12 additions & 0 deletions src/hooks/useLockScreen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import {lockAsync, OrientationLock, unlockAsync} from 'expo-screen-orientation'
import {useEffect} from 'react'

export const useLockScreen = (orientation: OrientationLock) => {
useEffect(() => {
void lockAsync(orientation)

return () => {
void unlockAsync()
}
}, [orientation])
}
15 changes: 5 additions & 10 deletions src/modules/access-code/components/AccessCodeKeyBoard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import {lockAsync, OrientationLock, unlockAsync} from 'expo-screen-orientation'
import {useCallback, useEffect, useMemo} from 'react'
import {OrientationLock} from 'expo-screen-orientation'
import {useCallback, useMemo} from 'react'
import {View, StyleSheet, Platform} from 'react-native'
import {EdgeInsets, useSafeAreaInsets} from 'react-native-safe-area-context'
import {Box} from '@/components/ui/containers/Box'
import {Column} from '@/components/ui/layout/Column'
import {Row} from '@/components/ui/layout/Row'
import {useAccessibilityAnnounce} from '@/hooks/accessibility/useAccessibilityAnnounce'
import {useLockScreen} from '@/hooks/useLockScreen'
import {AccessCodeKeyBoardKey} from '@/modules/access-code/components/AccessCodeKeyboardKey'
import {useAccessCode} from '@/modules/access-code/hooks/useAccessCode'
import {useAccessCodeBiometrics} from '@/modules/access-code/hooks/useAccessCodeBiometrics'
Expand All @@ -32,6 +33,8 @@ export const AccessCodeKeyBoard = ({onPressAuthenticate, type}: Props) => {
const {codeConfirmed} = useConfirmAccessCode()
const {codeLength} = useAccessCode()

useLockScreen(OrientationLock.PORTRAIT_UP)

const nextTextField = useMemo(() => {
switch (type) {
case AccessCodeType.codeEntered:
Expand All @@ -58,14 +61,6 @@ export const AccessCodeKeyBoard = ({onPressAuthenticate, type}: Props) => {
[accessibilityAnnounce, addDigit, codeLength, nextTextField, type],
)

useEffect(() => {
void lockAsync(OrientationLock.PORTRAIT_UP)

return () => {
void unlockAsync()
}
}, [])

return (
<View style={styles.container}>
<Box inset="sm">
Expand Down
13 changes: 4 additions & 9 deletions src/modules/city-pass/components/card-display/CityPasses.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {lockAsync, OrientationLock, unlockAsync} from 'expo-screen-orientation'
import {OrientationLock} from 'expo-screen-orientation'
import {useCallback, useEffect} from 'react'
import {AccessibilityInfo, Alert, StyleSheet, View} from 'react-native'
import {useDispatch} from '@/hooks/redux/useDispatch'
import {useBlockScreenshots} from '@/hooks/useBlockScreenshots'
import {useBrightScreen} from '@/hooks/useBrightScreen'
import {useLockScreen} from '@/hooks/useLockScreen'
import {useEnterAccessCode} from '@/modules/access-code/hooks/useEnterAccessCode'
import {CityPassesSwiper} from '@/modules/city-pass/components/card-display/CityPassesSwiper'
import {setStartIndex} from '@/modules/city-pass/slice'
Expand All @@ -19,18 +20,12 @@ export const CityPasses = ({index}: Props) => {
const {isCodeValid} = useEnterAccessCode()
const styles = useThemable(createStyles)

useLockScreen(OrientationLock.PORTRAIT_UP)

useEffect(() => {
dispatch(setStartIndex(index))
}, [dispatch, index])

useEffect(() => {
void lockAsync(OrientationLock.PORTRAIT_UP)

return () => {
void unlockAsync()
}
}, [])

const onScreenshot = useCallback(() => {
const screenshotMessage = 'Dit scherm staat geen schermafdrukken toe'

Expand Down

0 comments on commit e7dab42

Please sign in to comment.