Skip to content

Commit

Permalink
feat: split up regular and credo flow
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>
  • Loading branch information
berendsliedrecht committed Sep 26, 2024
1 parent ece1994 commit 8640fdb
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 134 deletions.
82 changes: 25 additions & 57 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,37 @@
import { isBleEnabled } from '@animo-id/react-native-ble-didcomm'
import * as React from 'react'
import { Alert, Button, PermissionsAndroid, Platform, StyleSheet, Text, View } from 'react-native'
import { Central } from './Central'
import { Peripheral } from './Peripheral'
import { Spacer } from './Spacer'
import React, { type ReactElement, useState } from 'react'
import { Button, StyleSheet, View } from 'react-native'

const requestPermissions = async () => {
await PermissionsAndroid.requestMultiple([
'android.permission.ACCESS_FINE_LOCATION',
'android.permission.BLUETOOTH_CONNECT',
'android.permission.BLUETOOTH_SCAN',
'android.permission.BLUETOOTH_ADVERTISE',
'android.permission.ACCESS_COARSE_LOCATION',
])
}
import { Spacer } from './Spacer'
import { RegularScreen } from './regular/Screen'

export const App = () => {
const [isCentral, setIsCentral] = React.useState<boolean>(false)
const [isPeripheral, setIsPeripheral] = React.useState<boolean>(false)
const [flow, setFlow] = useState<'regular' | 'credo'>(undefined)

let component: ReactElement

const asCentral = () => setIsCentral(true)
if (!flow) {
component = (
<>
<Button title="credo flow" onPress={() => setFlow('credo')} />
<Spacer />
<Button title="regular flow" onPress={() => setFlow('regular')} />
</>
)
}

const asPeripheral = () => setIsPeripheral(true)
if (flow === 'regular') {
component = <RegularScreen />
}

if (flow === 'credo') {
component = <RegularScreen />
}

return (
<View style={styles.container}>
<Text>foo Bluetooth demo screen. role: {isCentral ? 'central' : isPeripheral ? 'peripheral' : 'none'}</Text>
<Spacer />
<Button title="is ble enabled :)" onPress={() => isBleEnabled().then(console.log)} />
<Button title="reset" onPress={() => setFlow(undefined)} />
<Spacer />
{Platform.OS === 'android' && (
<Button
title="requestPermissions"
onPress={async () => {
await requestPermissions()
}}
/>
)}
<Spacer />
{(isCentral || isPeripheral) && (
<>
<Button
title="Back"
onPress={() => {
setIsCentral(false)
setIsPeripheral(false)
}}
/>
<Spacer />
</>
)}
{!isCentral && !isPeripheral && (
<>
<Button title="Central" onPress={asCentral} />
<Spacer />
<Button title="Peripheral" onPress={asPeripheral} />
</>
)}
{isCentral && <Central />}
{isPeripheral && <Peripheral />}
{component}
</View>
)
}
Expand All @@ -69,9 +42,4 @@ const styles = StyleSheet.create({
alignItems: 'center',
justifyContent: 'center',
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
})
30 changes: 9 additions & 21 deletions example/src/RequestPermissions.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
import React from 'react'
import { Button, PermissionsAndroid } from 'react-native'
import { PermissionsAndroid } from 'react-native'

export const RequestPermissions = () => {
const requestPermissions = async () => {
await PermissionsAndroid.requestMultiple([
'android.permission.ACCESS_FINE_LOCATION',
'android.permission.BLUETOOTH_CONNECT',
'android.permission.BLUETOOTH_SCAN',
'android.permission.BLUETOOTH_ADVERTISE',
'android.permission.ACCESS_COARSE_LOCATION',
])
}

return (
<Button
title="requestPermissions"
onPress={async () => {
await requestPermissions()
}}
/>
)
export const requestPermissions = async () => {
await PermissionsAndroid.requestMultiple([
'android.permission.ACCESS_FINE_LOCATION',
'android.permission.BLUETOOTH_CONNECT',
'android.permission.BLUETOOTH_SCAN',
'android.permission.BLUETOOTH_ADVERTISE',
'android.permission.ACCESS_COARSE_LOCATION',
])
}
37 changes: 0 additions & 37 deletions example/src/bigPresentationMsg.ts

This file was deleted.

17 changes: 0 additions & 17 deletions example/src/presentationMsg.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import type React from 'react'
import { useMemo, useState } from 'react'
import { Button } from 'react-native'
import { Spacer } from './Spacer'
import { Spacer } from '../Spacer'

const msg = 'Hello from Central!'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import type React from 'react'
import { useMemo, useState } from 'react'
import { Button } from 'react-native'
import { Spacer } from './Spacer'
import { Spacer } from '../Spacer'

const msg = 'Hello from peripheral!'

Expand Down
Loading

0 comments on commit 8640fdb

Please sign in to comment.