Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Bluetooth changing ability and status check #90

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"react": "16.11.0",
"react-native": "0.62.2",
"react-native-background-fetch": "^3.0.4",
"react-native-bluetooth-status": "^1.5.1",
"react-native-config": "^1.1.0",
"react-native-gesture-handler": "^1.6.1",
"react-native-markdown-display": "^6.1.0",
Expand Down
6 changes: 0 additions & 6 deletions src/screens/home/views/BluetoothDisabledView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import {BaseHomeView} from '../components/BaseHomeView';

export const BluetoothDisabledView = () => {
const [i18n] = useI18n();
const toSettings = useCallback(() => {
Linking.openSettings();
}, []);

return (
<BaseHomeView>
Expand All @@ -23,9 +20,6 @@ export const BluetoothDisabledView = () => {
{i18n.translate('Home.EnableBluetoothCTA')}
</Text>
<LastCheckedDisplay />
<Box alignSelf="stretch" marginTop="l">
<Button text={i18n.translate('Home.TurnOnBluetooth')} variant="bigFlat" onPress={toSettings} />
</Box>
</BaseHomeView>
);
};
54 changes: 35 additions & 19 deletions src/screens/home/views/OverlayView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, {useCallback} from 'react';
import {Linking} from 'react-native';
import React, {useCallback, useState} from 'react';
import {Linking, Platform} from 'react-native';
import {useNavigation} from '@react-navigation/native';
import {Box, InfoBlock, BoxProps} from 'components';
import {useI18n, I18n} from '@shopify/react-i18n';
import {useBluetoothStatus} from 'react-native-bluetooth-status';
import {SystemStatus, useStartExposureNotificationService} from 'services/ExposureNotificationService';

import {InfoShareView} from './InfoShareView';
Expand All @@ -29,21 +30,32 @@ const SystemStatusOff = ({i18n}: {i18n: I18n}) => {
);
};

const BluetoothStatusOff = ({i18n}: {i18n: I18n}) => {
const toSettings = useCallback(() => {
Linking.openSettings();
}, []);
return (
<InfoBlock
icon="icon-bluetooth-off"
title={i18n.translate('OverlayOpen.BluetoothCardStatus')}
titleBolded={i18n.translate('OverlayOpen.BluetoothCardStatusOff')}
text={i18n.translate('OverlayOpen.BluetoothCardBody')}
button={{text: i18n.translate('OverlayOpen.BluetoothCardAction'), action: toSettings}}
backgroundColor="errorBackground"
color="errorText"
/>
);
const BluetoothStatusOff = ({action, i18n}: {action: () => void; i18n: I18n}) => {
if (Platform.OS !== 'android') {
return (
<InfoBlock
icon="icon-bluetooth-off"
title={i18n.translate('OverlayOpen.BluetoothCardStatus')}
titleBolded={i18n.translate('OverlayOpen.BluetoothCardStatusOff')}
text={i18n.translate('OverlayOpen.BluetoothCardBody')}
backgroundColor="errorBackground"
color="errorText"
/>
);
}
if (Platform.OS === 'android') {
return (
<InfoBlock
icon="icon-bluetooth-off"
title={i18n.translate('OverlayOpen.BluetoothCardStatus')}
titleBolded={i18n.translate('OverlayOpen.BluetoothCardStatusOff')}
text={i18n.translate('OverlayOpen.BluetoothCardBody')}
button={{text: i18n.translate('OverlayOpen.BluetoothCardAction'), action}}
backgroundColor="errorBackground"
color="errorText"
/>
);
}
};

const NotificationStatusOff = ({action, i18n}: {action: () => void; i18n: I18n}) => {
Expand All @@ -69,6 +81,10 @@ interface Props extends Pick<BoxProps, 'maxWidth'> {
export const OverlayView = ({status, notificationWarning, turnNotificationsOn, maxWidth}: Props) => {
const [i18n] = useI18n();
const navigation = useNavigation();
const [btStatus, isPending, setBluetooth] = useBluetoothStatus();
const setBluetoothAction = () => {
setBluetooth(true);
};

return (
<Box maxWidth={maxWidth}>
Expand All @@ -80,9 +96,9 @@ export const OverlayView = ({status, notificationWarning, turnNotificationsOn, m
<SystemStatusOff i18n={i18n} />
</Box>
)}
{status !== SystemStatus.Active && (
{!btStatus && (
<Box marginBottom="m" marginHorizontal="m">
<BluetoothStatusOff i18n={i18n} />
<BluetoothStatusOff action={setBluetoothAction} i18n={i18n} />
</Box>
)}
{notificationWarning && (
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,11 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@cs125/wait-until@^0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@cs125/wait-until/-/wait-until-0.0.3.tgz#957fc279121704845300dac47ee37a3b34c203d2"
integrity sha512-Z3+GXZbAjiiI0cJi1si+WfBBPfmLwZ9Tk4wqyFJGeZHJilyveBCpSktHdJlmqjHBBvrMi8ymXefYi2S833LhRA==

"@egjs/hammerjs@^2.0.17":
version "2.0.17"
resolved "https://registry.yarnpkg.com/@egjs/hammerjs/-/hammerjs-2.0.17.tgz#5dc02af75a6a06e4c2db0202cae38c9263895124"
Expand Down Expand Up @@ -7128,6 +7133,13 @@ react-native-background-fetch@^3.0.4:
plist "^3.0.1"
xcode "^2.0.0"

react-native-bluetooth-status@^1.5.1:
version "1.5.1"
resolved "https://registry.yarnpkg.com/react-native-bluetooth-status/-/react-native-bluetooth-status-1.5.1.tgz#3cb7d528b146fe15a0fc6127963f259901cbf3ab"
integrity sha512-d+7NvFhLh3FRJOWWrJQjDwg/X9KILViEwLW2BBocIBsWGdFoZR51oXUKkR/FpMZ03AQiedKMDOTbP9nKBIVIEg==
dependencies:
"@cs125/wait-until" "^0.0.3"

react-native-config@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-native-config/-/react-native-config-1.1.0.tgz#e59ee672ca6cd36599d86b806b22b129f1631ca2"
Expand Down