forked from momolarson/BLEServiceDiscovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBLEservicecharacteristics.js
83 lines (76 loc) · 3.06 KB
/
BLEservicecharacteristics.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import React from 'react';
import { connect } from 'react-redux';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { SafeAreaView, View, FlatList, StyleSheet, Text, TouchableHighlight} from 'react-native';
import { selectedCharacteristic,getServiceCharacteristics} from './actions';
import DataActivityIndicator from './DataActivityIndicator';
function Item({ characteristic }) {
return (
<View style={styles.item}>
<Text style={styles.title}>{characteristic.uuid}</Text>
<Text style={styles.subtext}>Notifiable: {characteristic.isNotifiable.toString()}</Text>
<Text style={styles.subtext}>Notifying: {characteristic.isNotifying.toString()}</Text>
<Text style={styles.subtext}>Readable: {characteristic.isReadable.toString()}</Text>
<Text style={styles.subtext}>Indicatable: {characteristic.isIndicatable.toString()}</Text>
<Text style={styles.subtext}>Writeable with Response: {characteristic.isWritableWithResponse.toString()}</Text>
<Text style={styles.subtext}>Writeable without Response: {characteristic.isWritableWithoutResponse.toString()}</Text>
</View>
);
}
function handleClick (BLECharacteristic,characteristic){
console.log("handleclick:", BLECharacteristic);
BLECharacteristic.selectCharacteristic(characteristic);
BLECharacteristic.navigation.navigate('BLECharacteristic');
}
function BLEservicecharacteristics(BLECharacteristics) {
console.log("function:", BLECharacteristics);
BLECharacteristics.getServiceCharacteristics(BLECharacteristics.BLEService);
return(
<SafeAreaView style={styles.container}>
<FlatList
data={BLECharacteristics.BLEServiceCharacteristics}
renderItem={({ item }) =>
<TouchableHighlight
onPress={() => handleClick(BLECharacteristics,item)}
style={styles.rowFront}
underlayColor={'#AAA'}
>
<Item characteristic={item} />
</TouchableHighlight>}
keyExtractor={item => item.id.toString()}
ListEmptyComponent={DataActivityIndicator}
/>
</SafeAreaView>
);
}
//}
function mapStateToProps(state){
return{
BLEService:state.BLEs.selectedService,
BLEServiceCharacteristics:state.BLEs.connectedServiceCharacteristics,
};
}
const mapDispatchToProps = dispatch => ({
selectCharacteristic: characteristic => dispatch(selectedCharacteristic(characteristic)),
getServiceCharacteristics: service => dispatch(getServiceCharacteristics(service))
})
export default connect(mapStateToProps,mapDispatchToProps,null,{ forwardRef: true })(BLEservicecharacteristics);
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: 2,
},
item: {
backgroundColor: '#f9c2ff',
padding: 20,
marginVertical: 8,
marginHorizontal: 16,
},
title: {
fontSize: 14,
},
subtext: {
fontSize: 10,
}
});