Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 4 additions & 131 deletions src/features/keystone/ConnectKeystoneStartScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,140 +1,18 @@
/* eslint-disable react/jsx-props-no-spreading */
import Box from '@components/Box'
import ButtonPressable from '@components/ButtonPressable'
import SafeAreaBox from '@components/SafeAreaBox'
import Text from '@components/Text'
import { useNavigation } from '@react-navigation/native'
import WarningKeystone from '@assets/images/warningKeystone.svg'
import React, {
forwardRef,
ReactNode,
Ref,
useCallback,
useImperativeHandle,
useMemo,
useRef,
} from 'react'
import useCamera from '@hooks/useCamera'
import { BottomSheetBackdrop, BottomSheetModal } from '@gorhom/bottom-sheet'
import { useOpacity, useSpacing } from '@theme/themeHooks'
import useBackHandler from '@hooks/useBackHandler'
import { useTheme } from '@shopify/restyle'
import React, { useCallback } from 'react'
import { t } from 'i18next'
import { Image, Linking, Platform } from 'react-native'
import { Image } from 'react-native'
import { AddNewAccountNavigationProp } from '../home/addNewAccount/addNewAccountTypes'

type CameraPermissionBottomSheetAlertRef = {
show: () => void
dismiss: () => void
}

const CameraPermissionBottomSheetAlert = forwardRef(
(
{ children }: { children: ReactNode },
ref: Ref<CameraPermissionBottomSheetAlertRef>,
) => {
useImperativeHandle(ref, () => ({
show: () => {
bottomSheetModalRef.current?.present()
},
dismiss: () => {
bottomSheetModalRef.current?.dismiss()
},
}))

const bottomSheetModalRef = useRef<BottomSheetModal>(null)
const { backgroundStyle } = useOpacity('surfaceSecondary', 1)
const { m } = useSpacing()
const { colors } = useTheme()
const snapPoints = useMemo(() => ['40%'], [])
const sheetHandleStyle = useMemo(() => ({ padding: m }), [m])
const { handleDismiss } = useBackHandler(bottomSheetModalRef)
const handleIndicatorStyle = useMemo(() => {
return {
backgroundColor: colors.secondaryText,
}
}, [colors.secondaryText])
const renderBackdrop = useCallback(
(props) => (
<BottomSheetBackdrop
disappearsOnIndex={-1}
appearsOnIndex={0}
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
/>
),
[],
)

return (
<BottomSheetModal
ref={bottomSheetModalRef}
index={0}
backgroundStyle={backgroundStyle}
backdropComponent={renderBackdrop}
snapPoints={snapPoints}
handleStyle={sheetHandleStyle}
onDismiss={handleDismiss}
handleIndicatorStyle={handleIndicatorStyle}
>
{children}
</BottomSheetModal>
)
},
)

const WarningContent = () => {
const handleOpenSettings = () => {
if (Platform.OS === 'ios') {
Linking.openURL('app-settings:')
} else {
Linking.openSettings()
}
}
return (
<SafeAreaBox
flex={1}
justifyContent="center"
marginHorizontal="l"
edges={['bottom']}
>
<Box flex={1} justifyContent="center">
<Box alignItems="center">
<WarningKeystone />
<Text variant="body0" textAlign="center" marginVertical="l">
{t('keystone.connectKeystoneStart.warning') as string}
</Text>
</Box>
</Box>
<ButtonPressable
borderRadius="round"
onPress={handleOpenSettings}
backgroundColor="primaryText"
backgroundColorOpacityPressed={0.7}
backgroundColorDisabled="surfaceSecondary"
backgroundColorDisabledOpacity={0.5}
titleColorDisabled="black500"
titleColor="primary"
fontWeight="500"
title={t('keystone.connectKeystoneStart.ok')}
marginBottom="l"
/>
</SafeAreaBox>
)
}

const ConnectKeystoneStart = () => {
const { hasPermission } = useCamera()
const cameraPermissionBottomSheetAlertRef =
useRef<CameraPermissionBottomSheetAlertRef>(null)
const navigation = useNavigation<AddNewAccountNavigationProp>()
const handleStart = useCallback(() => {
if (!hasPermission) {
cameraPermissionBottomSheetAlertRef.current?.show()
} else {
navigation.navigate('KeystoneNavigator')
}
}, [navigation, hasPermission])
navigation.navigate('KeystoneNavigator')
}, [navigation])
return (
<SafeAreaBox
flex={1}
Expand All @@ -155,11 +33,6 @@ const ConnectKeystoneStart = () => {
</Text>
</Box>
</Box>
<CameraPermissionBottomSheetAlert
ref={cameraPermissionBottomSheetAlertRef}
>
<WarningContent />
</CameraPermissionBottomSheetAlert>
<ButtonPressable
borderRadius="round"
onPress={handleStart}
Expand Down
17 changes: 0 additions & 17 deletions src/hooks/useCamera.ts

This file was deleted.

Loading