Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ web-build/

# macOS
.DS_Store

# Android
android/
289 changes: 172 additions & 117 deletions App.js
Original file line number Diff line number Diff line change
@@ -1,130 +1,185 @@
import React, { useState } from "react";
import {
StyleSheet,
Text,
View,
TouchableOpacity,
ScrollView,
SafeAreaView,
} from "react-native";
import { StatusBar } from "expo-status-bar";
import { StyleSheet, Text, View } from "react-native";
import {
Button,
DataTable,
Title,
Provider as PaperProvider,
Divider,
} from "react-native-paper";

import useApp from "./useApp";

const PermissionStatus = ({
READ_SMS_PERMISSION_STATUS,
RECEIVE_SMS_PERMISSION_STATUS,
startReadSMS,
stopReadSMS,
checkIfHasSMSPermission,
requestReadSMSPermission,
}) => {
console.log(
"READ_SMS_PERMISSION_STATUS, RECEIVE_SMS_PERMISSION_STATUS:",
READ_SMS_PERMISSION_STATUS,
RECEIVE_SMS_PERMISSION_STATUS
);
return (
<DataTable>
<DataTable.Header>
<DataTable.Title>Permission Status</DataTable.Title>
</DataTable.Header>

<DataTable.Row>
<DataTable.Cell>READ_SMS:</DataTable.Cell>
<DataTable.Cell>
{READ_SMS_PERMISSION_STATUS + "" || "null"}
</DataTable.Cell>
</DataTable.Row>
<DataTable.Row>
<DataTable.Cell>RECEIVE_SMS:</DataTable.Cell>
<DataTable.Cell>
{RECEIVE_SMS_PERMISSION_STATUS + "" || "null"}
</DataTable.Cell>
</DataTable.Row>

{(!READ_SMS_PERMISSION_STATUS || !RECEIVE_SMS_PERMISSION_STATUS) && (
<Button onPress={requestReadSMSPermission} mode="contained">
Request Permission
</Button>
)}
</DataTable>
);
};
} from "@maniac-tech/react-native-expo-read-sms";

export default function App() {
const {
appState,
buttonClickHandler,
checkPermissions,
errorCallbackStatus,
hasReceiveSMSPermission,
hasReadSMSPermission,
requestReadSMSPermission,
smsPermissionState,
successCallbackStatus,
smsMessageBody,
smsMessageNumber,
smsError,
} = useApp();
const [logs, setLogs] = useState([]);
const [isListening, setIsListening] = useState(false);
const [permissionStatus, setPermissionStatus] = useState(null);

const addLog = (message, type = "info") => {
const timestamp = new Date().toLocaleTimeString();
setLogs((prev) => [{ message, type, timestamp }, ...prev]);
};

// ─── Test: checkIfHasSMSPermission ──────────────────────────────────────────
const handleCheckPermission = async () => {
addLog("Checking SMS permissions...");
try {
const result = await checkIfHasSMSPermission();
setPermissionStatus(result);
addLog(
`READ_SMS: ${result.hasReadSmsPermission}, RECEIVE_SMS: ${result.hasReceiveSmsPermission}`,
result.hasReadSmsPermission && result.hasReceiveSmsPermission
? "success"
: "warning"
);
} catch (e) {
addLog(`Error checking permission: ${e.message}`, "error");
}
};

// ─── Test: requestReadSMSPermission ─────────────────────────────────────────
const handleRequestPermission = async () => {
addLog("Requesting SMS permissions...");
try {
const granted = await requestReadSMSPermission();
addLog(
granted ? "Permissions granted ✓" : "Permissions denied ✗",
granted ? "success" : "error"
);
// Refresh permission status after request
await handleCheckPermission();
} catch (e) {
addLog(`Error requesting permission: ${e.message}`, "error");
}
};

// ─── Test: startReadSMS ──────────────────────────────────────────────────────
const handleStartListening = async () => {
addLog("Starting SMS listener...");
try {
await startReadSMS((status, sms, error) => {
if (status === "success") {
addLog(`SMS received: ${sms}`, "success");
setIsListening(true);
} else {
addLog(`SMS listener error: ${error}`, "error");
setIsListening(false);
}
});
setIsListening(true);
addLog("SMS listener started — send an SMS to test ✓", "success");
} catch (e) {
addLog(`Failed to start listener: ${e.message}`, "error");
}
};

// ─── Test: stopReadSMS ───────────────────────────────────────────────────────
const handleStopListening = () => {
addLog("Stopping SMS listener...");
try {
stopReadSMS();
setIsListening(false);
addLog("SMS listener stopped ✓", "success");
} catch (e) {
addLog(`Failed to stop listener: ${e.message}`, "error");
}
};

const clearLogs = () => setLogs([]);

return (
<PaperProvider>
<View style={styles.container}>
<StatusBar style="auto" />
<Title>ExpoReadSMS - Test Application (Expo)</Title>

<DataTable>
<DataTable.Row>
<DataTable.Cell>App State:</DataTable.Cell>
<DataTable.Cell>{appState}</DataTable.Cell>
</DataTable.Row>
</DataTable>
<Divider />
<PermissionStatus
READ_SMS_PERMISSION_STATUS={hasReadSMSPermission}
RECEIVE_SMS_PERMISSION_STATUS={hasReceiveSMSPermission}
requestReadSMSPermission={requestReadSMSPermission}
/>
<DataTable>
<DataTable.Row>
<DataTable.Cell>
<Text>smsPermissionState:</Text>
</DataTable.Cell>
<DataTable.Cell>{smsPermissionState + "" || "null"}</DataTable.Cell>
</DataTable.Row>
<DataTable.Row>
<DataTable.Cell>
<Text>smsMessageNumber:</Text>
</DataTable.Cell>
<DataTable.Cell>{smsMessageNumber + "" || "null"}</DataTable.Cell>
</DataTable.Row>
<DataTable.Row>
<DataTable.Cell>
<Text>smsMessageBody:</Text>
</DataTable.Cell>
<DataTable.Cell>{smsMessageBody + "" || "null"}</DataTable.Cell>
</DataTable.Row>
<DataTable.Row>
<DataTable.Cell>
<Text>smsError:</Text>
</DataTable.Cell>
<DataTable.Cell>{smsError + "" || "null"}</DataTable.Cell>
</DataTable.Row>

<Button onPress={checkPermissions} title="start" mode="contained">
Recheck permission state
</Button>
<Button onPress={buttonClickHandler} title="start" mode="contained">
Start
</Button>
</DataTable>
<SafeAreaView style={styles.container}>
<StatusBar style="auto" />

<View style={styles.header}>
<Text style={styles.title}>ExpoReadSMS TestApp</Text>
<Text style={styles.subtitle}>SDK 51 · RN 0.74 · Library v9.1.0</Text>
<View style={[styles.badge, isListening ? styles.badgeActive : styles.badgeInactive]}>
<Text style={styles.badgeText}>
{isListening ? "● Listening" : "○ Not Listening"}
</Text>
</View>
</View>
</PaperProvider>

<View style={styles.buttonGrid}>
<TouchableOpacity style={[styles.button, styles.buttonSecondary]} onPress={handleCheckPermission}>
<Text style={styles.buttonText}>Check Permission</Text>
</TouchableOpacity>

<TouchableOpacity style={[styles.button, styles.buttonSecondary]} onPress={handleRequestPermission}>
<Text style={styles.buttonText}>Request Permission</Text>
</TouchableOpacity>

<TouchableOpacity
style={[styles.button, styles.buttonPrimary, isListening && styles.buttonDisabled]}
onPress={handleStartListening}
disabled={isListening}
>
<Text style={styles.buttonText}>Start Listening</Text>
</TouchableOpacity>

<TouchableOpacity
style={[styles.button, styles.buttonDanger, !isListening && styles.buttonDisabled]}
onPress={handleStopListening}
disabled={!isListening}
>
<Text style={styles.buttonText}>Stop Listening</Text>
</TouchableOpacity>
</View>

<View style={styles.logsHeader}>
<Text style={styles.logsTitle}>Logs</Text>
<TouchableOpacity onPress={clearLogs}>
<Text style={styles.clearText}>Clear</Text>
</TouchableOpacity>
</View>

<ScrollView style={styles.logsContainer}>
{logs.length === 0 && (
<Text style={styles.emptyLogs}>Tap a button above to begin testing.</Text>
)}
{logs.map((log, index) => (
<View key={index} style={[styles.logEntry, styles[`log_${log.type}`]]}>
<Text style={styles.logTime}>{log.timestamp}</Text>
<Text style={styles.logMessage}>{log.message}</Text>
</View>
))}
</ScrollView>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
container: { flex: 1, backgroundColor: "#f5f5f5" },
header: { padding: 20, backgroundColor: "#fff", alignItems: "center", borderBottomWidth: 1, borderBottomColor: "#e0e0e0" },
title: { fontSize: 20, fontWeight: "bold", color: "#1a1a1a" },
subtitle: { fontSize: 13, color: "#666", marginTop: 4 },
badge: { marginTop: 10, paddingHorizontal: 14, paddingVertical: 5, borderRadius: 20 },
badgeActive: { backgroundColor: "#d4edda" },
badgeInactive: { backgroundColor: "#f8d7da" },
badgeText: { fontSize: 13, fontWeight: "600" },
buttonGrid: { flexDirection: "row", flexWrap: "wrap", padding: 12, gap: 8 },
button: { flex: 1, minWidth: "45%", padding: 14, borderRadius: 10, alignItems: "center" },
buttonPrimary: { backgroundColor: "#007AFF" },
buttonSecondary: { backgroundColor: "#5856D6" },
buttonDanger: { backgroundColor: "#FF3B30" },
buttonDisabled: { opacity: 0.4 },
buttonText: { color: "#fff", fontWeight: "600", fontSize: 14 },
logsHeader: { flexDirection: "row", justifyContent: "space-between", alignItems: "center", paddingHorizontal: 16, paddingVertical: 8, backgroundColor: "#fff", borderBottomWidth: 1, borderBottomColor: "#e0e0e0" },
logsTitle: { fontSize: 15, fontWeight: "600" },
clearText: { fontSize: 14, color: "#007AFF" },
logsContainer: { flex: 1, padding: 12 },
emptyLogs: { color: "#999", textAlign: "center", marginTop: 40, fontSize: 14 },
logEntry: { padding: 10, marginBottom: 8, borderRadius: 8, borderLeftWidth: 4 },
log_info: { backgroundColor: "#e8f4f8", borderLeftColor: "#007AFF" },
log_success: { backgroundColor: "#d4edda", borderLeftColor: "#28a745" },
log_warning: { backgroundColor: "#fff3cd", borderLeftColor: "#ffc107" },
log_error: { backgroundColor: "#f8d7da", borderLeftColor: "#dc3545" },
logTime: { fontSize: 11, color: "#888", marginBottom: 2 },
logMessage: { fontSize: 13, color: "#1a1a1a" },
});
49 changes: 15 additions & 34 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"expo": {
"name": "ExpoReadSMS-Test",
"slug": "ExpoReadSMS-Test",
"name": "ExpoReadSMS-TestApp",
"slug": "ExpoReadSMS-TestApp",
"version": "1.0.0",
"sdkVersion": "53.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
Expand All @@ -11,49 +12,29 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"enabled": true,
"fallbackToCacheTimeout": 0,
"url": "https://u.expo.dev/645044d2-03a2-47c7-be5f-d5ff0f228cb7"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#FFFFFF"
"backgroundColor": "#ffffff"
},
"package": "com.maniactech.exporeadsmstest",
"permissions": []
},
"web": {
"favicon": "./assets/favicon.png"
"package": "com.maniactech.exporeadsms",
"permissions": [
"android.permission.RECEIVE_SMS",
"android.permission.READ_SMS"
]
},
"plugins": [
"expo-updates",
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 34,
"compileSdkVersion": 34,
"targetSdkVersion": 34,
"buildToolsVersion": "34.0.0"
"compileSdkVersion": 35,
"targetSdkVersion": 35,
"minSdkVersion": 24
}
}
]
],
"runtimeVersion": {
"policy": "sdkVersion"
},
"extra": {
"eas": {
"projectId": "645044d2-03a2-47c7-be5f-d5ff0f228cb7"
}
}
],
"expo-asset"
]
}
}
Loading