Skip to content

Initialize web and mobile Aether projects #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 6 additions & 0 deletions apps/mobile/Aether/.buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

[android]
target = Google Inc.:Google APIs:23

[maven_repositories]
central = https://repo1.maven.org/maven2
3 changes: 3 additions & 0 deletions apps/mobile/Aether/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files
[*.bat]
end_of_line = crlf
4 changes: 4 additions & 0 deletions apps/mobile/Aether/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: '@react-native-community',
};
63 changes: 63 additions & 0 deletions apps/mobile/Aether/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
[ignore]
; We fork some components by platform
.*/*[.]android.js

; Ignore "BUCK" generated dirs
<PROJECT_ROOT>/\.buckd/

; Ignore polyfills
node_modules/react-native/Libraries/polyfills/.*

; Flow doesn't support platforms
.*/Libraries/Utilities/LoadingView.js

[untyped]
.*/node_modules/@react-native-community/cli/.*/.*

[include]

[libs]
node_modules/react-native/interface.js
node_modules/react-native/flow/

[options]
emoji=true

exact_by_default=true

module.file_ext=.js
module.file_ext=.json
module.file_ext=.ios.js

munge_underscores=true

module.name_mapper='^react-native/\(.*\)$' -> '<PROJECT_ROOT>/node_modules/react-native/\1'
module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '<PROJECT_ROOT>/node_modules/react-native/Libraries/Image/RelativeImageStub'

suppress_type=$FlowIssue
suppress_type=$FlowFixMe
suppress_type=$FlowFixMeProps
suppress_type=$FlowFixMeState

[lints]
sketchy-null-number=warn
sketchy-null-mixed=warn
sketchy-number=warn
untyped-type-import=warn
nonstrict-import=warn
deprecated-type=warn
unsafe-getters-setters=warn
unnecessary-invariant=warn
signature-verification-failure=warn

[strict]
deprecated-type
nonstrict-import
sketchy-null
unclear-type
unsafe-getters-setters
untyped-import
untyped-type-import

[version]
^0.149.0
3 changes: 3 additions & 0 deletions apps/mobile/Aether/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Windows files should use crlf line endings
# https://help.github.com/articles/dealing-with-line-endings/
*.bat text eol=crlf
59 changes: 59 additions & 0 deletions apps/mobile/Aether/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# OSX
#
.DS_Store

# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
*.moved-aside
DerivedData
*.hmap
*.ipa
*.xcuserstate

# Android/IntelliJ
#
build/
.idea
.gradle
local.properties
*.iml

# node.js
#
node_modules/
npm-debug.log
yarn-error.log

# BUCK
buck-out/
\.buckd/
*.keystore
!debug.keystore

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/

*/fastlane/report.xml
*/fastlane/Preview.html
*/fastlane/screenshots

# Bundle artifact
*.jsbundle

# CocoaPods
/ios/Pods/
7 changes: 7 additions & 0 deletions apps/mobile/Aether/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
bracketSpacing: false,
jsxBracketSameLine: true,
singleQuote: true,
trailingComma: 'all',
arrowParens: 'avoid',
};
1 change: 1 addition & 0 deletions apps/mobile/Aether/.watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
186 changes: 186 additions & 0 deletions apps/mobile/Aether/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
import React, {useEffect, useState} from 'react';
import {
ActivityIndicator,
FlatList,
Image,
PermissionsAndroid,
Platform,
SafeAreaView,
ScrollView,
StatusBar,
StyleSheet,
Text,
View,
TouchableOpacity,
} from 'react-native';
import Header from './components/Header';
import {BleService} from './service/BleService';
import {BleCallbackInfo, BlePeripheral} from './service/BleService.types';
import Constants from './styles/Constants';

let BluetoothService: BleService;

const App: React.FC = () => {
const [peripherals, setPeripherals] = useState<BlePeripheral[]>([]);
const [isScanning, setIsScanning] = useState(false);
const [isBleServiceReady, setIsBleServiceReady] = useState(false);

useEffect(() => {
BluetoothService = new BleService((info: BleCallbackInfo) => {
setIsScanning(info.isScanning);
setPeripherals(info.results);
});

BluetoothService.initialize();
checkPermissions();
setIsBleServiceReady(true);

return () => {
BluetoothService.remove();
};
}, []);

const checkPermissions = () => {
if (Platform.OS === 'android' && Platform.Version >= 23) {
PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
).then(result => {
if (result) {
console.log('Permission is OK - ', result);
} else {
PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
).then(result => {
if (result) {
console.log('User accept - ', result);
} else {
console.log('User refuse - ', result);
}
});
}
});
}
};

const renderItem = (item: BlePeripheral) => {
const color = item.connected ? 'green' : '#fff';
return (
<TouchableOpacity
style={styles.device}
onPress={() => BluetoothService.testPeripheral(item)}>
<View style={[styles.deviceInfo, {backgroundColor: color}]}>
<Text style={styles.deviceText}>{item.name}</Text>
<Image
style={styles.bluetoothImage}
source={require('./assets/BLE.png')}
/>
</View>
</TouchableOpacity>
);
};

if (!isBleServiceReady) {
return (
<View style={[styles.activityContainer, styles.activityHorizontal]}>
<ActivityIndicator size="large" color={Constants.colors.primary} />
</View>
);
}

return (
<View style={styles.screen}>
<StatusBar
barStyle="dark-content"
backgroundColor={Constants.colors.primary}
/>
<SafeAreaView>
<Header title="Connect Aether device" />
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View>
<View style={{margin: 10}}>
<TouchableOpacity
style={styles.buttonScan}
onPress={() => BluetoothService.startScan(3)}>
<Text style={styles.buttonScanText}>
{'Scan Bluetooth (' + (isScanning ? 'on' : 'off') + ')'}
</Text>
</TouchableOpacity>
</View>

<View style={{margin: 10}}>
<TouchableOpacity
style={styles.buttonScan}
onPress={() => BluetoothService.retrieveConnected()}>
<Text style={styles.buttonScanText}>
{'Retrieve connected peripherals'}
</Text>
</TouchableOpacity>
</View>

{peripherals.length == 0 && (
<View style={{flex: 1, margin: 20}}>
<Text style={{textAlign: 'center'}}>No peripherals</Text>
</View>
)}
</View>
</ScrollView>
<FlatList
data={peripherals}
renderItem={({item}) => renderItem(item)}
keyExtractor={item => item.id}
/>
</SafeAreaView>
</View>
);
};

const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: Constants.colors.screen,
},
device: {
backgroundColor: Constants.colors.white,
margin: 8,
padding: 10,
borderBottomWidth: 1,
borderBottomColor: Constants.colors.primary,
flexDirection: 'row',
},
deviceInfo: {
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
width: '100%',
},
deviceText: {
fontSize: 18,
textTransform: 'capitalize',
},
activityContainer: {
flex: 1,
justifyContent: 'center',
},
activityHorizontal: {
flexDirection: 'row',
justifyContent: 'space-around',
padding: 10,
},
bluetoothImage: {
width: 12,
height: 20,
},
buttonScan: {
backgroundColor: Constants.colors.primary,
padding: 8,
borderRadius: 4,
},
buttonScanText: {
color: Constants.colors.white,
textTransform: 'uppercase',
fontSize: 16,
textAlign: 'center',
},
});

export default App;
14 changes: 14 additions & 0 deletions apps/mobile/Aether/__tests__/App-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @format
*/

import 'react-native';
import React from 'react';
import App from '../App';

// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';

it('renders correctly', () => {
renderer.create(<App />);
});
Loading