-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #377 from digitalfabrik/LUN-400-image-for-own-voca…
…bulary LUN-400: Image for own vocabulary
- Loading branch information
Showing
30 changed files
with
476 additions
and
121 deletions.
There are no files selected for viewing
File renamed without changes.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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 @@ | ||
module.exports = { readFile: jest.fn(() => Promise.resolve('image')) } |
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,75 @@ | ||
import React, { ReactElement, useEffect, useRef, useState } from 'react' | ||
import { AppState, Modal as RNModal, Platform } from 'react-native' | ||
import { PERMISSIONS, request, RESULTS } from 'react-native-permissions' | ||
import { widthPercentageToDP as wp } from 'react-native-responsive-screen' | ||
import styled from 'styled-components/native' | ||
|
||
import { CloseCircleIconBlue, CloseCircleIconWhite } from '../../assets/images' | ||
import { reportError } from '../services/sentry' | ||
import NotAuthorisedView from './NotAuthorisedView' | ||
|
||
const Container = styled.SafeAreaView` | ||
flex: 1; | ||
background-color: ${props => props.theme.colors.background}; | ||
` | ||
|
||
const Icon = styled.Pressable` | ||
align-self: flex-end; | ||
margin: ${props => `${props.theme.spacings.xs} ${props.theme.spacings.sm}`}; | ||
width: ${wp('7%')}px; | ||
height: ${wp('7%')}px; | ||
` | ||
|
||
interface Props { | ||
setVisible: (visible: boolean) => void | ||
children: ReactElement | ||
} | ||
|
||
const CameraOverlay = ({ setVisible, children }: Props): ReactElement => { | ||
const appState = useRef(AppState.currentState) | ||
|
||
const [isPressed, setIsPressed] = useState<boolean>(false) | ||
const [permissionRequested, setPermissionRequested] = useState<boolean>(false) | ||
const [permissionGranted, setPermissionGranted] = useState<boolean>(false) | ||
|
||
// Needed when navigating back from settings, when users selected "ask every time" as camera permission option | ||
useEffect(() => { | ||
if (!permissionRequested) { | ||
request(Platform.OS === 'ios' ? PERMISSIONS.IOS.CAMERA : PERMISSIONS.ANDROID.CAMERA) | ||
.then(result => setPermissionGranted(result === RESULTS.GRANTED)) | ||
.catch(reportError) | ||
.finally(() => setPermissionRequested(true)) | ||
} | ||
}, [permissionRequested]) | ||
|
||
useEffect(() => { | ||
const subscription = AppState.addEventListener('change', nextAppState => { | ||
if ((appState.current === 'inactive' || appState.current === 'background') && nextAppState === 'active') { | ||
setPermissionRequested(false) | ||
} | ||
appState.current = nextAppState | ||
}) | ||
return subscription.remove | ||
}, []) | ||
|
||
return ( | ||
<RNModal visible transparent animationType='fade' onRequestClose={() => setVisible(false)}> | ||
<Container> | ||
<Icon | ||
onPress={() => setVisible(false)} | ||
onPressIn={() => setIsPressed(true)} | ||
onPressOut={() => setIsPressed(false)}> | ||
{isPressed ? ( | ||
<CloseCircleIconBlue testID='close-circle-icon-blue' width={wp('7%')} height={wp('7%')} /> | ||
) : ( | ||
<CloseCircleIconWhite testID='close-circle-icon-white' width={wp('7%')} height={wp('7%')} /> | ||
)} | ||
</Icon> | ||
{permissionGranted && children} | ||
{permissionRequested && !permissionGranted && <NotAuthorisedView setVisible={setVisible} />} | ||
</Container> | ||
</RNModal> | ||
) | ||
} | ||
|
||
export default CameraOverlay |
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
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,37 @@ | ||
import { fireEvent } from '@testing-library/react-native' | ||
import React from 'react' | ||
import { Text } from 'react-native' | ||
|
||
import render from '../../testing/render' | ||
import CameraOverlay from '../CameraOverlay' | ||
|
||
jest.mock('react-native-permissions', () => require('react-native-permissions/mock')) | ||
|
||
describe('CameraOverlay', () => { | ||
const setVisible = jest.fn() | ||
|
||
it('should show close header with correct icon', async () => { | ||
const { getByTestId, queryByTestId, findByTestId } = render( | ||
<CameraOverlay setVisible={setVisible}> | ||
<Text>Children</Text> | ||
</CameraOverlay> | ||
) | ||
const closeIcon = await findByTestId('close-circle-icon-white') | ||
expect(closeIcon).toBeDefined() | ||
fireEvent(closeIcon, 'onPressIn') | ||
expect(getByTestId('close-circle-icon-blue')).toBeDefined() | ||
expect(queryByTestId('close-circle-icon-white')).toBeNull() | ||
}) | ||
|
||
it('should close overlay on icon press', async () => { | ||
const { findByTestId } = render( | ||
<CameraOverlay setVisible={setVisible}> | ||
<Text>Children</Text> | ||
</CameraOverlay> | ||
) | ||
const closeIcon = await findByTestId('close-circle-icon-white') | ||
expect(closeIcon).toBeDefined() | ||
fireEvent.press(closeIcon) | ||
expect(setVisible).toHaveBeenCalledWith(false) | ||
}) | ||
}) |
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
Oops, something went wrong.