- Backend: Update Legacy API credentials to robster/rob2 - Frontend: ROOM_LOCATIONS with icons and legacyCode mapping - Device Settings: Modal picker for room selection - api.ts: Bidirectional conversion (code ↔ name) - Various UI/UX improvements across screens PRD-DEPLOYMENT.md completed (Score: 9/10) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
127 lines
3.2 KiB
TypeScript
127 lines
3.2 KiB
TypeScript
import React, { useRef } from 'react';
|
|
import { View, StyleSheet, SafeAreaView } from 'react-native';
|
|
import { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
import { useRouter } from 'expo-router';
|
|
import { AppColors } from '@/constants/theme';
|
|
|
|
// Remote URL for the test page (loaded from server)
|
|
// Add cache-busting query param to force reload
|
|
const TEST_PAGE_URL = `https://wellnuo.smartlaunchhub.com/test-bridge.html?v=${Date.now()}`;
|
|
|
|
export default function BugScreen() {
|
|
const router = useRouter();
|
|
const webViewRef = useRef<WebView>(null);
|
|
|
|
// Handle messages from WebView
|
|
const handleMessage = (event: WebViewMessageEvent) => {
|
|
try {
|
|
const data = JSON.parse(event.nativeEvent.data);
|
|
|
|
switch (data.action) {
|
|
case 'NAVIGATE':
|
|
handleNavigation(data.screen);
|
|
break;
|
|
case 'NATIVE_FEATURE':
|
|
handleNativeFeature(data.feature);
|
|
break;
|
|
case 'CUSTOM':
|
|
handleCustomMessage(data.payload);
|
|
break;
|
|
default:
|
|
// Unknown action
|
|
break;
|
|
}
|
|
} catch (error) {
|
|
// Silently ignore parsing errors
|
|
}
|
|
};
|
|
|
|
// Navigate to different screens
|
|
const handleNavigation = (screen: string) => {
|
|
switch (screen) {
|
|
case 'beneficiaries':
|
|
router.push('/(tabs)');
|
|
break;
|
|
case 'chat':
|
|
router.push('/(tabs)/chat');
|
|
break;
|
|
case 'profile':
|
|
router.push('/(tabs)/profile');
|
|
break;
|
|
default:
|
|
// Send error back to WebView
|
|
sendToWebView({ error: `Unknown screen: ${screen}` });
|
|
}
|
|
};
|
|
|
|
// Handle native feature requests
|
|
const handleNativeFeature = (feature: string) => {
|
|
switch (feature) {
|
|
case 'bluetooth':
|
|
// TODO: Implement Bluetooth scanning screen
|
|
sendToWebView({
|
|
status: 'not_implemented',
|
|
message: 'Bluetooth scanning will be implemented here'
|
|
});
|
|
break;
|
|
case 'camera':
|
|
// TODO: Implement camera
|
|
sendToWebView({
|
|
status: 'not_implemented',
|
|
message: 'Camera will be implemented here'
|
|
});
|
|
break;
|
|
default:
|
|
sendToWebView({ error: `Unknown feature: ${feature}` });
|
|
}
|
|
};
|
|
|
|
// Handle custom messages
|
|
const handleCustomMessage = (payload: any) => {
|
|
// Echo back with confirmation
|
|
sendToWebView({
|
|
status: 'received',
|
|
echo: payload,
|
|
processedAt: Date.now()
|
|
});
|
|
};
|
|
|
|
// Send message TO WebView
|
|
const sendToWebView = (data: object) => {
|
|
const script = `
|
|
window.dispatchEvent(new MessageEvent('message', {
|
|
data: '${JSON.stringify(data)}'
|
|
}));
|
|
true;
|
|
`;
|
|
webViewRef.current?.injectJavaScript(script);
|
|
};
|
|
|
|
return (
|
|
<SafeAreaView style={styles.container}>
|
|
<WebView
|
|
ref={webViewRef}
|
|
source={{ uri: TEST_PAGE_URL }}
|
|
style={styles.webview}
|
|
onMessage={handleMessage}
|
|
javaScriptEnabled={true}
|
|
domStorageEnabled={true}
|
|
startInLoadingState={true}
|
|
scalesPageToFit={true}
|
|
cacheEnabled={false}
|
|
incognito={true}
|
|
/>
|
|
</SafeAreaView>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
container: {
|
|
flex: 1,
|
|
backgroundColor: AppColors.background,
|
|
},
|
|
webview: {
|
|
flex: 1,
|
|
},
|
|
});
|