UI changes and audio fixes
This commit is contained in:
parent
4647b24ccc
commit
9e60fee6ee
|
@ -10,7 +10,12 @@ const Stack = createNativeStackNavigator();
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<NavigationContainer>
|
<NavigationContainer>
|
||||||
<Stack.Navigator initialRouteName="Home">
|
<Stack.Navigator
|
||||||
|
initialRouteName="Home"
|
||||||
|
screenOptions={{
|
||||||
|
headerShown: false, // This hides the navigation bar globally
|
||||||
|
}}
|
||||||
|
>
|
||||||
<Stack.Screen name="Home" component={HomeScreen} />
|
<Stack.Screen name="Home" component={HomeScreen} />
|
||||||
<Stack.Screen name="Camera" component={CameraScreen} />
|
<Stack.Screen name="Camera" component={CameraScreen} />
|
||||||
<Stack.Screen name="Main" component={Main} />
|
<Stack.Screen name="Main" component={Main} />
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 13 KiB |
Binary file not shown.
|
@ -3,9 +3,11 @@ import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
|
||||||
import { Camera } from "expo-camera";
|
import { Camera } from "expo-camera";
|
||||||
import { useNavigation } from "@react-navigation/native";
|
import { useNavigation } from "@react-navigation/native";
|
||||||
import { BarCodeScanner } from "expo-barcode-scanner";
|
import { BarCodeScanner } from "expo-barcode-scanner";
|
||||||
|
// import useSoundEffect from "../lib/useSoundEffect";
|
||||||
|
|
||||||
export default function CameraScreen() {
|
export default function CameraScreen() {
|
||||||
const [permission, requestPermission] = Camera.useCameraPermissions();
|
const [permission, requestPermission] = Camera.useCameraPermissions();
|
||||||
|
// const playYay = useSoundEffect(require("../../assets/yay.wav"));
|
||||||
|
|
||||||
const [scanned, setScanned] = useState(false);
|
const [scanned, setScanned] = useState(false);
|
||||||
const navigation = useNavigation();
|
const navigation = useNavigation();
|
||||||
|
@ -31,18 +33,20 @@ export default function CameraScreen() {
|
||||||
// setFacing((current) => (current === "back" ? "front" : "back"));
|
// setFacing((current) => (current === "back" ? "front" : "back"));
|
||||||
// }
|
// }
|
||||||
|
|
||||||
const handleBarCodeScanned = ({
|
const handleBarCodeScanned = async ({
|
||||||
type,
|
type,
|
||||||
data,
|
data,
|
||||||
}: {
|
}: {
|
||||||
type: string;
|
type: string;
|
||||||
data: string;
|
data: string;
|
||||||
}) => {
|
}) => {
|
||||||
|
// await playYay();
|
||||||
setScanned(true);
|
setScanned(true);
|
||||||
console.log(
|
console.log(
|
||||||
`Bar code with type ${type} and data ${data} has been scanned!`
|
`Bar code with type ${type} and data ${data} has been scanned!`
|
||||||
);
|
);
|
||||||
alert(`Scanned URL: ${data}`);
|
// alert(`Scanned URL: ${data}`);
|
||||||
|
|
||||||
navigation.navigate("Main", { scannedData: data });
|
navigation.navigate("Main", { scannedData: data });
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
|
@ -64,7 +68,9 @@ export default function CameraScreen() {
|
||||||
onPress={() => setScanned(false)}
|
onPress={() => setScanned(false)}
|
||||||
style={styles.button}
|
style={styles.button}
|
||||||
>
|
>
|
||||||
<Text style={styles.text}>Scan Again</Text>
|
<Text numberOfLines={1} style={styles.text}>
|
||||||
|
Scan Again
|
||||||
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
|
@ -78,6 +84,7 @@ const styles = StyleSheet.create({
|
||||||
flex: 1,
|
flex: 1,
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
justifyContent: "flex-end",
|
justifyContent: "flex-end",
|
||||||
|
position: "relative",
|
||||||
},
|
},
|
||||||
camera: {
|
camera: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
@ -85,18 +92,22 @@ const styles = StyleSheet.create({
|
||||||
buttonContainer: {
|
buttonContainer: {
|
||||||
backgroundColor: "transparent",
|
backgroundColor: "transparent",
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
margin: 20,
|
margin: 2,
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 44,
|
||||||
|
left: 4,
|
||||||
flex: 0.1,
|
flex: 0.1,
|
||||||
alignSelf: "flex-end",
|
alignSelf: "flex-end",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: "#000",
|
backgroundColor: "#000",
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
padding: 15,
|
paddingHorizontal: 8,
|
||||||
|
paddingVertical: 6,
|
||||||
},
|
},
|
||||||
text: {
|
text: {
|
||||||
fontSize: 18,
|
fontSize: 14,
|
||||||
color: "white",
|
color: "white",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,23 +23,23 @@ const styles = StyleSheet.create({
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
backgroundColor: "#fff",
|
backgroundColor: "#000",
|
||||||
},
|
},
|
||||||
circle: {
|
circle: {
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
borderRadius: 50,
|
borderRadius: 50,
|
||||||
backgroundColor: "black",
|
backgroundColor: "#fff",
|
||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
backgroundColor: "black",
|
backgroundColor: "#fff",
|
||||||
paddingHorizontal: 20,
|
paddingHorizontal: 20,
|
||||||
paddingVertical: 10,
|
paddingVertical: 10,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
},
|
},
|
||||||
buttonText: {
|
buttonText: {
|
||||||
color: "white",
|
color: "#000",
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useEffect, useCallback, useRef } from "react";
|
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import { View, Text, TouchableOpacity, StyleSheet } from "react-native";
|
import { View, Text, TouchableOpacity, StyleSheet, Image } from "react-native";
|
||||||
import * as FileSystem from "expo-file-system";
|
import * as FileSystem from "expo-file-system";
|
||||||
import { AVPlaybackStatus, AVPlaybackStatusSuccess, Audio } from "expo-av";
|
import { AVPlaybackStatus, AVPlaybackStatusSuccess, Audio } from "expo-av";
|
||||||
import { polyfill as polyfillEncoding } from "react-native-polyfill-globals/src/encoding";
|
import { polyfill as polyfillEncoding } from "react-native-polyfill-globals/src/encoding";
|
||||||
|
@ -7,6 +7,9 @@ import { create } from "zustand";
|
||||||
import useStore from "../lib/state";
|
import useStore from "../lib/state";
|
||||||
import { Animated } from "react-native";
|
import { Animated } from "react-native";
|
||||||
import * as Haptics from "expo-haptics";
|
import * as Haptics from "expo-haptics";
|
||||||
|
import useSoundEffect from "../lib/useSoundEffect";
|
||||||
|
import IconImage from "../../assets/qr.png";
|
||||||
|
import { useNavigation } from "@react-navigation/native";
|
||||||
|
|
||||||
interface MainProps {
|
interface MainProps {
|
||||||
route: {
|
route: {
|
||||||
|
@ -56,7 +59,9 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
polyfillEncoding();
|
polyfillEncoding();
|
||||||
const backgroundColorAnim = useRef(new Animated.Value(0)).current;
|
const backgroundColorAnim = useRef(new Animated.Value(0)).current;
|
||||||
const buttonBackgroundColorAnim = useRef(new Animated.Value(0)).current;
|
const buttonBackgroundColorAnim = useRef(new Animated.Value(0)).current;
|
||||||
|
const playPip = useSoundEffect(require("../../assets/pip.mp3"));
|
||||||
|
const playPop = useSoundEffect(require("../../assets/pop.mp3"));
|
||||||
|
const navigation = useNavigation();
|
||||||
const backgroundColor = backgroundColorAnim.interpolate({
|
const backgroundColor = backgroundColorAnim.interpolate({
|
||||||
inputRange: [0, 1],
|
inputRange: [0, 1],
|
||||||
outputRange: ["black", "white"], // Change as needed
|
outputRange: ["black", "white"], // Change as needed
|
||||||
|
@ -168,7 +173,8 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
websocket.binaryType = "blob";
|
websocket.binaryType = "blob";
|
||||||
|
|
||||||
websocket.onopen = () => {
|
websocket.onopen = () => {
|
||||||
setConnectionStatus(`Connected to ${scannedData}`);
|
setConnectionStatus(`Connected`);
|
||||||
|
// setConnectionStatus(`Connected to ${scannedData}`);
|
||||||
console.log("WebSocket connected");
|
console.log("WebSocket connected");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -318,47 +324,69 @@ const Main: React.FC<MainProps> = ({ route }) => {
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<Animated.View style={[styles.container, { backgroundColor }]}>
|
<Animated.View style={[styles.container, { backgroundColor }]}>
|
||||||
<Text
|
{/* <TouchableOpacity
|
||||||
style={[
|
onPress={() => {
|
||||||
styles.statusText,
|
console.log("hi!");
|
||||||
{ color: connectionStatus.startsWith("Connected") ? "green" : "red" },
|
|
||||||
]}
|
navigation.navigate("Camera");
|
||||||
>
|
|
||||||
{connectionStatus}
|
|
||||||
</Text>
|
|
||||||
<TouchableOpacity
|
|
||||||
style={styles.button}
|
|
||||||
onPressIn={() => {
|
|
||||||
setIsPressed(true);
|
|
||||||
toggleRecording(true); // Pass true when pressed
|
|
||||||
startRecording();
|
|
||||||
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
|
|
||||||
}}
|
|
||||||
onPressOut={() => {
|
|
||||||
setIsPressed(false);
|
|
||||||
toggleRecording(false); // Pass false when released
|
|
||||||
stopRecording();
|
|
||||||
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Animated.View
|
<Animated.View style={styles.qr}>
|
||||||
style={[styles.circle, { backgroundColor: buttonBackgroundColor }]}
|
<Image source={IconImage} style={styles.icon} />
|
||||||
>
|
|
||||||
{/* <Text
|
|
||||||
style={
|
|
||||||
recording ? styles.buttonTextRecording : styles.buttonTextDefault
|
|
||||||
}
|
|
||||||
>
|
|
||||||
Record
|
|
||||||
</Text> */}
|
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity> */}
|
||||||
|
{/* <View style={styles.topBar}></View> */}
|
||||||
|
<View style={styles.middle}>
|
||||||
|
<Text
|
||||||
|
style={[
|
||||||
|
styles.statusText,
|
||||||
|
{
|
||||||
|
color: connectionStatus.startsWith("Connected") ? "green" : "red",
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{connectionStatus}
|
||||||
|
</Text>
|
||||||
|
<TouchableOpacity
|
||||||
|
style={styles.button}
|
||||||
|
onPressIn={() => {
|
||||||
|
playPip();
|
||||||
|
setIsPressed(true);
|
||||||
|
toggleRecording(true); // Pass true when pressed
|
||||||
|
startRecording();
|
||||||
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
|
||||||
|
}}
|
||||||
|
onPressOut={() => {
|
||||||
|
playPop();
|
||||||
|
setIsPressed(false);
|
||||||
|
toggleRecording(false); // Pass false when released
|
||||||
|
stopRecording();
|
||||||
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Animated.View
|
||||||
|
style={[styles.circle, { backgroundColor: buttonBackgroundColor }]}
|
||||||
|
>
|
||||||
|
{/* <Text
|
||||||
|
style={
|
||||||
|
recording ? styles.buttonTextRecording : styles.buttonTextDefault
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Record
|
||||||
|
</Text> */}
|
||||||
|
</Animated.View>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
</Animated.View>
|
</Animated.View>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
|
flex: 1,
|
||||||
|
position: "relative",
|
||||||
|
},
|
||||||
|
middle: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
@ -372,6 +400,23 @@ const styles = StyleSheet.create({
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
|
qr: {
|
||||||
|
position: "absolute",
|
||||||
|
top: 30,
|
||||||
|
left: 10,
|
||||||
|
padding: 10,
|
||||||
|
zIndex: 100,
|
||||||
|
},
|
||||||
|
icon: {
|
||||||
|
height: 40,
|
||||||
|
width: 40,
|
||||||
|
},
|
||||||
|
topBar: {
|
||||||
|
height: 40,
|
||||||
|
backgroundColor: "#000",
|
||||||
|
paddingTop: 50,
|
||||||
|
},
|
||||||
|
|
||||||
button: {
|
button: {
|
||||||
width: 100,
|
width: 100,
|
||||||
height: 100,
|
height: 100,
|
||||||
|
@ -389,7 +434,7 @@ const styles = StyleSheet.create({
|
||||||
},
|
},
|
||||||
statusText: {
|
statusText: {
|
||||||
position: "absolute",
|
position: "absolute",
|
||||||
bottom: 10,
|
bottom: 20,
|
||||||
alignSelf: "center",
|
alignSelf: "center",
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
|
|
|
@ -196,11 +196,11 @@ async def send_messages(websocket: WebSocket):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if isinstance(message, dict):
|
if isinstance(message, dict):
|
||||||
print(f"Sending to the device: {type(message)} {str(message)[:100]}")
|
# print(f"Sending to the device: {type(message)} {str(message)[:100]}")
|
||||||
await websocket.send_json(message)
|
await websocket.send_json(message)
|
||||||
elif isinstance(message, bytes):
|
elif isinstance(message, bytes):
|
||||||
message = base64.b64encode(message)
|
message = base64.b64encode(message)
|
||||||
print(f"Sending to the device: {type(message)} {str(message)[:100]}")
|
# print(f"Sending to the device: {type(message)} {str(message)[:100]}")
|
||||||
await websocket.send_bytes(message)
|
await websocket.send_bytes(message)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue