MCPcopy Create free account
hub / github.com/transistorsoft/react-native-background-geolocation / AppContent

Function AppContent

example/HelloWorld/App.tsx:54–751  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52}
53
54function AppContent() {
55 const safeAreaInsets = useSafeAreaInsets();
56 const isDarkMode = useColorScheme() === 'dark';
57 const [trackingEnabled, setTrackingEnabled] = useState(false);
58 const [isMoving, setIsMoving] = useState(false);
59 const [currentActivity, setCurrentActivity] = useState('unknown');
60 const [lastLocation, setLastLocation] = useState<Location | null>(null);
61 const [providerEnabled, setProviderEnabled] = useState(false);
62 const [menuVisible, setMenuVisible] = useState(false);
63 const [registrationVisible, setRegistrationVisible] = useState(false);
64 const [odometer, setOdometer] = useState(0);
65 const [odometerError, setOdometerError] = useState<number | null>(null);
66 const [isInitialized, setIsInitialized] = useState(false);
67 const [emailDialogVisible, setEmailDialogVisible] = useState(false);
68 const [emailInput, setEmailInput] = useState('');
69
70 // Check registration status on mount
71 useEffect(() => {
72 checkRegistrationAndInitialize();
73 }, []);
74
75 const checkRegistrationAndInitialize = async () => {
76 try {
77 // Check if user has registered before
78 const registered = await AsyncStorage.getItem('@transistor_registered');
79
80 if (!registered) {
81 // First launch - show registration modal
82 setRegistrationVisible(true);
83 } else {
84 // Already registered - initialize BackgroundGeolocation
85 const org = await AsyncStorage.getItem('@transistor_org');
86 const username = await AsyncStorage.getItem('@transistor_username');
87
88 if (org && username) {
89 await initializeBackgroundGeolocation(org, username);
90 } else {
91 // Corrupted storage - re-register
92 setRegistrationVisible(true);
93 }
94 }
95 } catch (error) {
96 console.error('Error checking registration:', error);
97 setRegistrationVisible(true);
98 }
99 };
100
101 const initializeBackgroundGeolocation = async (org: string, username: string) => {
102 if (isInitialized) return; // Prevent double initialization
103
104 // Poke a custom log message into SDK logs.
105 BackgroundGeolocation.logger.debug("INITIALIZING BACKGROUND GEOLOCATION");
106
107 try {
108 // Get or create demo server (tracker.transistorsoft.com) token with the registered credentials
109 const token = await BackgroundGeolocation.findOrCreateTransistorAuthorizationToken(org, username);
110
111 const state = await BackgroundGeolocation.ready({

Callers

nothing calls this directly

Calls 11

getActivityIconFunction · 0.85
onMotionChangeMethod · 0.80
onProviderChangeMethod · 0.80
removeMethod · 0.80
logMethod · 0.65
warnMethod · 0.65
emailLogMethod · 0.65
onLocationMethod · 0.45
onGeofenceMethod · 0.45
onActivityChangeMethod · 0.45

Tested by

no test coverage detected